| File: | src/gnu/usr.bin/binutils-2.17/binutils/dwarf.c |
| Warning: | line 186, column 19 The result of the left shift is undefined because the left operand is negative |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* dwarf.c -- display DWARF contents of a BFD binary file | |||
| 2 | Copyright 2005, 2006 | |||
| 3 | Free Software Foundation, Inc. | |||
| 4 | ||||
| 5 | This file is part of GNU Binutils. | |||
| 6 | ||||
| 7 | This program is free software; you can redistribute it and/or modify | |||
| 8 | it under the terms of the GNU General Public License as published by | |||
| 9 | the Free Software Foundation; either version 2 of the License, or | |||
| 10 | (at your option) any later version. | |||
| 11 | ||||
| 12 | This program is distributed in the hope that it will be useful, | |||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| 15 | GNU General Public License for more details. | |||
| 16 | ||||
| 17 | You should have received a copy of the GNU General Public License | |||
| 18 | along with this program; if not, write to the Free Software | |||
| 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | |||
| 20 | 02110-1301, USA. */ | |||
| 21 | ||||
| 22 | #include <stdio.h> | |||
| 23 | ||||
| 24 | #include "dwarf.h" | |||
| 25 | ||||
| 26 | #include "bucomm.h" | |||
| 27 | #include "libiberty.h" | |||
| 28 | ||||
| 29 | static int have_frame_base; | |||
| 30 | static int need_base_address; | |||
| 31 | ||||
| 32 | static unsigned int last_pointer_size = 0; | |||
| 33 | static int warned_about_missing_comp_units = FALSE0; | |||
| 34 | ||||
| 35 | static unsigned int num_debug_info_entries = 0; | |||
| 36 | static debug_info *debug_information = NULL((void*)0); | |||
| 37 | ||||
| 38 | dwarf_vma eh_addr_size; | |||
| 39 | int is_relocatable; | |||
| 40 | ||||
| 41 | int do_debug_info; | |||
| 42 | int do_debug_abbrevs; | |||
| 43 | int do_debug_lines; | |||
| 44 | int do_debug_pubnames; | |||
| 45 | int do_debug_aranges; | |||
| 46 | int do_debug_ranges; | |||
| 47 | int do_debug_frames; | |||
| 48 | int do_debug_frames_interp; | |||
| 49 | int do_debug_macinfo; | |||
| 50 | int do_debug_str; | |||
| 51 | int do_debug_loc; | |||
| 52 | ||||
| 53 | dwarf_vma (*byte_get) (unsigned char *, int); | |||
| 54 | ||||
| 55 | dwarf_vma | |||
| 56 | byte_get_little_endian (unsigned char *field, int size) | |||
| 57 | { | |||
| 58 | switch (size) | |||
| 59 | { | |||
| 60 | case 1: | |||
| 61 | return *field; | |||
| 62 | ||||
| 63 | case 2: | |||
| 64 | return ((unsigned int) (field[0])) | |||
| 65 | | (((unsigned int) (field[1])) << 8); | |||
| 66 | ||||
| 67 | case 4: | |||
| 68 | return ((unsigned long) (field[0])) | |||
| 69 | | (((unsigned long) (field[1])) << 8) | |||
| 70 | | (((unsigned long) (field[2])) << 16) | |||
| 71 | | (((unsigned long) (field[3])) << 24); | |||
| 72 | ||||
| 73 | case 8: | |||
| 74 | if (sizeof (dwarf_vma) == 8) | |||
| 75 | return ((dwarf_vma) (field[0])) | |||
| 76 | | (((dwarf_vma) (field[1])) << 8) | |||
| 77 | | (((dwarf_vma) (field[2])) << 16) | |||
| 78 | | (((dwarf_vma) (field[3])) << 24) | |||
| 79 | | (((dwarf_vma) (field[4])) << 32) | |||
| 80 | | (((dwarf_vma) (field[5])) << 40) | |||
| 81 | | (((dwarf_vma) (field[6])) << 48) | |||
| 82 | | (((dwarf_vma) (field[7])) << 56); | |||
| 83 | else if (sizeof (dwarf_vma) == 4) | |||
| 84 | /* We want to extract data from an 8 byte wide field and | |||
| 85 | place it into a 4 byte wide field. Since this is a little | |||
| 86 | endian source we can just use the 4 byte extraction code. */ | |||
| 87 | return ((unsigned long) (field[0])) | |||
| 88 | | (((unsigned long) (field[1])) << 8) | |||
| 89 | | (((unsigned long) (field[2])) << 16) | |||
| 90 | | (((unsigned long) (field[3])) << 24); | |||
| 91 | ||||
| 92 | default: | |||
| 93 | error (_("Unhandled data length: %d\n")("Unhandled data length: %d\n"), size); | |||
| 94 | abort (); | |||
| 95 | } | |||
| 96 | } | |||
| 97 | ||||
| 98 | dwarf_vma | |||
| 99 | byte_get_big_endian (unsigned char *field, int size) | |||
| 100 | { | |||
| 101 | switch (size) | |||
| 102 | { | |||
| 103 | case 1: | |||
| 104 | return *field; | |||
| 105 | ||||
| 106 | case 2: | |||
| 107 | return ((unsigned int) (field[1])) | (((int) (field[0])) << 8); | |||
| 108 | ||||
| 109 | case 4: | |||
| 110 | return ((unsigned long) (field[3])) | |||
| 111 | | (((unsigned long) (field[2])) << 8) | |||
| 112 | | (((unsigned long) (field[1])) << 16) | |||
| 113 | | (((unsigned long) (field[0])) << 24); | |||
| 114 | ||||
| 115 | case 8: | |||
| 116 | if (sizeof (dwarf_vma) == 8) | |||
| 117 | return ((dwarf_vma) (field[7])) | |||
| 118 | | (((dwarf_vma) (field[6])) << 8) | |||
| 119 | | (((dwarf_vma) (field[5])) << 16) | |||
| 120 | | (((dwarf_vma) (field[4])) << 24) | |||
| 121 | | (((dwarf_vma) (field[3])) << 32) | |||
| 122 | | (((dwarf_vma) (field[2])) << 40) | |||
| 123 | | (((dwarf_vma) (field[1])) << 48) | |||
| 124 | | (((dwarf_vma) (field[0])) << 56); | |||
| 125 | else if (sizeof (dwarf_vma) == 4) | |||
| 126 | { | |||
| 127 | /* Although we are extracing data from an 8 byte wide field, | |||
| 128 | we are returning only 4 bytes of data. */ | |||
| 129 | field += 4; | |||
| 130 | return ((unsigned long) (field[3])) | |||
| 131 | | (((unsigned long) (field[2])) << 8) | |||
| 132 | | (((unsigned long) (field[1])) << 16) | |||
| 133 | | (((unsigned long) (field[0])) << 24); | |||
| 134 | } | |||
| 135 | ||||
| 136 | default: | |||
| 137 | error (_("Unhandled data length: %d\n")("Unhandled data length: %d\n"), size); | |||
| 138 | abort (); | |||
| 139 | } | |||
| 140 | } | |||
| 141 | ||||
| 142 | static dwarf_vma | |||
| 143 | byte_get_signed (unsigned char *field, int size) | |||
| 144 | { | |||
| 145 | dwarf_vma x = byte_get (field, size); | |||
| 146 | ||||
| 147 | switch (size) | |||
| 148 | { | |||
| 149 | case 1: | |||
| 150 | return (x ^ 0x80) - 0x80; | |||
| 151 | case 2: | |||
| 152 | return (x ^ 0x8000) - 0x8000; | |||
| 153 | case 4: | |||
| 154 | return (x ^ 0x80000000) - 0x80000000; | |||
| 155 | case 8: | |||
| 156 | return x; | |||
| 157 | default: | |||
| 158 | abort (); | |||
| 159 | } | |||
| 160 | } | |||
| 161 | ||||
| 162 | static unsigned long int | |||
| 163 | read_leb128 (unsigned char *data, unsigned int *length_return, int sign) | |||
| 164 | { | |||
| 165 | unsigned long int result = 0; | |||
| 166 | unsigned int num_read = 0; | |||
| 167 | unsigned int shift = 0; | |||
| 168 | unsigned char byte; | |||
| 169 | ||||
| 170 | do | |||
| 171 | { | |||
| 172 | byte = *data++; | |||
| 173 | num_read++; | |||
| 174 | ||||
| 175 | result |= ((unsigned long int) (byte & 0x7f)) << shift; | |||
| 176 | ||||
| 177 | shift += 7; | |||
| 178 | ||||
| 179 | } | |||
| 180 | while (byte & 0x80); | |||
| 181 | ||||
| 182 | if (length_return
| |||
| 183 | *length_return = num_read; | |||
| 184 | ||||
| 185 | if (sign
| |||
| 186 | result |= -1L << shift; | |||
| ||||
| 187 | ||||
| 188 | return result; | |||
| 189 | } | |||
| 190 | ||||
| 191 | typedef struct State_Machine_Registers | |||
| 192 | { | |||
| 193 | unsigned long address; | |||
| 194 | unsigned int file; | |||
| 195 | unsigned int line; | |||
| 196 | unsigned int column; | |||
| 197 | int is_stmt; | |||
| 198 | int basic_block; | |||
| 199 | int end_sequence; | |||
| 200 | /* This variable hold the number of the last entry seen | |||
| 201 | in the File Table. */ | |||
| 202 | unsigned int last_file_entry; | |||
| 203 | } SMR; | |||
| 204 | ||||
| 205 | static SMR state_machine_regs; | |||
| 206 | ||||
| 207 | static void | |||
| 208 | reset_state_machine (int is_stmt) | |||
| 209 | { | |||
| 210 | state_machine_regs.address = 0; | |||
| 211 | state_machine_regs.file = 1; | |||
| 212 | state_machine_regs.line = 1; | |||
| 213 | state_machine_regs.column = 0; | |||
| 214 | state_machine_regs.is_stmt = is_stmt; | |||
| 215 | state_machine_regs.basic_block = 0; | |||
| 216 | state_machine_regs.end_sequence = 0; | |||
| 217 | state_machine_regs.last_file_entry = 0; | |||
| 218 | } | |||
| 219 | ||||
| 220 | /* Handled an extend line op. | |||
| 221 | Returns the number of bytes read. */ | |||
| 222 | ||||
| 223 | static int | |||
| 224 | process_extended_line_op (unsigned char *data, int is_stmt) | |||
| 225 | { | |||
| 226 | unsigned char op_code; | |||
| 227 | unsigned int bytes_read; | |||
| 228 | unsigned int len; | |||
| 229 | unsigned char *name; | |||
| 230 | unsigned long adr; | |||
| 231 | ||||
| 232 | len = read_leb128 (data, & bytes_read, 0); | |||
| 233 | data += bytes_read; | |||
| 234 | ||||
| 235 | if (len == 0) | |||
| 236 | { | |||
| 237 | warn (_("badly formed extended line op encountered!\n")("badly formed extended line op encountered!\n")); | |||
| 238 | return bytes_read; | |||
| 239 | } | |||
| 240 | ||||
| 241 | len += bytes_read; | |||
| 242 | op_code = *data++; | |||
| 243 | ||||
| 244 | printf (_(" Extended opcode %d: ")(" Extended opcode %d: "), op_code); | |||
| 245 | ||||
| 246 | switch (op_code) | |||
| 247 | { | |||
| 248 | case DW_LNE_end_sequence: | |||
| 249 | printf (_("End of Sequence\n\n")("End of Sequence\n\n")); | |||
| 250 | reset_state_machine (is_stmt); | |||
| 251 | break; | |||
| 252 | ||||
| 253 | case DW_LNE_set_address: | |||
| 254 | adr = byte_get (data, len - bytes_read - 1); | |||
| 255 | printf (_("set Address to 0x%lx\n")("set Address to 0x%lx\n"), adr); | |||
| 256 | state_machine_regs.address = adr; | |||
| 257 | break; | |||
| 258 | ||||
| 259 | case DW_LNE_define_file: | |||
| 260 | printf (_(" define new File Table entry\n")(" define new File Table entry\n")); | |||
| 261 | printf (_(" Entry\tDir\tTime\tSize\tName\n")(" Entry\tDir\tTime\tSize\tName\n")); | |||
| 262 | ||||
| 263 | printf (_(" %d\t")(" %d\t"), ++state_machine_regs.last_file_entry); | |||
| 264 | name = data; | |||
| 265 | data += strlen ((char *) data) + 1; | |||
| 266 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 267 | data += bytes_read; | |||
| 268 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 269 | data += bytes_read; | |||
| 270 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 271 | printf (_("%s\n\n")("%s\n\n"), name); | |||
| 272 | break; | |||
| 273 | ||||
| 274 | default: | |||
| 275 | printf (_("UNKNOWN: length %d\n")("UNKNOWN: length %d\n"), len - bytes_read); | |||
| 276 | break; | |||
| 277 | } | |||
| 278 | ||||
| 279 | return len; | |||
| 280 | } | |||
| 281 | ||||
| 282 | static const char * | |||
| 283 | fetch_indirect_string (unsigned long offset) | |||
| 284 | { | |||
| 285 | struct dwarf_section *section = &debug_displays [str].section; | |||
| 286 | ||||
| 287 | if (section->start == NULL((void*)0)) | |||
| 288 | return _("<no .debug_str section>")("<no .debug_str section>"); | |||
| 289 | ||||
| 290 | /* DWARF sections under Mach-O have non-zero addresses. */ | |||
| 291 | offset -= section->address; | |||
| 292 | if (offset > section->size) | |||
| 293 | { | |||
| 294 | warn (_("DW_FORM_strp offset too big: %lx\n")("DW_FORM_strp offset too big: %lx\n"), offset); | |||
| 295 | return _("<offset is too big>")("<offset is too big>"); | |||
| 296 | } | |||
| 297 | ||||
| 298 | return (const char *) section->start + offset; | |||
| 299 | } | |||
| 300 | ||||
| 301 | /* FIXME: There are better and more efficient ways to handle | |||
| 302 | these structures. For now though, I just want something that | |||
| 303 | is simple to implement. */ | |||
| 304 | typedef struct abbrev_attr | |||
| 305 | { | |||
| 306 | unsigned long attribute; | |||
| 307 | unsigned long form; | |||
| 308 | struct abbrev_attr *next; | |||
| 309 | } | |||
| 310 | abbrev_attr; | |||
| 311 | ||||
| 312 | typedef struct abbrev_entry | |||
| 313 | { | |||
| 314 | unsigned long entry; | |||
| 315 | unsigned long tag; | |||
| 316 | int children; | |||
| 317 | struct abbrev_attr *first_attr; | |||
| 318 | struct abbrev_attr *last_attr; | |||
| 319 | struct abbrev_entry *next; | |||
| 320 | } | |||
| 321 | abbrev_entry; | |||
| 322 | ||||
| 323 | static abbrev_entry *first_abbrev = NULL((void*)0); | |||
| 324 | static abbrev_entry *last_abbrev = NULL((void*)0); | |||
| 325 | ||||
| 326 | static void | |||
| 327 | free_abbrevs (void) | |||
| 328 | { | |||
| 329 | abbrev_entry *abbrev; | |||
| 330 | ||||
| 331 | for (abbrev = first_abbrev; abbrev;) | |||
| 332 | { | |||
| 333 | abbrev_entry *next = abbrev->next; | |||
| 334 | abbrev_attr *attr; | |||
| 335 | ||||
| 336 | for (attr = abbrev->first_attr; attr;) | |||
| 337 | { | |||
| 338 | abbrev_attr *next = attr->next; | |||
| 339 | ||||
| 340 | free (attr); | |||
| 341 | attr = next; | |||
| 342 | } | |||
| 343 | ||||
| 344 | free (abbrev); | |||
| 345 | abbrev = next; | |||
| 346 | } | |||
| 347 | ||||
| 348 | last_abbrev = first_abbrev = NULL((void*)0); | |||
| 349 | } | |||
| 350 | ||||
| 351 | static void | |||
| 352 | add_abbrev (unsigned long number, unsigned long tag, int children) | |||
| 353 | { | |||
| 354 | abbrev_entry *entry; | |||
| 355 | ||||
| 356 | entry = malloc (sizeof (*entry)); | |||
| 357 | ||||
| 358 | if (entry == NULL((void*)0)) | |||
| 359 | /* ugg */ | |||
| 360 | return; | |||
| 361 | ||||
| 362 | entry->entry = number; | |||
| 363 | entry->tag = tag; | |||
| 364 | entry->children = children; | |||
| 365 | entry->first_attr = NULL((void*)0); | |||
| 366 | entry->last_attr = NULL((void*)0); | |||
| 367 | entry->next = NULL((void*)0); | |||
| 368 | ||||
| 369 | if (first_abbrev == NULL((void*)0)) | |||
| 370 | first_abbrev = entry; | |||
| 371 | else | |||
| 372 | last_abbrev->next = entry; | |||
| 373 | ||||
| 374 | last_abbrev = entry; | |||
| 375 | } | |||
| 376 | ||||
| 377 | static void | |||
| 378 | add_abbrev_attr (unsigned long attribute, unsigned long form) | |||
| 379 | { | |||
| 380 | abbrev_attr *attr; | |||
| 381 | ||||
| 382 | attr = malloc (sizeof (*attr)); | |||
| 383 | ||||
| 384 | if (attr == NULL((void*)0)) | |||
| 385 | /* ugg */ | |||
| 386 | return; | |||
| 387 | ||||
| 388 | attr->attribute = attribute; | |||
| 389 | attr->form = form; | |||
| 390 | attr->next = NULL((void*)0); | |||
| 391 | ||||
| 392 | if (last_abbrev->first_attr == NULL((void*)0)) | |||
| 393 | last_abbrev->first_attr = attr; | |||
| 394 | else | |||
| 395 | last_abbrev->last_attr->next = attr; | |||
| 396 | ||||
| 397 | last_abbrev->last_attr = attr; | |||
| 398 | } | |||
| 399 | ||||
| 400 | /* Processes the (partial) contents of a .debug_abbrev section. | |||
| 401 | Returns NULL if the end of the section was encountered. | |||
| 402 | Returns the address after the last byte read if the end of | |||
| 403 | an abbreviation set was found. */ | |||
| 404 | ||||
| 405 | static unsigned char * | |||
| 406 | process_abbrev_section (unsigned char *start, unsigned char *end) | |||
| 407 | { | |||
| 408 | if (first_abbrev != NULL((void*)0)) | |||
| 409 | return NULL((void*)0); | |||
| 410 | ||||
| 411 | while (start < end) | |||
| 412 | { | |||
| 413 | unsigned int bytes_read; | |||
| 414 | unsigned long entry; | |||
| 415 | unsigned long tag; | |||
| 416 | unsigned long attribute; | |||
| 417 | int children; | |||
| 418 | ||||
| 419 | entry = read_leb128 (start, & bytes_read, 0); | |||
| 420 | start += bytes_read; | |||
| 421 | ||||
| 422 | /* A single zero is supposed to end the section according | |||
| 423 | to the standard. If there's more, then signal that to | |||
| 424 | the caller. */ | |||
| 425 | if (entry == 0) | |||
| 426 | return start == end ? NULL((void*)0) : start; | |||
| 427 | ||||
| 428 | tag = read_leb128 (start, & bytes_read, 0); | |||
| 429 | start += bytes_read; | |||
| 430 | ||||
| 431 | children = *start++; | |||
| 432 | ||||
| 433 | add_abbrev (entry, tag, children); | |||
| 434 | ||||
| 435 | do | |||
| 436 | { | |||
| 437 | unsigned long form; | |||
| 438 | ||||
| 439 | attribute = read_leb128 (start, & bytes_read, 0); | |||
| 440 | start += bytes_read; | |||
| 441 | ||||
| 442 | form = read_leb128 (start, & bytes_read, 0); | |||
| 443 | start += bytes_read; | |||
| 444 | ||||
| 445 | if (attribute != 0) | |||
| 446 | add_abbrev_attr (attribute, form); | |||
| 447 | } | |||
| 448 | while (attribute != 0); | |||
| 449 | } | |||
| 450 | ||||
| 451 | return NULL((void*)0); | |||
| 452 | } | |||
| 453 | ||||
| 454 | static char * | |||
| 455 | get_TAG_name (unsigned long tag) | |||
| 456 | { | |||
| 457 | switch (tag) | |||
| 458 | { | |||
| 459 | case DW_TAG_padding: return "DW_TAG_padding"; | |||
| 460 | case DW_TAG_array_type: return "DW_TAG_array_type"; | |||
| 461 | case DW_TAG_class_type: return "DW_TAG_class_type"; | |||
| 462 | case DW_TAG_entry_point: return "DW_TAG_entry_point"; | |||
| 463 | case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type"; | |||
| 464 | case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter"; | |||
| 465 | case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration"; | |||
| 466 | case DW_TAG_label: return "DW_TAG_label"; | |||
| 467 | case DW_TAG_lexical_block: return "DW_TAG_lexical_block"; | |||
| 468 | case DW_TAG_member: return "DW_TAG_member"; | |||
| 469 | case DW_TAG_pointer_type: return "DW_TAG_pointer_type"; | |||
| 470 | case DW_TAG_reference_type: return "DW_TAG_reference_type"; | |||
| 471 | case DW_TAG_compile_unit: return "DW_TAG_compile_unit"; | |||
| 472 | case DW_TAG_string_type: return "DW_TAG_string_type"; | |||
| 473 | case DW_TAG_structure_type: return "DW_TAG_structure_type"; | |||
| 474 | case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type"; | |||
| 475 | case DW_TAG_typedef: return "DW_TAG_typedef"; | |||
| 476 | case DW_TAG_union_type: return "DW_TAG_union_type"; | |||
| 477 | case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters"; | |||
| 478 | case DW_TAG_variant: return "DW_TAG_variant"; | |||
| 479 | case DW_TAG_common_block: return "DW_TAG_common_block"; | |||
| 480 | case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion"; | |||
| 481 | case DW_TAG_inheritance: return "DW_TAG_inheritance"; | |||
| 482 | case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine"; | |||
| 483 | case DW_TAG_module: return "DW_TAG_module"; | |||
| 484 | case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type"; | |||
| 485 | case DW_TAG_set_type: return "DW_TAG_set_type"; | |||
| 486 | case DW_TAG_subrange_type: return "DW_TAG_subrange_type"; | |||
| 487 | case DW_TAG_with_stmt: return "DW_TAG_with_stmt"; | |||
| 488 | case DW_TAG_access_declaration: return "DW_TAG_access_declaration"; | |||
| 489 | case DW_TAG_base_type: return "DW_TAG_base_type"; | |||
| 490 | case DW_TAG_catch_block: return "DW_TAG_catch_block"; | |||
| 491 | case DW_TAG_const_type: return "DW_TAG_const_type"; | |||
| 492 | case DW_TAG_constant: return "DW_TAG_constant"; | |||
| 493 | case DW_TAG_enumerator: return "DW_TAG_enumerator"; | |||
| 494 | case DW_TAG_file_type: return "DW_TAG_file_type"; | |||
| 495 | case DW_TAG_friend: return "DW_TAG_friend"; | |||
| 496 | case DW_TAG_namelist: return "DW_TAG_namelist"; | |||
| 497 | case DW_TAG_namelist_item: return "DW_TAG_namelist_item"; | |||
| 498 | case DW_TAG_packed_type: return "DW_TAG_packed_type"; | |||
| 499 | case DW_TAG_subprogram: return "DW_TAG_subprogram"; | |||
| 500 | case DW_TAG_template_type_param: return "DW_TAG_template_type_param"; | |||
| 501 | case DW_TAG_template_value_param: return "DW_TAG_template_value_param"; | |||
| 502 | case DW_TAG_thrown_type: return "DW_TAG_thrown_type"; | |||
| 503 | case DW_TAG_try_block: return "DW_TAG_try_block"; | |||
| 504 | case DW_TAG_variant_part: return "DW_TAG_variant_part"; | |||
| 505 | case DW_TAG_variable: return "DW_TAG_variable"; | |||
| 506 | case DW_TAG_volatile_type: return "DW_TAG_volatile_type"; | |||
| 507 | case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop"; | |||
| 508 | case DW_TAG_format_label: return "DW_TAG_format_label"; | |||
| 509 | case DW_TAG_function_template: return "DW_TAG_function_template"; | |||
| 510 | case DW_TAG_class_template: return "DW_TAG_class_template"; | |||
| 511 | /* DWARF 2.1 values. */ | |||
| 512 | case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure"; | |||
| 513 | case DW_TAG_restrict_type: return "DW_TAG_restrict_type"; | |||
| 514 | case DW_TAG_interface_type: return "DW_TAG_interface_type"; | |||
| 515 | case DW_TAG_namespace: return "DW_TAG_namespace"; | |||
| 516 | case DW_TAG_imported_module: return "DW_TAG_imported_module"; | |||
| 517 | case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type"; | |||
| 518 | case DW_TAG_partial_unit: return "DW_TAG_partial_unit"; | |||
| 519 | case DW_TAG_imported_unit: return "DW_TAG_imported_unit"; | |||
| 520 | /* UPC values. */ | |||
| 521 | case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type"; | |||
| 522 | case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type"; | |||
| 523 | case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type"; | |||
| 524 | default: | |||
| 525 | { | |||
| 526 | static char buffer[100]; | |||
| 527 | ||||
| 528 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx")("Unknown TAG value: %lx"), tag); | |||
| 529 | return buffer; | |||
| 530 | } | |||
| 531 | } | |||
| 532 | } | |||
| 533 | ||||
| 534 | static char * | |||
| 535 | get_FORM_name (unsigned long form) | |||
| 536 | { | |||
| 537 | switch (form) | |||
| 538 | { | |||
| 539 | case DW_FORM_addr: return "DW_FORM_addr"; | |||
| 540 | case DW_FORM_block2: return "DW_FORM_block2"; | |||
| 541 | case DW_FORM_block4: return "DW_FORM_block4"; | |||
| 542 | case DW_FORM_data2: return "DW_FORM_data2"; | |||
| 543 | case DW_FORM_data4: return "DW_FORM_data4"; | |||
| 544 | case DW_FORM_data8: return "DW_FORM_data8"; | |||
| 545 | case DW_FORM_string: return "DW_FORM_string"; | |||
| 546 | case DW_FORM_block: return "DW_FORM_block"; | |||
| 547 | case DW_FORM_block1: return "DW_FORM_block1"; | |||
| 548 | case DW_FORM_data1: return "DW_FORM_data1"; | |||
| 549 | case DW_FORM_flag: return "DW_FORM_flag"; | |||
| 550 | case DW_FORM_sdata: return "DW_FORM_sdata"; | |||
| 551 | case DW_FORM_strp: return "DW_FORM_strp"; | |||
| 552 | case DW_FORM_udata: return "DW_FORM_udata"; | |||
| 553 | case DW_FORM_ref_addr: return "DW_FORM_ref_addr"; | |||
| 554 | case DW_FORM_ref1: return "DW_FORM_ref1"; | |||
| 555 | case DW_FORM_ref2: return "DW_FORM_ref2"; | |||
| 556 | case DW_FORM_ref4: return "DW_FORM_ref4"; | |||
| 557 | case DW_FORM_ref8: return "DW_FORM_ref8"; | |||
| 558 | case DW_FORM_ref_udata: return "DW_FORM_ref_udata"; | |||
| 559 | case DW_FORM_indirect: return "DW_FORM_indirect"; | |||
| 560 | default: | |||
| 561 | { | |||
| 562 | static char buffer[100]; | |||
| 563 | ||||
| 564 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx")("Unknown FORM value: %lx"), form); | |||
| 565 | return buffer; | |||
| 566 | } | |||
| 567 | } | |||
| 568 | } | |||
| 569 | ||||
| 570 | static unsigned char * | |||
| 571 | display_block (unsigned char *data, unsigned long length) | |||
| 572 | { | |||
| 573 | printf (_(" %lu byte block: ")(" %lu byte block: "), length); | |||
| 574 | ||||
| 575 | while (length --) | |||
| 576 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |||
| 577 | ||||
| 578 | return data; | |||
| 579 | } | |||
| 580 | ||||
| 581 | static int | |||
| 582 | decode_location_expression (unsigned char * data, | |||
| 583 | unsigned int pointer_size, | |||
| 584 | unsigned long length, | |||
| 585 | unsigned long cu_offset) | |||
| 586 | { | |||
| 587 | unsigned op; | |||
| 588 | unsigned int bytes_read; | |||
| 589 | unsigned long uvalue; | |||
| 590 | unsigned char *end = data + length; | |||
| 591 | int need_frame_base = 0; | |||
| 592 | ||||
| 593 | while (data < end) | |||
| 594 | { | |||
| 595 | op = *data++; | |||
| 596 | ||||
| 597 | switch (op) | |||
| 598 | { | |||
| 599 | case DW_OP_addr: | |||
| 600 | printf ("DW_OP_addr: %lx", | |||
| 601 | (unsigned long) byte_get (data, pointer_size)); | |||
| 602 | data += pointer_size; | |||
| 603 | break; | |||
| 604 | case DW_OP_deref: | |||
| 605 | printf ("DW_OP_deref"); | |||
| 606 | break; | |||
| 607 | case DW_OP_const1u: | |||
| 608 | printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1)); | |||
| 609 | break; | |||
| 610 | case DW_OP_const1s: | |||
| 611 | printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1)); | |||
| 612 | break; | |||
| 613 | case DW_OP_const2u: | |||
| 614 | printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); | |||
| 615 | data += 2; | |||
| 616 | break; | |||
| 617 | case DW_OP_const2s: | |||
| 618 | printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2)); | |||
| 619 | data += 2; | |||
| 620 | break; | |||
| 621 | case DW_OP_const4u: | |||
| 622 | printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); | |||
| 623 | data += 4; | |||
| 624 | break; | |||
| 625 | case DW_OP_const4s: | |||
| 626 | printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4)); | |||
| 627 | data += 4; | |||
| 628 | break; | |||
| 629 | case DW_OP_const8u: | |||
| 630 | printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), | |||
| 631 | (unsigned long) byte_get (data + 4, 4)); | |||
| 632 | data += 8; | |||
| 633 | break; | |||
| 634 | case DW_OP_const8s: | |||
| 635 | printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), | |||
| 636 | (long) byte_get (data + 4, 4)); | |||
| 637 | data += 8; | |||
| 638 | break; | |||
| 639 | case DW_OP_constu: | |||
| 640 | printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0)); | |||
| 641 | data += bytes_read; | |||
| 642 | break; | |||
| 643 | case DW_OP_consts: | |||
| 644 | printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1)); | |||
| 645 | data += bytes_read; | |||
| 646 | break; | |||
| 647 | case DW_OP_dup: | |||
| 648 | printf ("DW_OP_dup"); | |||
| 649 | break; | |||
| 650 | case DW_OP_drop: | |||
| 651 | printf ("DW_OP_drop"); | |||
| 652 | break; | |||
| 653 | case DW_OP_over: | |||
| 654 | printf ("DW_OP_over"); | |||
| 655 | break; | |||
| 656 | case DW_OP_pick: | |||
| 657 | printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1)); | |||
| 658 | break; | |||
| 659 | case DW_OP_swap: | |||
| 660 | printf ("DW_OP_swap"); | |||
| 661 | break; | |||
| 662 | case DW_OP_rot: | |||
| 663 | printf ("DW_OP_rot"); | |||
| 664 | break; | |||
| 665 | case DW_OP_xderef: | |||
| 666 | printf ("DW_OP_xderef"); | |||
| 667 | break; | |||
| 668 | case DW_OP_abs: | |||
| 669 | printf ("DW_OP_abs"); | |||
| 670 | break; | |||
| 671 | case DW_OP_and: | |||
| 672 | printf ("DW_OP_and"); | |||
| 673 | break; | |||
| 674 | case DW_OP_div: | |||
| 675 | printf ("DW_OP_div"); | |||
| 676 | break; | |||
| 677 | case DW_OP_minus: | |||
| 678 | printf ("DW_OP_minus"); | |||
| 679 | break; | |||
| 680 | case DW_OP_mod: | |||
| 681 | printf ("DW_OP_mod"); | |||
| 682 | break; | |||
| 683 | case DW_OP_mul: | |||
| 684 | printf ("DW_OP_mul"); | |||
| 685 | break; | |||
| 686 | case DW_OP_neg: | |||
| 687 | printf ("DW_OP_neg"); | |||
| 688 | break; | |||
| 689 | case DW_OP_not: | |||
| 690 | printf ("DW_OP_not"); | |||
| 691 | break; | |||
| 692 | case DW_OP_or: | |||
| 693 | printf ("DW_OP_or"); | |||
| 694 | break; | |||
| 695 | case DW_OP_plus: | |||
| 696 | printf ("DW_OP_plus"); | |||
| 697 | break; | |||
| 698 | case DW_OP_plus_uconst: | |||
| 699 | printf ("DW_OP_plus_uconst: %lu", | |||
| 700 | read_leb128 (data, &bytes_read, 0)); | |||
| 701 | data += bytes_read; | |||
| 702 | break; | |||
| 703 | case DW_OP_shl: | |||
| 704 | printf ("DW_OP_shl"); | |||
| 705 | break; | |||
| 706 | case DW_OP_shr: | |||
| 707 | printf ("DW_OP_shr"); | |||
| 708 | break; | |||
| 709 | case DW_OP_shra: | |||
| 710 | printf ("DW_OP_shra"); | |||
| 711 | break; | |||
| 712 | case DW_OP_xor: | |||
| 713 | printf ("DW_OP_xor"); | |||
| 714 | break; | |||
| 715 | case DW_OP_bra: | |||
| 716 | printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2)); | |||
| 717 | data += 2; | |||
| 718 | break; | |||
| 719 | case DW_OP_eq: | |||
| 720 | printf ("DW_OP_eq"); | |||
| 721 | break; | |||
| 722 | case DW_OP_ge: | |||
| 723 | printf ("DW_OP_ge"); | |||
| 724 | break; | |||
| 725 | case DW_OP_gt: | |||
| 726 | printf ("DW_OP_gt"); | |||
| 727 | break; | |||
| 728 | case DW_OP_le: | |||
| 729 | printf ("DW_OP_le"); | |||
| 730 | break; | |||
| 731 | case DW_OP_lt: | |||
| 732 | printf ("DW_OP_lt"); | |||
| 733 | break; | |||
| 734 | case DW_OP_ne: | |||
| 735 | printf ("DW_OP_ne"); | |||
| 736 | break; | |||
| 737 | case DW_OP_skip: | |||
| 738 | printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2)); | |||
| 739 | data += 2; | |||
| 740 | break; | |||
| 741 | ||||
| 742 | case DW_OP_lit0: | |||
| 743 | case DW_OP_lit1: | |||
| 744 | case DW_OP_lit2: | |||
| 745 | case DW_OP_lit3: | |||
| 746 | case DW_OP_lit4: | |||
| 747 | case DW_OP_lit5: | |||
| 748 | case DW_OP_lit6: | |||
| 749 | case DW_OP_lit7: | |||
| 750 | case DW_OP_lit8: | |||
| 751 | case DW_OP_lit9: | |||
| 752 | case DW_OP_lit10: | |||
| 753 | case DW_OP_lit11: | |||
| 754 | case DW_OP_lit12: | |||
| 755 | case DW_OP_lit13: | |||
| 756 | case DW_OP_lit14: | |||
| 757 | case DW_OP_lit15: | |||
| 758 | case DW_OP_lit16: | |||
| 759 | case DW_OP_lit17: | |||
| 760 | case DW_OP_lit18: | |||
| 761 | case DW_OP_lit19: | |||
| 762 | case DW_OP_lit20: | |||
| 763 | case DW_OP_lit21: | |||
| 764 | case DW_OP_lit22: | |||
| 765 | case DW_OP_lit23: | |||
| 766 | case DW_OP_lit24: | |||
| 767 | case DW_OP_lit25: | |||
| 768 | case DW_OP_lit26: | |||
| 769 | case DW_OP_lit27: | |||
| 770 | case DW_OP_lit28: | |||
| 771 | case DW_OP_lit29: | |||
| 772 | case DW_OP_lit30: | |||
| 773 | case DW_OP_lit31: | |||
| 774 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |||
| 775 | break; | |||
| 776 | ||||
| 777 | case DW_OP_reg0: | |||
| 778 | case DW_OP_reg1: | |||
| 779 | case DW_OP_reg2: | |||
| 780 | case DW_OP_reg3: | |||
| 781 | case DW_OP_reg4: | |||
| 782 | case DW_OP_reg5: | |||
| 783 | case DW_OP_reg6: | |||
| 784 | case DW_OP_reg7: | |||
| 785 | case DW_OP_reg8: | |||
| 786 | case DW_OP_reg9: | |||
| 787 | case DW_OP_reg10: | |||
| 788 | case DW_OP_reg11: | |||
| 789 | case DW_OP_reg12: | |||
| 790 | case DW_OP_reg13: | |||
| 791 | case DW_OP_reg14: | |||
| 792 | case DW_OP_reg15: | |||
| 793 | case DW_OP_reg16: | |||
| 794 | case DW_OP_reg17: | |||
| 795 | case DW_OP_reg18: | |||
| 796 | case DW_OP_reg19: | |||
| 797 | case DW_OP_reg20: | |||
| 798 | case DW_OP_reg21: | |||
| 799 | case DW_OP_reg22: | |||
| 800 | case DW_OP_reg23: | |||
| 801 | case DW_OP_reg24: | |||
| 802 | case DW_OP_reg25: | |||
| 803 | case DW_OP_reg26: | |||
| 804 | case DW_OP_reg27: | |||
| 805 | case DW_OP_reg28: | |||
| 806 | case DW_OP_reg29: | |||
| 807 | case DW_OP_reg30: | |||
| 808 | case DW_OP_reg31: | |||
| 809 | printf ("DW_OP_reg%d", op - DW_OP_reg0); | |||
| 810 | break; | |||
| 811 | ||||
| 812 | case DW_OP_breg0: | |||
| 813 | case DW_OP_breg1: | |||
| 814 | case DW_OP_breg2: | |||
| 815 | case DW_OP_breg3: | |||
| 816 | case DW_OP_breg4: | |||
| 817 | case DW_OP_breg5: | |||
| 818 | case DW_OP_breg6: | |||
| 819 | case DW_OP_breg7: | |||
| 820 | case DW_OP_breg8: | |||
| 821 | case DW_OP_breg9: | |||
| 822 | case DW_OP_breg10: | |||
| 823 | case DW_OP_breg11: | |||
| 824 | case DW_OP_breg12: | |||
| 825 | case DW_OP_breg13: | |||
| 826 | case DW_OP_breg14: | |||
| 827 | case DW_OP_breg15: | |||
| 828 | case DW_OP_breg16: | |||
| 829 | case DW_OP_breg17: | |||
| 830 | case DW_OP_breg18: | |||
| 831 | case DW_OP_breg19: | |||
| 832 | case DW_OP_breg20: | |||
| 833 | case DW_OP_breg21: | |||
| 834 | case DW_OP_breg22: | |||
| 835 | case DW_OP_breg23: | |||
| 836 | case DW_OP_breg24: | |||
| 837 | case DW_OP_breg25: | |||
| 838 | case DW_OP_breg26: | |||
| 839 | case DW_OP_breg27: | |||
| 840 | case DW_OP_breg28: | |||
| 841 | case DW_OP_breg29: | |||
| 842 | case DW_OP_breg30: | |||
| 843 | case DW_OP_breg31: | |||
| 844 | printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0, | |||
| 845 | read_leb128 (data, &bytes_read, 1)); | |||
| 846 | data += bytes_read; | |||
| 847 | break; | |||
| 848 | ||||
| 849 | case DW_OP_regx: | |||
| 850 | printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0)); | |||
| 851 | data += bytes_read; | |||
| 852 | break; | |||
| 853 | case DW_OP_fbreg: | |||
| 854 | need_frame_base = 1; | |||
| 855 | printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1)); | |||
| 856 | data += bytes_read; | |||
| 857 | break; | |||
| 858 | case DW_OP_bregx: | |||
| 859 | uvalue = read_leb128 (data, &bytes_read, 0); | |||
| 860 | data += bytes_read; | |||
| 861 | printf ("DW_OP_bregx: %lu %ld", uvalue, | |||
| 862 | read_leb128 (data, &bytes_read, 1)); | |||
| 863 | data += bytes_read; | |||
| 864 | break; | |||
| 865 | case DW_OP_piece: | |||
| 866 | printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0)); | |||
| 867 | data += bytes_read; | |||
| 868 | break; | |||
| 869 | case DW_OP_deref_size: | |||
| 870 | printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1)); | |||
| 871 | break; | |||
| 872 | case DW_OP_xderef_size: | |||
| 873 | printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1)); | |||
| 874 | break; | |||
| 875 | case DW_OP_nop: | |||
| 876 | printf ("DW_OP_nop"); | |||
| 877 | break; | |||
| 878 | ||||
| 879 | /* DWARF 3 extensions. */ | |||
| 880 | case DW_OP_push_object_address: | |||
| 881 | printf ("DW_OP_push_object_address"); | |||
| 882 | break; | |||
| 883 | case DW_OP_call2: | |||
| 884 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |||
| 885 | this ought to be an 8-byte wide computation. */ | |||
| 886 | printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset); | |||
| 887 | data += 2; | |||
| 888 | break; | |||
| 889 | case DW_OP_call4: | |||
| 890 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |||
| 891 | this ought to be an 8-byte wide computation. */ | |||
| 892 | printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset); | |||
| 893 | data += 4; | |||
| 894 | break; | |||
| 895 | case DW_OP_call_ref: | |||
| 896 | printf ("DW_OP_call_ref"); | |||
| 897 | break; | |||
| 898 | ||||
| 899 | /* GNU extensions. */ | |||
| 900 | case DW_OP_GNU_push_tls_address: | |||
| 901 | printf ("DW_OP_GNU_push_tls_address"); | |||
| 902 | break; | |||
| 903 | ||||
| 904 | default: | |||
| 905 | if (op >= DW_OP_lo_user0xe0 | |||
| 906 | && op <= DW_OP_hi_user0xff) | |||
| 907 | printf (_("(User defined location op)")("(User defined location op)")); | |||
| 908 | else | |||
| 909 | printf (_("(Unknown location op)")("(Unknown location op)")); | |||
| 910 | /* No way to tell where the next op is, so just bail. */ | |||
| 911 | return need_frame_base; | |||
| 912 | } | |||
| 913 | ||||
| 914 | /* Separate the ops. */ | |||
| 915 | if (data < end) | |||
| 916 | printf ("; "); | |||
| 917 | } | |||
| 918 | ||||
| 919 | return need_frame_base; | |||
| 920 | } | |||
| 921 | ||||
| 922 | static unsigned char * | |||
| 923 | read_and_display_attr_value (unsigned long attribute, | |||
| 924 | unsigned long form, | |||
| 925 | unsigned char *data, | |||
| 926 | unsigned long cu_offset, | |||
| 927 | unsigned long pointer_size, | |||
| 928 | unsigned long offset_size, | |||
| 929 | int dwarf_version, | |||
| 930 | debug_info *debug_info_p, | |||
| 931 | int do_loc) | |||
| 932 | { | |||
| 933 | unsigned long uvalue = 0; | |||
| 934 | unsigned char *block_start = NULL((void*)0); | |||
| 935 | unsigned int bytes_read; | |||
| 936 | ||||
| 937 | switch (form) | |||
| 938 | { | |||
| 939 | default: | |||
| 940 | break; | |||
| 941 | ||||
| 942 | case DW_FORM_ref_addr: | |||
| 943 | if (dwarf_version == 2) | |||
| 944 | { | |||
| 945 | uvalue = byte_get (data, pointer_size); | |||
| 946 | data += pointer_size; | |||
| 947 | } | |||
| 948 | else if (dwarf_version == 3) | |||
| 949 | { | |||
| 950 | uvalue = byte_get (data, offset_size); | |||
| 951 | data += offset_size; | |||
| 952 | } | |||
| 953 | else | |||
| 954 | { | |||
| 955 | error (_("Internal error: DWARF version is not 2 or 3.\n")("Internal error: DWARF version is not 2 or 3.\n")); | |||
| 956 | } | |||
| 957 | break; | |||
| 958 | ||||
| 959 | case DW_FORM_addr: | |||
| 960 | uvalue = byte_get (data, pointer_size); | |||
| 961 | data += pointer_size; | |||
| 962 | break; | |||
| 963 | ||||
| 964 | case DW_FORM_strp: | |||
| 965 | uvalue = byte_get (data, offset_size); | |||
| 966 | data += offset_size; | |||
| 967 | break; | |||
| 968 | ||||
| 969 | case DW_FORM_ref1: | |||
| 970 | case DW_FORM_flag: | |||
| 971 | case DW_FORM_data1: | |||
| 972 | uvalue = byte_get (data++, 1); | |||
| 973 | break; | |||
| 974 | ||||
| 975 | case DW_FORM_ref2: | |||
| 976 | case DW_FORM_data2: | |||
| 977 | uvalue = byte_get (data, 2); | |||
| 978 | data += 2; | |||
| 979 | break; | |||
| 980 | ||||
| 981 | case DW_FORM_ref4: | |||
| 982 | case DW_FORM_data4: | |||
| 983 | uvalue = byte_get (data, 4); | |||
| 984 | data += 4; | |||
| 985 | break; | |||
| 986 | ||||
| 987 | case DW_FORM_sdata: | |||
| 988 | uvalue = read_leb128 (data, & bytes_read, 1); | |||
| 989 | data += bytes_read; | |||
| 990 | break; | |||
| 991 | ||||
| 992 | case DW_FORM_ref_udata: | |||
| 993 | case DW_FORM_udata: | |||
| 994 | uvalue = read_leb128 (data, & bytes_read, 0); | |||
| 995 | data += bytes_read; | |||
| 996 | break; | |||
| 997 | ||||
| 998 | case DW_FORM_indirect: | |||
| 999 | form = read_leb128 (data, & bytes_read, 0); | |||
| 1000 | data += bytes_read; | |||
| 1001 | if (!do_loc) | |||
| 1002 | printf (" %s", get_FORM_name (form)); | |||
| 1003 | return read_and_display_attr_value (attribute, form, data, | |||
| 1004 | cu_offset, pointer_size, | |||
| 1005 | offset_size, dwarf_version, | |||
| 1006 | debug_info_p, do_loc); | |||
| 1007 | } | |||
| 1008 | ||||
| 1009 | switch (form) | |||
| 1010 | { | |||
| 1011 | case DW_FORM_ref_addr: | |||
| 1012 | if (!do_loc) | |||
| 1013 | printf (" <#%lx>", uvalue); | |||
| 1014 | break; | |||
| 1015 | ||||
| 1016 | case DW_FORM_ref1: | |||
| 1017 | case DW_FORM_ref2: | |||
| 1018 | case DW_FORM_ref4: | |||
| 1019 | case DW_FORM_ref_udata: | |||
| 1020 | if (!do_loc) | |||
| 1021 | printf (" <%lx>", uvalue + cu_offset); | |||
| 1022 | break; | |||
| 1023 | ||||
| 1024 | case DW_FORM_data4: | |||
| 1025 | case DW_FORM_addr: | |||
| 1026 | if (!do_loc) | |||
| 1027 | printf (" %#lx", uvalue); | |||
| 1028 | break; | |||
| 1029 | ||||
| 1030 | case DW_FORM_flag: | |||
| 1031 | case DW_FORM_data1: | |||
| 1032 | case DW_FORM_data2: | |||
| 1033 | case DW_FORM_sdata: | |||
| 1034 | case DW_FORM_udata: | |||
| 1035 | if (!do_loc) | |||
| 1036 | printf (" %ld", uvalue); | |||
| 1037 | break; | |||
| 1038 | ||||
| 1039 | case DW_FORM_ref8: | |||
| 1040 | case DW_FORM_data8: | |||
| 1041 | if (!do_loc) | |||
| 1042 | { | |||
| 1043 | uvalue = byte_get (data, 4); | |||
| 1044 | printf (" %lx", uvalue); | |||
| 1045 | printf (" %lx", (unsigned long) byte_get (data + 4, 4)); | |||
| 1046 | } | |||
| 1047 | if ((do_loc || do_debug_loc || do_debug_ranges) | |||
| 1048 | && num_debug_info_entries == 0) | |||
| 1049 | { | |||
| 1050 | if (sizeof (uvalue) == 8) | |||
| 1051 | uvalue = byte_get (data, 8); | |||
| 1052 | else | |||
| 1053 | error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n")("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n" )); | |||
| 1054 | } | |||
| 1055 | data += 8; | |||
| 1056 | break; | |||
| 1057 | ||||
| 1058 | case DW_FORM_string: | |||
| 1059 | if (!do_loc) | |||
| 1060 | printf (" %s", data); | |||
| 1061 | data += strlen ((char *) data) + 1; | |||
| 1062 | break; | |||
| 1063 | ||||
| 1064 | case DW_FORM_block: | |||
| 1065 | uvalue = read_leb128 (data, & bytes_read, 0); | |||
| 1066 | block_start = data + bytes_read; | |||
| 1067 | if (do_loc) | |||
| 1068 | data = block_start + uvalue; | |||
| 1069 | else | |||
| 1070 | data = display_block (block_start, uvalue); | |||
| 1071 | break; | |||
| 1072 | ||||
| 1073 | case DW_FORM_block1: | |||
| 1074 | uvalue = byte_get (data, 1); | |||
| 1075 | block_start = data + 1; | |||
| 1076 | if (do_loc) | |||
| 1077 | data = block_start + uvalue; | |||
| 1078 | else | |||
| 1079 | data = display_block (block_start, uvalue); | |||
| 1080 | break; | |||
| 1081 | ||||
| 1082 | case DW_FORM_block2: | |||
| 1083 | uvalue = byte_get (data, 2); | |||
| 1084 | block_start = data + 2; | |||
| 1085 | if (do_loc) | |||
| 1086 | data = block_start + uvalue; | |||
| 1087 | else | |||
| 1088 | data = display_block (block_start, uvalue); | |||
| 1089 | break; | |||
| 1090 | ||||
| 1091 | case DW_FORM_block4: | |||
| 1092 | uvalue = byte_get (data, 4); | |||
| 1093 | block_start = data + 4; | |||
| 1094 | if (do_loc) | |||
| 1095 | data = block_start + uvalue; | |||
| 1096 | else | |||
| 1097 | data = display_block (block_start, uvalue); | |||
| 1098 | break; | |||
| 1099 | ||||
| 1100 | case DW_FORM_strp: | |||
| 1101 | if (!do_loc) | |||
| 1102 | printf (_(" (indirect string, offset: 0x%lx): %s")(" (indirect string, offset: 0x%lx): %s"), | |||
| 1103 | uvalue, fetch_indirect_string (uvalue)); | |||
| 1104 | break; | |||
| 1105 | ||||
| 1106 | case DW_FORM_indirect: | |||
| 1107 | /* Handled above. */ | |||
| 1108 | break; | |||
| 1109 | ||||
| 1110 | default: | |||
| 1111 | warn (_("Unrecognized form: %lu\n")("Unrecognized form: %lu\n"), form); | |||
| 1112 | break; | |||
| 1113 | } | |||
| 1114 | ||||
| 1115 | /* For some attributes we can display further information. */ | |||
| 1116 | if ((do_loc || do_debug_loc || do_debug_ranges) | |||
| 1117 | && num_debug_info_entries == 0) | |||
| 1118 | { | |||
| 1119 | switch (attribute) | |||
| 1120 | { | |||
| 1121 | case DW_AT_frame_base: | |||
| 1122 | have_frame_base = 1; | |||
| 1123 | case DW_AT_location: | |||
| 1124 | case DW_AT_data_member_location: | |||
| 1125 | case DW_AT_vtable_elem_location: | |||
| 1126 | case DW_AT_allocated: | |||
| 1127 | case DW_AT_associated: | |||
| 1128 | case DW_AT_data_location: | |||
| 1129 | case DW_AT_stride: | |||
| 1130 | case DW_AT_upper_bound: | |||
| 1131 | case DW_AT_lower_bound: | |||
| 1132 | if (form == DW_FORM_data4 || form == DW_FORM_data8) | |||
| 1133 | { | |||
| 1134 | /* Process location list. */ | |||
| 1135 | unsigned int max = debug_info_p->max_loc_offsets; | |||
| 1136 | unsigned int num = debug_info_p->num_loc_offsets; | |||
| 1137 | ||||
| 1138 | if (max == 0 || num >= max) | |||
| 1139 | { | |||
| 1140 | max += 1024; | |||
| 1141 | debug_info_p->loc_offsets | |||
| 1142 | = xcrealloc (debug_info_p->loc_offsets, | |||
| 1143 | max, sizeof (*debug_info_p->loc_offsets)); | |||
| 1144 | debug_info_p->have_frame_base | |||
| 1145 | = xcrealloc (debug_info_p->have_frame_base, | |||
| 1146 | max, sizeof (*debug_info_p->have_frame_base)); | |||
| 1147 | debug_info_p->max_loc_offsets = max; | |||
| 1148 | } | |||
| 1149 | debug_info_p->loc_offsets [num] = uvalue; | |||
| 1150 | debug_info_p->have_frame_base [num] = have_frame_base; | |||
| 1151 | debug_info_p->num_loc_offsets++; | |||
| 1152 | } | |||
| 1153 | break; | |||
| 1154 | ||||
| 1155 | case DW_AT_low_pc: | |||
| 1156 | if (need_base_address) | |||
| 1157 | debug_info_p->base_address = uvalue; | |||
| 1158 | break; | |||
| 1159 | ||||
| 1160 | case DW_AT_ranges: | |||
| 1161 | if (form == DW_FORM_data4 || form == DW_FORM_data8) | |||
| 1162 | { | |||
| 1163 | /* Process range list. */ | |||
| 1164 | unsigned int max = debug_info_p->max_range_lists; | |||
| 1165 | unsigned int num = debug_info_p->num_range_lists; | |||
| 1166 | ||||
| 1167 | if (max == 0 || num >= max) | |||
| 1168 | { | |||
| 1169 | max += 1024; | |||
| 1170 | debug_info_p->range_lists | |||
| 1171 | = xcrealloc (debug_info_p->range_lists, | |||
| 1172 | max, sizeof (*debug_info_p->range_lists)); | |||
| 1173 | debug_info_p->max_range_lists = max; | |||
| 1174 | } | |||
| 1175 | debug_info_p->range_lists [num] = uvalue; | |||
| 1176 | debug_info_p->num_range_lists++; | |||
| 1177 | } | |||
| 1178 | break; | |||
| 1179 | ||||
| 1180 | default: | |||
| 1181 | break; | |||
| 1182 | } | |||
| 1183 | } | |||
| 1184 | ||||
| 1185 | if (do_loc) | |||
| 1186 | return data; | |||
| 1187 | ||||
| 1188 | printf ("\t"); | |||
| 1189 | ||||
| 1190 | switch (attribute) | |||
| 1191 | { | |||
| 1192 | case DW_AT_inline: | |||
| 1193 | switch (uvalue) | |||
| 1194 | { | |||
| 1195 | case DW_INL_not_inlined: | |||
| 1196 | printf (_("(not inlined)")("(not inlined)")); | |||
| 1197 | break; | |||
| 1198 | case DW_INL_inlined: | |||
| 1199 | printf (_("(inlined)")("(inlined)")); | |||
| 1200 | break; | |||
| 1201 | case DW_INL_declared_not_inlined: | |||
| 1202 | printf (_("(declared as inline but ignored)")("(declared as inline but ignored)")); | |||
| 1203 | break; | |||
| 1204 | case DW_INL_declared_inlined: | |||
| 1205 | printf (_("(declared as inline and inlined)")("(declared as inline and inlined)")); | |||
| 1206 | break; | |||
| 1207 | default: | |||
| 1208 | printf (_(" (Unknown inline attribute value: %lx)")(" (Unknown inline attribute value: %lx)"), uvalue); | |||
| 1209 | break; | |||
| 1210 | } | |||
| 1211 | break; | |||
| 1212 | ||||
| 1213 | case DW_AT_language: | |||
| 1214 | switch (uvalue) | |||
| 1215 | { | |||
| 1216 | case DW_LANG_C: printf ("(non-ANSI C)"); break; | |||
| 1217 | case DW_LANG_C89: printf ("(ANSI C)"); break; | |||
| 1218 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; | |||
| 1219 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; | |||
| 1220 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |||
| 1221 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; | |||
| 1222 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; | |||
| 1223 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |||
| 1224 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; | |||
| 1225 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |||
| 1226 | /* DWARF 2.1 values. */ | |||
| 1227 | case DW_LANG_C99: printf ("(ANSI C99)"); break; | |||
| 1228 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |||
| 1229 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |||
| 1230 | /* MIPS extension. */ | |||
| 1231 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |||
| 1232 | /* UPC extension. */ | |||
| 1233 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |||
| 1234 | default: | |||
| 1235 | printf ("(Unknown: %lx)", uvalue); | |||
| 1236 | break; | |||
| 1237 | } | |||
| 1238 | break; | |||
| 1239 | ||||
| 1240 | case DW_AT_encoding: | |||
| 1241 | switch (uvalue) | |||
| 1242 | { | |||
| 1243 | case DW_ATE_void: printf ("(void)"); break; | |||
| 1244 | case DW_ATE_address: printf ("(machine address)"); break; | |||
| 1245 | case DW_ATE_boolean: printf ("(boolean)"); break; | |||
| 1246 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |||
| 1247 | case DW_ATE_float: printf ("(float)"); break; | |||
| 1248 | case DW_ATE_signed: printf ("(signed)"); break; | |||
| 1249 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |||
| 1250 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |||
| 1251 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |||
| 1252 | /* DWARF 2.1 value. */ | |||
| 1253 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; | |||
| 1254 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |||
| 1255 | default: | |||
| 1256 | if (uvalue >= DW_ATE_lo_user0x80 | |||
| 1257 | && uvalue <= DW_ATE_hi_user0xff) | |||
| 1258 | printf ("(user defined type)"); | |||
| 1259 | else | |||
| 1260 | printf ("(unknown type)"); | |||
| 1261 | break; | |||
| 1262 | } | |||
| 1263 | break; | |||
| 1264 | ||||
| 1265 | case DW_AT_accessibility: | |||
| 1266 | switch (uvalue) | |||
| 1267 | { | |||
| 1268 | case DW_ACCESS_public: printf ("(public)"); break; | |||
| 1269 | case DW_ACCESS_protected: printf ("(protected)"); break; | |||
| 1270 | case DW_ACCESS_private: printf ("(private)"); break; | |||
| 1271 | default: | |||
| 1272 | printf ("(unknown accessibility)"); | |||
| 1273 | break; | |||
| 1274 | } | |||
| 1275 | break; | |||
| 1276 | ||||
| 1277 | case DW_AT_visibility: | |||
| 1278 | switch (uvalue) | |||
| 1279 | { | |||
| 1280 | case DW_VIS_local: printf ("(local)"); break; | |||
| 1281 | case DW_VIS_exported: printf ("(exported)"); break; | |||
| 1282 | case DW_VIS_qualified: printf ("(qualified)"); break; | |||
| 1283 | default: printf ("(unknown visibility)"); break; | |||
| 1284 | } | |||
| 1285 | break; | |||
| 1286 | ||||
| 1287 | case DW_AT_virtuality: | |||
| 1288 | switch (uvalue) | |||
| 1289 | { | |||
| 1290 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |||
| 1291 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |||
| 1292 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |||
| 1293 | default: printf ("(unknown virtuality)"); break; | |||
| 1294 | } | |||
| 1295 | break; | |||
| 1296 | ||||
| 1297 | case DW_AT_identifier_case: | |||
| 1298 | switch (uvalue) | |||
| 1299 | { | |||
| 1300 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |||
| 1301 | case DW_ID_up_case: printf ("(up_case)"); break; | |||
| 1302 | case DW_ID_down_case: printf ("(down_case)"); break; | |||
| 1303 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |||
| 1304 | default: printf ("(unknown case)"); break; | |||
| 1305 | } | |||
| 1306 | break; | |||
| 1307 | ||||
| 1308 | case DW_AT_calling_convention: | |||
| 1309 | switch (uvalue) | |||
| 1310 | { | |||
| 1311 | case DW_CC_normal: printf ("(normal)"); break; | |||
| 1312 | case DW_CC_program: printf ("(program)"); break; | |||
| 1313 | case DW_CC_nocall: printf ("(nocall)"); break; | |||
| 1314 | default: | |||
| 1315 | if (uvalue >= DW_CC_lo_user0x40 | |||
| 1316 | && uvalue <= DW_CC_hi_user0xff) | |||
| 1317 | printf ("(user defined)"); | |||
| 1318 | else | |||
| 1319 | printf ("(unknown convention)"); | |||
| 1320 | } | |||
| 1321 | break; | |||
| 1322 | ||||
| 1323 | case DW_AT_ordering: | |||
| 1324 | switch (uvalue) | |||
| 1325 | { | |||
| 1326 | case -1: printf ("(undefined)"); break; | |||
| 1327 | case 0: printf ("(row major)"); break; | |||
| 1328 | case 1: printf ("(column major)"); break; | |||
| 1329 | } | |||
| 1330 | break; | |||
| 1331 | ||||
| 1332 | case DW_AT_frame_base: | |||
| 1333 | have_frame_base = 1; | |||
| 1334 | case DW_AT_location: | |||
| 1335 | case DW_AT_data_member_location: | |||
| 1336 | case DW_AT_vtable_elem_location: | |||
| 1337 | case DW_AT_allocated: | |||
| 1338 | case DW_AT_associated: | |||
| 1339 | case DW_AT_data_location: | |||
| 1340 | case DW_AT_stride: | |||
| 1341 | case DW_AT_upper_bound: | |||
| 1342 | case DW_AT_lower_bound: | |||
| 1343 | if (block_start) | |||
| 1344 | { | |||
| 1345 | int need_frame_base; | |||
| 1346 | ||||
| 1347 | printf ("("); | |||
| 1348 | need_frame_base = decode_location_expression (block_start, | |||
| 1349 | pointer_size, | |||
| 1350 | uvalue, | |||
| 1351 | cu_offset); | |||
| 1352 | printf (")"); | |||
| 1353 | if (need_frame_base && !have_frame_base) | |||
| 1354 | printf (_(" [without DW_AT_frame_base]")(" [without DW_AT_frame_base]")); | |||
| 1355 | } | |||
| 1356 | else if (form == DW_FORM_data4 || form == DW_FORM_data8) | |||
| 1357 | printf (_("(location list)")("(location list)")); | |||
| 1358 | ||||
| 1359 | break; | |||
| 1360 | ||||
| 1361 | default: | |||
| 1362 | break; | |||
| 1363 | } | |||
| 1364 | ||||
| 1365 | return data; | |||
| 1366 | } | |||
| 1367 | ||||
| 1368 | static char * | |||
| 1369 | get_AT_name (unsigned long attribute) | |||
| 1370 | { | |||
| 1371 | switch (attribute) | |||
| 1372 | { | |||
| 1373 | case DW_AT_sibling: return "DW_AT_sibling"; | |||
| 1374 | case DW_AT_location: return "DW_AT_location"; | |||
| 1375 | case DW_AT_name: return "DW_AT_name"; | |||
| 1376 | case DW_AT_ordering: return "DW_AT_ordering"; | |||
| 1377 | case DW_AT_subscr_data: return "DW_AT_subscr_data"; | |||
| 1378 | case DW_AT_byte_size: return "DW_AT_byte_size"; | |||
| 1379 | case DW_AT_bit_offset: return "DW_AT_bit_offset"; | |||
| 1380 | case DW_AT_bit_size: return "DW_AT_bit_size"; | |||
| 1381 | case DW_AT_element_list: return "DW_AT_element_list"; | |||
| 1382 | case DW_AT_stmt_list: return "DW_AT_stmt_list"; | |||
| 1383 | case DW_AT_low_pc: return "DW_AT_low_pc"; | |||
| 1384 | case DW_AT_high_pc: return "DW_AT_high_pc"; | |||
| 1385 | case DW_AT_language: return "DW_AT_language"; | |||
| 1386 | case DW_AT_member: return "DW_AT_member"; | |||
| 1387 | case DW_AT_discr: return "DW_AT_discr"; | |||
| 1388 | case DW_AT_discr_value: return "DW_AT_discr_value"; | |||
| 1389 | case DW_AT_visibility: return "DW_AT_visibility"; | |||
| 1390 | case DW_AT_import: return "DW_AT_import"; | |||
| 1391 | case DW_AT_string_length: return "DW_AT_string_length"; | |||
| 1392 | case DW_AT_common_reference: return "DW_AT_common_reference"; | |||
| 1393 | case DW_AT_comp_dir: return "DW_AT_comp_dir"; | |||
| 1394 | case DW_AT_const_value: return "DW_AT_const_value"; | |||
| 1395 | case DW_AT_containing_type: return "DW_AT_containing_type"; | |||
| 1396 | case DW_AT_default_value: return "DW_AT_default_value"; | |||
| 1397 | case DW_AT_inline: return "DW_AT_inline"; | |||
| 1398 | case DW_AT_is_optional: return "DW_AT_is_optional"; | |||
| 1399 | case DW_AT_lower_bound: return "DW_AT_lower_bound"; | |||
| 1400 | case DW_AT_producer: return "DW_AT_producer"; | |||
| 1401 | case DW_AT_prototyped: return "DW_AT_prototyped"; | |||
| 1402 | case DW_AT_return_addr: return "DW_AT_return_addr"; | |||
| 1403 | case DW_AT_start_scope: return "DW_AT_start_scope"; | |||
| 1404 | case DW_AT_stride_size: return "DW_AT_stride_size"; | |||
| 1405 | case DW_AT_upper_bound: return "DW_AT_upper_bound"; | |||
| 1406 | case DW_AT_abstract_origin: return "DW_AT_abstract_origin"; | |||
| 1407 | case DW_AT_accessibility: return "DW_AT_accessibility"; | |||
| 1408 | case DW_AT_address_class: return "DW_AT_address_class"; | |||
| 1409 | case DW_AT_artificial: return "DW_AT_artificial"; | |||
| 1410 | case DW_AT_base_types: return "DW_AT_base_types"; | |||
| 1411 | case DW_AT_calling_convention: return "DW_AT_calling_convention"; | |||
| 1412 | case DW_AT_count: return "DW_AT_count"; | |||
| 1413 | case DW_AT_data_member_location: return "DW_AT_data_member_location"; | |||
| 1414 | case DW_AT_decl_column: return "DW_AT_decl_column"; | |||
| 1415 | case DW_AT_decl_file: return "DW_AT_decl_file"; | |||
| 1416 | case DW_AT_decl_line: return "DW_AT_decl_line"; | |||
| 1417 | case DW_AT_declaration: return "DW_AT_declaration"; | |||
| 1418 | case DW_AT_discr_list: return "DW_AT_discr_list"; | |||
| 1419 | case DW_AT_encoding: return "DW_AT_encoding"; | |||
| 1420 | case DW_AT_external: return "DW_AT_external"; | |||
| 1421 | case DW_AT_frame_base: return "DW_AT_frame_base"; | |||
| 1422 | case DW_AT_friend: return "DW_AT_friend"; | |||
| 1423 | case DW_AT_identifier_case: return "DW_AT_identifier_case"; | |||
| 1424 | case DW_AT_macro_info: return "DW_AT_macro_info"; | |||
| 1425 | case DW_AT_namelist_items: return "DW_AT_namelist_items"; | |||
| 1426 | case DW_AT_priority: return "DW_AT_priority"; | |||
| 1427 | case DW_AT_segment: return "DW_AT_segment"; | |||
| 1428 | case DW_AT_specification: return "DW_AT_specification"; | |||
| 1429 | case DW_AT_static_link: return "DW_AT_static_link"; | |||
| 1430 | case DW_AT_type: return "DW_AT_type"; | |||
| 1431 | case DW_AT_use_location: return "DW_AT_use_location"; | |||
| 1432 | case DW_AT_variable_parameter: return "DW_AT_variable_parameter"; | |||
| 1433 | case DW_AT_virtuality: return "DW_AT_virtuality"; | |||
| 1434 | case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location"; | |||
| 1435 | /* DWARF 2.1 values. */ | |||
| 1436 | case DW_AT_allocated: return "DW_AT_allocated"; | |||
| 1437 | case DW_AT_associated: return "DW_AT_associated"; | |||
| 1438 | case DW_AT_data_location: return "DW_AT_data_location"; | |||
| 1439 | case DW_AT_stride: return "DW_AT_stride"; | |||
| 1440 | case DW_AT_entry_pc: return "DW_AT_entry_pc"; | |||
| 1441 | case DW_AT_use_UTF8: return "DW_AT_use_UTF8"; | |||
| 1442 | case DW_AT_extension: return "DW_AT_extension"; | |||
| 1443 | case DW_AT_ranges: return "DW_AT_ranges"; | |||
| 1444 | case DW_AT_trampoline: return "DW_AT_trampoline"; | |||
| 1445 | case DW_AT_call_column: return "DW_AT_call_column"; | |||
| 1446 | case DW_AT_call_file: return "DW_AT_call_file"; | |||
| 1447 | case DW_AT_call_line: return "DW_AT_call_line"; | |||
| 1448 | /* SGI/MIPS extensions. */ | |||
| 1449 | case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde"; | |||
| 1450 | case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin"; | |||
| 1451 | case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin"; | |||
| 1452 | case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin"; | |||
| 1453 | case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor"; | |||
| 1454 | case DW_AT_MIPS_software_pipeline_depth: | |||
| 1455 | return "DW_AT_MIPS_software_pipeline_depth"; | |||
| 1456 | case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name"; | |||
| 1457 | case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride"; | |||
| 1458 | case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name"; | |||
| 1459 | case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin"; | |||
| 1460 | case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines"; | |||
| 1461 | /* GNU extensions. */ | |||
| 1462 | case DW_AT_sf_names: return "DW_AT_sf_names"; | |||
| 1463 | case DW_AT_src_info: return "DW_AT_src_info"; | |||
| 1464 | case DW_AT_mac_info: return "DW_AT_mac_info"; | |||
| 1465 | case DW_AT_src_coords: return "DW_AT_src_coords"; | |||
| 1466 | case DW_AT_body_begin: return "DW_AT_body_begin"; | |||
| 1467 | case DW_AT_body_end: return "DW_AT_body_end"; | |||
| 1468 | case DW_AT_GNU_vector: return "DW_AT_GNU_vector"; | |||
| 1469 | /* UPC extension. */ | |||
| 1470 | case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled"; | |||
| 1471 | default: | |||
| 1472 | { | |||
| 1473 | static char buffer[100]; | |||
| 1474 | ||||
| 1475 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx")("Unknown AT value: %lx"), | |||
| 1476 | attribute); | |||
| 1477 | return buffer; | |||
| 1478 | } | |||
| 1479 | } | |||
| 1480 | } | |||
| 1481 | ||||
| 1482 | static unsigned char * | |||
| 1483 | read_and_display_attr (unsigned long attribute, | |||
| 1484 | unsigned long form, | |||
| 1485 | unsigned char *data, | |||
| 1486 | unsigned long cu_offset, | |||
| 1487 | unsigned long pointer_size, | |||
| 1488 | unsigned long offset_size, | |||
| 1489 | int dwarf_version, | |||
| 1490 | debug_info *debug_info_p, | |||
| 1491 | int do_loc) | |||
| 1492 | { | |||
| 1493 | if (!do_loc) | |||
| 1494 | printf (" %-18s:", get_AT_name (attribute)); | |||
| 1495 | data = read_and_display_attr_value (attribute, form, data, cu_offset, | |||
| 1496 | pointer_size, offset_size, | |||
| 1497 | dwarf_version, debug_info_p, | |||
| 1498 | do_loc); | |||
| 1499 | if (!do_loc) | |||
| 1500 | printf ("\n"); | |||
| 1501 | return data; | |||
| 1502 | } | |||
| 1503 | ||||
| 1504 | ||||
| 1505 | /* Process the contents of a .debug_info section. If do_loc is non-zero | |||
| 1506 | then we are scanning for location lists and we do not want to display | |||
| 1507 | anything to the user. */ | |||
| 1508 | ||||
| 1509 | static int | |||
| 1510 | process_debug_info (struct dwarf_section *section, void *file, | |||
| 1511 | int do_loc) | |||
| 1512 | { | |||
| 1513 | unsigned char *start = section->start; | |||
| 1514 | unsigned char *end = start + section->size; | |||
| 1515 | unsigned char *section_begin; | |||
| 1516 | unsigned int unit; | |||
| 1517 | unsigned int num_units = 0; | |||
| 1518 | ||||
| 1519 | if ((do_loc || do_debug_loc || do_debug_ranges) | |||
| 1520 | && num_debug_info_entries == 0) | |||
| 1521 | { | |||
| 1522 | unsigned long length; | |||
| 1523 | ||||
| 1524 | /* First scan the section to get the number of comp units. */ | |||
| 1525 | for (section_begin = start, num_units = 0; section_begin < end; | |||
| 1526 | num_units ++) | |||
| 1527 | { | |||
| 1528 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |||
| 1529 | will be the length. For a 64-bit DWARF section, it'll be | |||
| 1530 | the escape code 0xffffffff followed by an 8 byte length. */ | |||
| 1531 | length = byte_get (section_begin, 4); | |||
| 1532 | ||||
| 1533 | if (length == 0xffffffff) | |||
| 1534 | { | |||
| 1535 | length = byte_get (section_begin + 4, 8); | |||
| 1536 | section_begin += length + 12; | |||
| 1537 | } | |||
| 1538 | else | |||
| 1539 | section_begin += length + 4; | |||
| 1540 | } | |||
| 1541 | ||||
| 1542 | if (num_units == 0) | |||
| 1543 | { | |||
| 1544 | error (_("No comp units in %s section ?")("No comp units in %s section ?"), section->name); | |||
| 1545 | return 0; | |||
| 1546 | } | |||
| 1547 | ||||
| 1548 | /* Then allocate an array to hold the information. */ | |||
| 1549 | debug_information = cmalloc (num_units, | |||
| 1550 | sizeof (* debug_information)); | |||
| 1551 | if (debug_information == NULL((void*)0)) | |||
| 1552 | { | |||
| 1553 | error (_("Not enough memory for a debug info array of %u entries")("Not enough memory for a debug info array of %u entries"), | |||
| 1554 | num_units); | |||
| 1555 | return 0; | |||
| 1556 | } | |||
| 1557 | } | |||
| 1558 | ||||
| 1559 | if (!do_loc) | |||
| 1560 | { | |||
| 1561 | printf (_("The section %s contains:\n\n")("The section %s contains:\n\n"), section->name); | |||
| 1562 | ||||
| 1563 | load_debug_section (str, file); | |||
| 1564 | } | |||
| 1565 | ||||
| 1566 | load_debug_section (abbrev, file); | |||
| 1567 | if (debug_displays [abbrev].section.start == NULL((void*)0)) | |||
| 1568 | { | |||
| 1569 | warn (_("Unable to locate %s section!\n")("Unable to locate %s section!\n"), | |||
| 1570 | debug_displays [abbrev].section.name); | |||
| 1571 | return 0; | |||
| 1572 | } | |||
| 1573 | ||||
| 1574 | for (section_begin = start, unit = 0; start < end; unit++) | |||
| 1575 | { | |||
| 1576 | DWARF2_Internal_CompUnit compunit; | |||
| 1577 | unsigned char *hdrptr; | |||
| 1578 | unsigned char *cu_abbrev_offset_ptr; | |||
| 1579 | unsigned char *tags; | |||
| 1580 | int level; | |||
| 1581 | unsigned long cu_offset; | |||
| 1582 | int offset_size; | |||
| 1583 | int initial_length_size; | |||
| 1584 | ||||
| 1585 | hdrptr = start; | |||
| 1586 | ||||
| 1587 | compunit.cu_length = byte_get (hdrptr, 4); | |||
| 1588 | hdrptr += 4; | |||
| 1589 | ||||
| 1590 | if (compunit.cu_length == 0xffffffff) | |||
| 1591 | { | |||
| 1592 | compunit.cu_length = byte_get (hdrptr, 8); | |||
| 1593 | hdrptr += 8; | |||
| 1594 | offset_size = 8; | |||
| 1595 | initial_length_size = 12; | |||
| 1596 | } | |||
| 1597 | else | |||
| 1598 | { | |||
| 1599 | offset_size = 4; | |||
| 1600 | initial_length_size = 4; | |||
| 1601 | } | |||
| 1602 | ||||
| 1603 | compunit.cu_version = byte_get (hdrptr, 2); | |||
| 1604 | hdrptr += 2; | |||
| 1605 | ||||
| 1606 | cu_offset = start - section_begin; | |||
| 1607 | start += compunit.cu_length + initial_length_size; | |||
| 1608 | ||||
| 1609 | cu_abbrev_offset_ptr = hdrptr; | |||
| 1610 | compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size); | |||
| 1611 | hdrptr += offset_size; | |||
| 1612 | ||||
| 1613 | compunit.cu_pointer_size = byte_get (hdrptr, 1); | |||
| 1614 | hdrptr += 1; | |||
| 1615 | if ((do_loc || do_debug_loc || do_debug_ranges) | |||
| 1616 | && num_debug_info_entries == 0) | |||
| 1617 | { | |||
| 1618 | debug_information [unit].cu_offset = cu_offset; | |||
| 1619 | debug_information [unit].pointer_size | |||
| 1620 | = compunit.cu_pointer_size; | |||
| 1621 | debug_information [unit].base_address = 0; | |||
| 1622 | debug_information [unit].loc_offsets = NULL((void*)0); | |||
| 1623 | debug_information [unit].have_frame_base = NULL((void*)0); | |||
| 1624 | debug_information [unit].max_loc_offsets = 0; | |||
| 1625 | debug_information [unit].num_loc_offsets = 0; | |||
| 1626 | debug_information [unit].range_lists = NULL((void*)0); | |||
| 1627 | debug_information [unit].max_range_lists= 0; | |||
| 1628 | debug_information [unit].num_range_lists = 0; | |||
| 1629 | } | |||
| 1630 | ||||
| 1631 | tags = hdrptr; | |||
| 1632 | ||||
| 1633 | if (!do_loc) | |||
| 1634 | { | |||
| 1635 | printf (_(" Compilation Unit @ offset 0x%lx:\n")(" Compilation Unit @ offset 0x%lx:\n"), cu_offset); | |||
| 1636 | printf (_(" Length: %ld\n")(" Length: %ld\n"), compunit.cu_length); | |||
| 1637 | printf (_(" Version: %d\n")(" Version: %d\n"), compunit.cu_version); | |||
| 1638 | printf (_(" Abbrev Offset: %ld\n")(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); | |||
| 1639 | printf (_(" Pointer Size: %d\n")(" Pointer Size: %d\n"), compunit.cu_pointer_size); | |||
| 1640 | } | |||
| 1641 | ||||
| 1642 | if (compunit.cu_version != 2 && compunit.cu_version != 3) | |||
| 1643 | { | |||
| 1644 | warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n")("Only version 2 and 3 DWARF debug information is currently supported.\n" )); | |||
| 1645 | continue; | |||
| 1646 | } | |||
| 1647 | ||||
| 1648 | free_abbrevs (); | |||
| 1649 | ||||
| 1650 | /* Process the abbrevs used by this compilation unit. DWARF | |||
| 1651 | sections under Mach-O have non-zero addresses. */ | |||
| 1652 | process_abbrev_section | |||
| 1653 | ((unsigned char *) debug_displays [abbrev].section.start | |||
| 1654 | + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address, | |||
| 1655 | (unsigned char *) debug_displays [abbrev].section.start | |||
| 1656 | + debug_displays [abbrev].section.size); | |||
| 1657 | ||||
| 1658 | level = 0; | |||
| 1659 | while (tags < start) | |||
| 1660 | { | |||
| 1661 | unsigned int bytes_read; | |||
| 1662 | unsigned long abbrev_number; | |||
| 1663 | abbrev_entry *entry; | |||
| 1664 | abbrev_attr *attr; | |||
| 1665 | ||||
| 1666 | abbrev_number = read_leb128 (tags, & bytes_read, 0); | |||
| 1667 | tags += bytes_read; | |||
| 1668 | ||||
| 1669 | /* A null DIE marks the end of a list of children. */ | |||
| 1670 | if (abbrev_number == 0) | |||
| 1671 | { | |||
| 1672 | --level; | |||
| 1673 | continue; | |||
| 1674 | } | |||
| 1675 | ||||
| 1676 | /* Scan through the abbreviation list until we reach the | |||
| 1677 | correct entry. */ | |||
| 1678 | for (entry = first_abbrev; | |||
| 1679 | entry && entry->entry != abbrev_number; | |||
| 1680 | entry = entry->next) | |||
| 1681 | continue; | |||
| 1682 | ||||
| 1683 | if (entry == NULL((void*)0)) | |||
| 1684 | { | |||
| 1685 | warn (_("Unable to locate entry %lu in the abbreviation table\n")("Unable to locate entry %lu in the abbreviation table\n"), | |||
| 1686 | abbrev_number); | |||
| 1687 | return 0; | |||
| 1688 | } | |||
| 1689 | ||||
| 1690 | if (!do_loc) | |||
| 1691 | printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n")(" <%d><%lx>: Abbrev Number: %lu (%s)\n"), | |||
| 1692 | level, | |||
| 1693 | (unsigned long) (tags - section_begin | |||
| 1694 | - bytes_read), | |||
| 1695 | abbrev_number, | |||
| 1696 | get_TAG_name (entry->tag)); | |||
| 1697 | ||||
| 1698 | switch (entry->tag) | |||
| 1699 | { | |||
| 1700 | default: | |||
| 1701 | need_base_address = 0; | |||
| 1702 | break; | |||
| 1703 | case DW_TAG_compile_unit: | |||
| 1704 | need_base_address = 1; | |||
| 1705 | break; | |||
| 1706 | case DW_TAG_entry_point: | |||
| 1707 | case DW_TAG_inlined_subroutine: | |||
| 1708 | case DW_TAG_subprogram: | |||
| 1709 | need_base_address = 0; | |||
| 1710 | /* Assuming that there is no DW_AT_frame_base. */ | |||
| 1711 | have_frame_base = 0; | |||
| 1712 | break; | |||
| 1713 | } | |||
| 1714 | ||||
| 1715 | for (attr = entry->first_attr; attr; attr = attr->next) | |||
| 1716 | tags = read_and_display_attr (attr->attribute, | |||
| 1717 | attr->form, | |||
| 1718 | tags, cu_offset, | |||
| 1719 | compunit.cu_pointer_size, | |||
| 1720 | offset_size, | |||
| 1721 | compunit.cu_version, | |||
| 1722 | &debug_information [unit], | |||
| 1723 | do_loc); | |||
| 1724 | ||||
| 1725 | if (entry->children) | |||
| 1726 | ++level; | |||
| 1727 | } | |||
| 1728 | } | |||
| 1729 | ||||
| 1730 | /* Set num_debug_info_entries here so that it can be used to check if | |||
| 1731 | we need to process .debug_loc and .debug_ranges sections. */ | |||
| 1732 | if ((do_loc || do_debug_loc || do_debug_ranges) | |||
| 1733 | && num_debug_info_entries == 0) | |||
| 1734 | num_debug_info_entries = num_units; | |||
| 1735 | ||||
| 1736 | if (!do_loc) | |||
| 1737 | { | |||
| 1738 | printf ("\n"); | |||
| 1739 | } | |||
| 1740 | ||||
| 1741 | return 1; | |||
| 1742 | } | |||
| 1743 | ||||
| 1744 | /* Locate and scan the .debug_info section in the file and record the pointer | |||
| 1745 | sizes and offsets for the compilation units in it. Usually an executable | |||
| 1746 | will have just one pointer size, but this is not guaranteed, and so we try | |||
| 1747 | not to make any assumptions. Returns zero upon failure, or the number of | |||
| 1748 | compilation units upon success. */ | |||
| 1749 | ||||
| 1750 | static unsigned int | |||
| 1751 | load_debug_info (void * file) | |||
| 1752 | { | |||
| 1753 | /* Reset the last pointer size so that we can issue correct error | |||
| 1754 | messages if we are displaying the contents of more than one section. */ | |||
| 1755 | last_pointer_size = 0; | |||
| 1756 | warned_about_missing_comp_units = FALSE0; | |||
| 1757 | ||||
| 1758 | /* If we already have the information there is nothing else to do. */ | |||
| 1759 | if (num_debug_info_entries > 0) | |||
| 1760 | return num_debug_info_entries; | |||
| 1761 | ||||
| 1762 | if (load_debug_section (info, file) | |||
| 1763 | && process_debug_info (&debug_displays [info].section, file, 1)) | |||
| 1764 | return num_debug_info_entries; | |||
| 1765 | else | |||
| 1766 | return 0; | |||
| 1767 | } | |||
| 1768 | ||||
| 1769 | static int | |||
| 1770 | display_debug_lines (struct dwarf_section *section, void *file) | |||
| 1771 | { | |||
| 1772 | unsigned char *start = section->start; | |||
| 1773 | unsigned char *data = start; | |||
| 1774 | unsigned char *end = start + section->size; | |||
| 1775 | ||||
| 1776 | printf (_("\nDump of debug contents of section %s:\n\n")("\nDump of debug contents of section %s:\n\n"), | |||
| 1777 | section->name); | |||
| 1778 | ||||
| 1779 | load_debug_info (file); | |||
| 1780 | ||||
| 1781 | while (data < end) | |||
| 1782 | { | |||
| 1783 | DWARF2_Internal_LineInfo info; | |||
| 1784 | unsigned char *standard_opcodes; | |||
| 1785 | unsigned char *end_of_sequence; | |||
| 1786 | unsigned char *hdrptr; | |||
| 1787 | int initial_length_size; | |||
| 1788 | int offset_size; | |||
| 1789 | int i; | |||
| 1790 | ||||
| 1791 | hdrptr = data; | |||
| 1792 | ||||
| 1793 | /* Check the length of the block. */ | |||
| 1794 | info.li_length = byte_get (hdrptr, 4); | |||
| 1795 | hdrptr += 4; | |||
| 1796 | ||||
| 1797 | if (info.li_length == 0xffffffff) | |||
| 1798 | { | |||
| 1799 | /* This section is 64-bit DWARF 3. */ | |||
| 1800 | info.li_length = byte_get (hdrptr, 8); | |||
| 1801 | hdrptr += 8; | |||
| 1802 | offset_size = 8; | |||
| 1803 | initial_length_size = 12; | |||
| 1804 | } | |||
| 1805 | else | |||
| 1806 | { | |||
| 1807 | offset_size = 4; | |||
| 1808 | initial_length_size = 4; | |||
| 1809 | } | |||
| 1810 | ||||
| 1811 | if (info.li_length + initial_length_size > section->size) | |||
| 1812 | { | |||
| 1813 | warn | |||
| 1814 | (_("The line info appears to be corrupt - the section is too small\n")("The line info appears to be corrupt - the section is too small\n" )); | |||
| 1815 | return 0; | |||
| 1816 | } | |||
| 1817 | ||||
| 1818 | /* Check its version number. */ | |||
| 1819 | info.li_version = byte_get (hdrptr, 2); | |||
| 1820 | hdrptr += 2; | |||
| 1821 | if (info.li_version != 2 && info.li_version != 3) | |||
| 1822 | { | |||
| 1823 | warn (_("Only DWARF version 2 and 3 line info is currently supported.\n")("Only DWARF version 2 and 3 line info is currently supported.\n" )); | |||
| 1824 | return 0; | |||
| 1825 | } | |||
| 1826 | ||||
| 1827 | info.li_prologue_length = byte_get (hdrptr, offset_size); | |||
| 1828 | hdrptr += offset_size; | |||
| 1829 | info.li_min_insn_length = byte_get (hdrptr, 1); | |||
| 1830 | hdrptr++; | |||
| 1831 | info.li_default_is_stmt = byte_get (hdrptr, 1); | |||
| 1832 | hdrptr++; | |||
| 1833 | info.li_line_base = byte_get (hdrptr, 1); | |||
| 1834 | hdrptr++; | |||
| 1835 | info.li_line_range = byte_get (hdrptr, 1); | |||
| 1836 | hdrptr++; | |||
| 1837 | info.li_opcode_base = byte_get (hdrptr, 1); | |||
| 1838 | hdrptr++; | |||
| 1839 | ||||
| 1840 | /* Sign extend the line base field. */ | |||
| 1841 | info.li_line_base <<= 24; | |||
| 1842 | info.li_line_base >>= 24; | |||
| 1843 | ||||
| 1844 | printf (_(" Length: %ld\n")(" Length: %ld\n"), info.li_length); | |||
| 1845 | printf (_(" DWARF Version: %d\n")(" DWARF Version: %d\n"), info.li_version); | |||
| 1846 | printf (_(" Prologue Length: %d\n")(" Prologue Length: %d\n"), info.li_prologue_length); | |||
| 1847 | printf (_(" Minimum Instruction Length: %d\n")(" Minimum Instruction Length: %d\n"), info.li_min_insn_length); | |||
| 1848 | printf (_(" Initial value of 'is_stmt': %d\n")(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt); | |||
| 1849 | printf (_(" Line Base: %d\n")(" Line Base: %d\n"), info.li_line_base); | |||
| 1850 | printf (_(" Line Range: %d\n")(" Line Range: %d\n"), info.li_line_range); | |||
| 1851 | printf (_(" Opcode Base: %d\n")(" Opcode Base: %d\n"), info.li_opcode_base); | |||
| 1852 | ||||
| 1853 | end_of_sequence = data + info.li_length + initial_length_size; | |||
| 1854 | ||||
| 1855 | reset_state_machine (info.li_default_is_stmt); | |||
| 1856 | ||||
| 1857 | /* Display the contents of the Opcodes table. */ | |||
| 1858 | standard_opcodes = hdrptr; | |||
| 1859 | ||||
| 1860 | printf (_("\n Opcodes:\n")("\n Opcodes:\n")); | |||
| 1861 | ||||
| 1862 | for (i = 1; i < info.li_opcode_base; i++) | |||
| 1863 | printf (_(" Opcode %d has %d args\n")(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |||
| 1864 | ||||
| 1865 | /* Display the contents of the Directory table. */ | |||
| 1866 | data = standard_opcodes + info.li_opcode_base - 1; | |||
| 1867 | ||||
| 1868 | if (*data == 0) | |||
| 1869 | printf (_("\n The Directory Table is empty.\n")("\n The Directory Table is empty.\n")); | |||
| 1870 | else | |||
| 1871 | { | |||
| 1872 | printf (_("\n The Directory Table:\n")("\n The Directory Table:\n")); | |||
| 1873 | ||||
| 1874 | while (*data != 0) | |||
| 1875 | { | |||
| 1876 | printf (_(" %s\n")(" %s\n"), data); | |||
| 1877 | ||||
| 1878 | data += strlen ((char *) data) + 1; | |||
| 1879 | } | |||
| 1880 | } | |||
| 1881 | ||||
| 1882 | /* Skip the NUL at the end of the table. */ | |||
| 1883 | data++; | |||
| 1884 | ||||
| 1885 | /* Display the contents of the File Name table. */ | |||
| 1886 | if (*data == 0) | |||
| 1887 | printf (_("\n The File Name Table is empty.\n")("\n The File Name Table is empty.\n")); | |||
| 1888 | else | |||
| 1889 | { | |||
| 1890 | printf (_("\n The File Name Table:\n")("\n The File Name Table:\n")); | |||
| 1891 | printf (_(" Entry\tDir\tTime\tSize\tName\n")(" Entry\tDir\tTime\tSize\tName\n")); | |||
| 1892 | ||||
| 1893 | while (*data != 0) | |||
| 1894 | { | |||
| 1895 | unsigned char *name; | |||
| 1896 | unsigned int bytes_read; | |||
| 1897 | ||||
| 1898 | printf (_(" %d\t")(" %d\t"), ++state_machine_regs.last_file_entry); | |||
| 1899 | name = data; | |||
| 1900 | ||||
| 1901 | data += strlen ((char *) data) + 1; | |||
| 1902 | ||||
| 1903 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 1904 | data += bytes_read; | |||
| 1905 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 1906 | data += bytes_read; | |||
| 1907 | printf (_("%lu\t")("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |||
| 1908 | data += bytes_read; | |||
| 1909 | printf (_("%s\n")("%s\n"), name); | |||
| 1910 | } | |||
| 1911 | } | |||
| 1912 | ||||
| 1913 | /* Skip the NUL at the end of the table. */ | |||
| 1914 | data++; | |||
| 1915 | ||||
| 1916 | /* Now display the statements. */ | |||
| 1917 | printf (_("\n Line Number Statements:\n")("\n Line Number Statements:\n")); | |||
| 1918 | ||||
| 1919 | while (data < end_of_sequence) | |||
| 1920 | { | |||
| 1921 | unsigned char op_code; | |||
| 1922 | int adv; | |||
| 1923 | unsigned long int uladv; | |||
| 1924 | unsigned int bytes_read; | |||
| 1925 | ||||
| 1926 | op_code = *data++; | |||
| 1927 | ||||
| 1928 | if (op_code >= info.li_opcode_base) | |||
| 1929 | { | |||
| 1930 | op_code -= info.li_opcode_base; | |||
| 1931 | uladv = (op_code / info.li_line_range) * info.li_min_insn_length; | |||
| 1932 | state_machine_regs.address += uladv; | |||
| 1933 | printf (_(" Special opcode %d: advance Address by %lu to 0x%lx")(" Special opcode %d: advance Address by %lu to 0x%lx"), | |||
| 1934 | op_code, uladv, state_machine_regs.address); | |||
| 1935 | adv = (op_code % info.li_line_range) + info.li_line_base; | |||
| 1936 | state_machine_regs.line += adv; | |||
| 1937 | printf (_(" and Line by %d to %d\n")(" and Line by %d to %d\n"), | |||
| 1938 | adv, state_machine_regs.line); | |||
| 1939 | } | |||
| 1940 | else switch (op_code) | |||
| 1941 | { | |||
| 1942 | case DW_LNS_extended_op: | |||
| 1943 | data += process_extended_line_op (data, info.li_default_is_stmt); | |||
| 1944 | break; | |||
| 1945 | ||||
| 1946 | case DW_LNS_copy: | |||
| 1947 | printf (_(" Copy\n")(" Copy\n")); | |||
| 1948 | break; | |||
| 1949 | ||||
| 1950 | case DW_LNS_advance_pc: | |||
| 1951 | uladv = read_leb128 (data, & bytes_read, 0); | |||
| 1952 | uladv *= info.li_min_insn_length; | |||
| 1953 | data += bytes_read; | |||
| 1954 | state_machine_regs.address += uladv; | |||
| 1955 | printf (_(" Advance PC by %lu to 0x%lx\n")(" Advance PC by %lu to 0x%lx\n"), uladv, | |||
| 1956 | state_machine_regs.address); | |||
| 1957 | break; | |||
| 1958 | ||||
| 1959 | case DW_LNS_advance_line: | |||
| 1960 | adv = read_leb128 (data, & bytes_read, 1); | |||
| 1961 | data += bytes_read; | |||
| 1962 | state_machine_regs.line += adv; | |||
| 1963 | printf (_(" Advance Line by %d to %d\n")(" Advance Line by %d to %d\n"), adv, | |||
| 1964 | state_machine_regs.line); | |||
| 1965 | break; | |||
| 1966 | ||||
| 1967 | case DW_LNS_set_file: | |||
| 1968 | adv = read_leb128 (data, & bytes_read, 0); | |||
| 1969 | data += bytes_read; | |||
| 1970 | printf (_(" Set File Name to entry %d in the File Name Table\n")(" Set File Name to entry %d in the File Name Table\n"), | |||
| 1971 | adv); | |||
| 1972 | state_machine_regs.file = adv; | |||
| 1973 | break; | |||
| 1974 | ||||
| 1975 | case DW_LNS_set_column: | |||
| 1976 | uladv = read_leb128 (data, & bytes_read, 0); | |||
| 1977 | data += bytes_read; | |||
| 1978 | printf (_(" Set column to %lu\n")(" Set column to %lu\n"), uladv); | |||
| 1979 | state_machine_regs.column = uladv; | |||
| 1980 | break; | |||
| 1981 | ||||
| 1982 | case DW_LNS_negate_stmt: | |||
| 1983 | adv = state_machine_regs.is_stmt; | |||
| 1984 | adv = ! adv; | |||
| 1985 | printf (_(" Set is_stmt to %d\n")(" Set is_stmt to %d\n"), adv); | |||
| 1986 | state_machine_regs.is_stmt = adv; | |||
| 1987 | break; | |||
| 1988 | ||||
| 1989 | case DW_LNS_set_basic_block: | |||
| 1990 | printf (_(" Set basic block\n")(" Set basic block\n")); | |||
| 1991 | state_machine_regs.basic_block = 1; | |||
| 1992 | break; | |||
| 1993 | ||||
| 1994 | case DW_LNS_const_add_pc: | |||
| 1995 | uladv = (((255 - info.li_opcode_base) / info.li_line_range) | |||
| 1996 | * info.li_min_insn_length); | |||
| 1997 | state_machine_regs.address += uladv; | |||
| 1998 | printf (_(" Advance PC by constant %lu to 0x%lx\n")(" Advance PC by constant %lu to 0x%lx\n"), uladv, | |||
| 1999 | state_machine_regs.address); | |||
| 2000 | break; | |||
| 2001 | ||||
| 2002 | case DW_LNS_fixed_advance_pc: | |||
| 2003 | uladv = byte_get (data, 2); | |||
| 2004 | data += 2; | |||
| 2005 | state_machine_regs.address += uladv; | |||
| 2006 | printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n")(" Advance PC by fixed size amount %lu to 0x%lx\n"), | |||
| 2007 | uladv, state_machine_regs.address); | |||
| 2008 | break; | |||
| 2009 | ||||
| 2010 | case DW_LNS_set_prologue_end: | |||
| 2011 | printf (_(" Set prologue_end to true\n")(" Set prologue_end to true\n")); | |||
| 2012 | break; | |||
| 2013 | ||||
| 2014 | case DW_LNS_set_epilogue_begin: | |||
| 2015 | printf (_(" Set epilogue_begin to true\n")(" Set epilogue_begin to true\n")); | |||
| 2016 | break; | |||
| 2017 | ||||
| 2018 | case DW_LNS_set_isa: | |||
| 2019 | uladv = read_leb128 (data, & bytes_read, 0); | |||
| 2020 | data += bytes_read; | |||
| 2021 | printf (_(" Set ISA to %lu\n")(" Set ISA to %lu\n"), uladv); | |||
| 2022 | break; | |||
| 2023 | ||||
| 2024 | default: | |||
| 2025 | printf (_(" Unknown opcode %d with operands: ")(" Unknown opcode %d with operands: "), op_code); | |||
| 2026 | ||||
| 2027 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |||
| 2028 | { | |||
| 2029 | printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0), | |||
| 2030 | i == 1 ? "" : ", "); | |||
| 2031 | data += bytes_read; | |||
| 2032 | } | |||
| 2033 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2034 | break; | |||
| 2035 | } | |||
| 2036 | } | |||
| 2037 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2038 | } | |||
| 2039 | ||||
| 2040 | return 1; | |||
| 2041 | } | |||
| 2042 | ||||
| 2043 | static int | |||
| 2044 | display_debug_pubnames (struct dwarf_section *section, | |||
| 2045 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2046 | { | |||
| 2047 | DWARF2_Internal_PubNames pubnames; | |||
| 2048 | unsigned char *start = section->start; | |||
| 2049 | unsigned char *end = start + section->size; | |||
| 2050 | ||||
| 2051 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2052 | ||||
| 2053 | while (start < end) | |||
| 2054 | { | |||
| 2055 | unsigned char *data; | |||
| 2056 | unsigned long offset; | |||
| 2057 | int offset_size, initial_length_size; | |||
| 2058 | ||||
| 2059 | data = start; | |||
| 2060 | ||||
| 2061 | pubnames.pn_length = byte_get (data, 4); | |||
| 2062 | data += 4; | |||
| 2063 | if (pubnames.pn_length == 0xffffffff) | |||
| 2064 | { | |||
| 2065 | pubnames.pn_length = byte_get (data, 8); | |||
| 2066 | data += 8; | |||
| 2067 | offset_size = 8; | |||
| 2068 | initial_length_size = 12; | |||
| 2069 | } | |||
| 2070 | else | |||
| 2071 | { | |||
| 2072 | offset_size = 4; | |||
| 2073 | initial_length_size = 4; | |||
| 2074 | } | |||
| 2075 | ||||
| 2076 | pubnames.pn_version = byte_get (data, 2); | |||
| 2077 | data += 2; | |||
| 2078 | pubnames.pn_offset = byte_get (data, offset_size); | |||
| 2079 | data += offset_size; | |||
| 2080 | pubnames.pn_size = byte_get (data, offset_size); | |||
| 2081 | data += offset_size; | |||
| 2082 | ||||
| 2083 | start += pubnames.pn_length + initial_length_size; | |||
| 2084 | ||||
| 2085 | if (pubnames.pn_version != 2 && pubnames.pn_version != 3) | |||
| 2086 | { | |||
| 2087 | static int warned = 0; | |||
| 2088 | ||||
| 2089 | if (! warned) | |||
| 2090 | { | |||
| 2091 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")("Only DWARF 2 and 3 pubnames are currently supported\n")); | |||
| 2092 | warned = 1; | |||
| 2093 | } | |||
| 2094 | ||||
| 2095 | continue; | |||
| 2096 | } | |||
| 2097 | ||||
| 2098 | printf (_(" Length: %ld\n")(" Length: %ld\n"), | |||
| 2099 | pubnames.pn_length); | |||
| 2100 | printf (_(" Version: %d\n")(" Version: %d\n"), | |||
| 2101 | pubnames.pn_version); | |||
| 2102 | printf (_(" Offset into .debug_info section: %ld\n")(" Offset into .debug_info section: %ld\n"), | |||
| 2103 | pubnames.pn_offset); | |||
| 2104 | printf (_(" Size of area in .debug_info section: %ld\n")(" Size of area in .debug_info section: %ld\n"), | |||
| 2105 | pubnames.pn_size); | |||
| 2106 | ||||
| 2107 | printf (_("\n Offset\tName\n")("\n Offset\tName\n")); | |||
| 2108 | ||||
| 2109 | do | |||
| 2110 | { | |||
| 2111 | offset = byte_get (data, offset_size); | |||
| 2112 | ||||
| 2113 | if (offset != 0) | |||
| 2114 | { | |||
| 2115 | data += offset_size; | |||
| 2116 | printf (" %-6ld\t\t%s\n", offset, data); | |||
| 2117 | data += strlen ((char *) data) + 1; | |||
| 2118 | } | |||
| 2119 | } | |||
| 2120 | while (offset != 0); | |||
| 2121 | } | |||
| 2122 | ||||
| 2123 | printf ("\n"); | |||
| 2124 | return 1; | |||
| 2125 | } | |||
| 2126 | ||||
| 2127 | static int | |||
| 2128 | display_debug_macinfo (struct dwarf_section *section, | |||
| 2129 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2130 | { | |||
| 2131 | unsigned char *start = section->start; | |||
| 2132 | unsigned char *end = start + section->size; | |||
| 2133 | unsigned char *curr = start; | |||
| 2134 | unsigned int bytes_read; | |||
| 2135 | enum dwarf_macinfo_record_type op; | |||
| 2136 | ||||
| 2137 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2138 | ||||
| 2139 | while (curr < end) | |||
| 2140 | { | |||
| 2141 | unsigned int lineno; | |||
| 2142 | const char *string; | |||
| 2143 | ||||
| 2144 | op = *curr; | |||
| 2145 | curr++; | |||
| 2146 | ||||
| 2147 | switch (op) | |||
| 2148 | { | |||
| 2149 | case DW_MACINFO_start_file: | |||
| 2150 | { | |||
| 2151 | unsigned int filenum; | |||
| 2152 | ||||
| 2153 | lineno = read_leb128 (curr, & bytes_read, 0); | |||
| 2154 | curr += bytes_read; | |||
| 2155 | filenum = read_leb128 (curr, & bytes_read, 0); | |||
| 2156 | curr += bytes_read; | |||
| 2157 | ||||
| 2158 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n")(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |||
| 2159 | lineno, filenum); | |||
| 2160 | } | |||
| 2161 | break; | |||
| 2162 | ||||
| 2163 | case DW_MACINFO_end_file: | |||
| 2164 | printf (_(" DW_MACINFO_end_file\n")(" DW_MACINFO_end_file\n")); | |||
| 2165 | break; | |||
| 2166 | ||||
| 2167 | case DW_MACINFO_define: | |||
| 2168 | lineno = read_leb128 (curr, & bytes_read, 0); | |||
| 2169 | curr += bytes_read; | |||
| 2170 | string = (char *) curr; | |||
| 2171 | curr += strlen (string) + 1; | |||
| 2172 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n")(" DW_MACINFO_define - lineno : %d macro : %s\n"), | |||
| 2173 | lineno, string); | |||
| 2174 | break; | |||
| 2175 | ||||
| 2176 | case DW_MACINFO_undef: | |||
| 2177 | lineno = read_leb128 (curr, & bytes_read, 0); | |||
| 2178 | curr += bytes_read; | |||
| 2179 | string = (char *) curr; | |||
| 2180 | curr += strlen (string) + 1; | |||
| 2181 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n")(" DW_MACINFO_undef - lineno : %d macro : %s\n"), | |||
| 2182 | lineno, string); | |||
| 2183 | break; | |||
| 2184 | ||||
| 2185 | case DW_MACINFO_vendor_ext: | |||
| 2186 | { | |||
| 2187 | unsigned int constant; | |||
| 2188 | ||||
| 2189 | constant = read_leb128 (curr, & bytes_read, 0); | |||
| 2190 | curr += bytes_read; | |||
| 2191 | string = (char *) curr; | |||
| 2192 | curr += strlen (string) + 1; | |||
| 2193 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n")(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), | |||
| 2194 | constant, string); | |||
| 2195 | } | |||
| 2196 | break; | |||
| 2197 | } | |||
| 2198 | } | |||
| 2199 | ||||
| 2200 | return 1; | |||
| 2201 | } | |||
| 2202 | ||||
| 2203 | static int | |||
| 2204 | display_debug_abbrev (struct dwarf_section *section, | |||
| 2205 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2206 | { | |||
| 2207 | abbrev_entry *entry; | |||
| 2208 | unsigned char *start = section->start; | |||
| 2209 | unsigned char *end = start + section->size; | |||
| 2210 | ||||
| 2211 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2212 | ||||
| 2213 | do | |||
| 2214 | { | |||
| 2215 | free_abbrevs (); | |||
| 2216 | ||||
| 2217 | start = process_abbrev_section (start, end); | |||
| 2218 | ||||
| 2219 | if (first_abbrev == NULL((void*)0)) | |||
| 2220 | continue; | |||
| 2221 | ||||
| 2222 | printf (_(" Number TAG\n")(" Number TAG\n")); | |||
| 2223 | ||||
| 2224 | for (entry = first_abbrev; entry; entry = entry->next) | |||
| 2225 | { | |||
| 2226 | abbrev_attr *attr; | |||
| 2227 | ||||
| 2228 | printf (_(" %ld %s [%s]\n")(" %ld %s [%s]\n"), | |||
| 2229 | entry->entry, | |||
| 2230 | get_TAG_name (entry->tag), | |||
| 2231 | entry->children ? _("has children")("has children") : _("no children")("no children")); | |||
| 2232 | ||||
| 2233 | for (attr = entry->first_attr; attr; attr = attr->next) | |||
| 2234 | printf (_(" %-18s %s\n")(" %-18s %s\n"), | |||
| 2235 | get_AT_name (attr->attribute), | |||
| 2236 | get_FORM_name (attr->form)); | |||
| 2237 | } | |||
| 2238 | } | |||
| 2239 | while (start); | |||
| 2240 | ||||
| 2241 | printf ("\n"); | |||
| 2242 | ||||
| 2243 | return 1; | |||
| 2244 | } | |||
| 2245 | ||||
| 2246 | static int | |||
| 2247 | display_debug_loc (struct dwarf_section *section, void *file) | |||
| 2248 | { | |||
| 2249 | unsigned char *start = section->start; | |||
| 2250 | unsigned char *section_end; | |||
| 2251 | unsigned long bytes; | |||
| 2252 | unsigned char *section_begin = start; | |||
| 2253 | unsigned int num_loc_list = 0; | |||
| 2254 | unsigned long last_offset = 0; | |||
| 2255 | unsigned int first = 0; | |||
| 2256 | unsigned int i; | |||
| 2257 | unsigned int j; | |||
| 2258 | int seen_first_offset = 0; | |||
| 2259 | int use_debug_info = 1; | |||
| 2260 | unsigned char *next; | |||
| 2261 | ||||
| 2262 | bytes = section->size; | |||
| 2263 | section_end = start + bytes; | |||
| 2264 | ||||
| 2265 | if (bytes == 0) | |||
| 2266 | { | |||
| 2267 | printf (_("\nThe %s section is empty.\n")("\nThe %s section is empty.\n"), section->name); | |||
| 2268 | return 0; | |||
| 2269 | } | |||
| 2270 | ||||
| 2271 | load_debug_info (file); | |||
| 2272 | ||||
| 2273 | /* Check the order of location list in .debug_info section. If | |||
| 2274 | offsets of location lists are in the ascending order, we can | |||
| 2275 | use `debug_information' directly. */ | |||
| 2276 | for (i = 0; i < num_debug_info_entries; i++) | |||
| 2277 | { | |||
| 2278 | unsigned int num; | |||
| 2279 | ||||
| 2280 | num = debug_information [i].num_loc_offsets; | |||
| 2281 | num_loc_list += num; | |||
| 2282 | ||||
| 2283 | /* Check if we can use `debug_information' directly. */ | |||
| 2284 | if (use_debug_info && num != 0) | |||
| 2285 | { | |||
| 2286 | if (!seen_first_offset) | |||
| 2287 | { | |||
| 2288 | /* This is the first location list. */ | |||
| 2289 | last_offset = debug_information [i].loc_offsets [0]; | |||
| 2290 | first = i; | |||
| 2291 | seen_first_offset = 1; | |||
| 2292 | j = 1; | |||
| 2293 | } | |||
| 2294 | else | |||
| 2295 | j = 0; | |||
| 2296 | ||||
| 2297 | for (; j < num; j++) | |||
| 2298 | { | |||
| 2299 | if (last_offset > | |||
| 2300 | debug_information [i].loc_offsets [j]) | |||
| 2301 | { | |||
| 2302 | use_debug_info = 0; | |||
| 2303 | break; | |||
| 2304 | } | |||
| 2305 | last_offset = debug_information [i].loc_offsets [j]; | |||
| 2306 | } | |||
| 2307 | } | |||
| 2308 | } | |||
| 2309 | ||||
| 2310 | if (!use_debug_info) | |||
| 2311 | /* FIXME: Should we handle this case? */ | |||
| 2312 | error (_("Location lists in .debug_info section aren't in ascending order!\n")("Location lists in .debug_info section aren't in ascending order!\n" )); | |||
| 2313 | ||||
| 2314 | if (!seen_first_offset) | |||
| 2315 | error (_("No location lists in .debug_info section!\n")("No location lists in .debug_info section!\n")); | |||
| 2316 | ||||
| 2317 | /* DWARF sections under Mach-O have non-zero addresses. */ | |||
| 2318 | if (debug_information [first].loc_offsets [0] != section->address) | |||
| 2319 | warn (_("Location lists in %s section start at 0x%lx\n")("Location lists in %s section start at 0x%lx\n"), | |||
| 2320 | section->name, debug_information [first].loc_offsets [0]); | |||
| 2321 | ||||
| 2322 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2323 | printf (_(" Offset Begin End Expression\n")(" Offset Begin End Expression\n")); | |||
| 2324 | ||||
| 2325 | seen_first_offset = 0; | |||
| 2326 | for (i = first; i < num_debug_info_entries; i++) | |||
| 2327 | { | |||
| 2328 | unsigned long begin; | |||
| 2329 | unsigned long end; | |||
| 2330 | unsigned short length; | |||
| 2331 | unsigned long offset; | |||
| 2332 | unsigned int pointer_size; | |||
| 2333 | unsigned long cu_offset; | |||
| 2334 | unsigned long base_address; | |||
| 2335 | int need_frame_base; | |||
| 2336 | int has_frame_base; | |||
| 2337 | ||||
| 2338 | pointer_size = debug_information [i].pointer_size; | |||
| 2339 | cu_offset = debug_information [i].cu_offset; | |||
| 2340 | ||||
| 2341 | for (j = 0; j < debug_information [i].num_loc_offsets; j++) | |||
| 2342 | { | |||
| 2343 | has_frame_base = debug_information [i].have_frame_base [j]; | |||
| 2344 | /* DWARF sections under Mach-O have non-zero addresses. */ | |||
| 2345 | offset = debug_information [i].loc_offsets [j] - section->address; | |||
| 2346 | next = section_begin + offset; | |||
| 2347 | base_address = debug_information [i].base_address; | |||
| 2348 | ||||
| 2349 | if (!seen_first_offset) | |||
| 2350 | seen_first_offset = 1; | |||
| 2351 | else | |||
| 2352 | { | |||
| 2353 | if (start < next) | |||
| 2354 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n")("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |||
| 2355 | (long)(start - section_begin), (long)(next - section_begin)); | |||
| 2356 | else if (start > next) | |||
| 2357 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n")("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n" ), | |||
| 2358 | (long)(start - section_begin), (long)(next - section_begin)); | |||
| 2359 | } | |||
| 2360 | start = next; | |||
| 2361 | ||||
| 2362 | if (offset >= bytes) | |||
| 2363 | { | |||
| 2364 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n")("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |||
| 2365 | offset); | |||
| 2366 | continue; | |||
| 2367 | } | |||
| 2368 | ||||
| 2369 | while (1) | |||
| 2370 | { | |||
| 2371 | if (start + 2 * pointer_size > section_end) | |||
| 2372 | { | |||
| 2373 | warn (_("Location list starting at offset 0x%lx is not terminated.\n")("Location list starting at offset 0x%lx is not terminated.\n" ), | |||
| 2374 | offset); | |||
| 2375 | break; | |||
| 2376 | } | |||
| 2377 | ||||
| 2378 | begin = byte_get (start, pointer_size); | |||
| 2379 | start += pointer_size; | |||
| 2380 | end = byte_get (start, pointer_size); | |||
| 2381 | start += pointer_size; | |||
| 2382 | ||||
| 2383 | if (begin == 0 && end == 0) | |||
| 2384 | { | |||
| 2385 | printf (_(" %8.8lx <End of list>\n")(" %8.8lx <End of list>\n"), offset); | |||
| 2386 | break; | |||
| 2387 | } | |||
| 2388 | ||||
| 2389 | /* Check base address specifiers. */ | |||
| 2390 | if (begin == -1UL && end != -1UL) | |||
| 2391 | { | |||
| 2392 | base_address = end; | |||
| 2393 | printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n")(" %8.8lx %8.8lx %8.8lx (base address)\n"), | |||
| 2394 | offset, begin, end); | |||
| 2395 | continue; | |||
| 2396 | } | |||
| 2397 | ||||
| 2398 | if (start + 2 > section_end) | |||
| 2399 | { | |||
| 2400 | warn (_("Location list starting at offset 0x%lx is not terminated.\n")("Location list starting at offset 0x%lx is not terminated.\n" ), | |||
| 2401 | offset); | |||
| 2402 | break; | |||
| 2403 | } | |||
| 2404 | ||||
| 2405 | length = byte_get (start, 2); | |||
| 2406 | start += 2; | |||
| 2407 | ||||
| 2408 | if (start + length > section_end) | |||
| 2409 | { | |||
| 2410 | warn (_("Location list starting at offset 0x%lx is not terminated.\n")("Location list starting at offset 0x%lx is not terminated.\n" ), | |||
| 2411 | offset); | |||
| 2412 | break; | |||
| 2413 | } | |||
| 2414 | ||||
| 2415 | printf (" %8.8lx %8.8lx %8.8lx (", | |||
| 2416 | offset, begin + base_address, end + base_address); | |||
| 2417 | need_frame_base = decode_location_expression (start, | |||
| 2418 | pointer_size, | |||
| 2419 | length, | |||
| 2420 | cu_offset); | |||
| 2421 | putchar (')')(!__isthreaded ? __sputc(')', (&__sF[1])) : (putc)(')', ( &__sF[1]))); | |||
| 2422 | ||||
| 2423 | if (need_frame_base && !has_frame_base) | |||
| 2424 | printf (_(" [without DW_AT_frame_base]")(" [without DW_AT_frame_base]")); | |||
| 2425 | ||||
| 2426 | if (begin == end) | |||
| 2427 | fputs (_(" (start == end)")(" (start == end)"), stdout(&__sF[1])); | |||
| 2428 | else if (begin > end) | |||
| 2429 | fputs (_(" (start > end)")(" (start > end)"), stdout(&__sF[1])); | |||
| 2430 | ||||
| 2431 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2432 | ||||
| 2433 | start += length; | |||
| 2434 | } | |||
| 2435 | } | |||
| 2436 | } | |||
| 2437 | return 1; | |||
| 2438 | } | |||
| 2439 | ||||
| 2440 | static int | |||
| 2441 | display_debug_str (struct dwarf_section *section, | |||
| 2442 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2443 | { | |||
| 2444 | unsigned char *start = section->start; | |||
| 2445 | unsigned long bytes = section->size; | |||
| 2446 | dwarf_vma addr = section->address; | |||
| 2447 | ||||
| 2448 | if (bytes == 0) | |||
| 2449 | { | |||
| 2450 | printf (_("\nThe %s section is empty.\n")("\nThe %s section is empty.\n"), section->name); | |||
| 2451 | return 0; | |||
| 2452 | } | |||
| 2453 | ||||
| 2454 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2455 | ||||
| 2456 | while (bytes) | |||
| 2457 | { | |||
| 2458 | int j; | |||
| 2459 | int k; | |||
| 2460 | int lbytes; | |||
| 2461 | ||||
| 2462 | lbytes = (bytes > 16 ? 16 : bytes); | |||
| 2463 | ||||
| 2464 | printf (" 0x%8.8lx ", (unsigned long) addr); | |||
| 2465 | ||||
| 2466 | for (j = 0; j < 16; j++) | |||
| 2467 | { | |||
| 2468 | if (j < lbytes) | |||
| 2469 | printf ("%2.2x", start[j]); | |||
| 2470 | else | |||
| 2471 | printf (" "); | |||
| 2472 | ||||
| 2473 | if ((j & 3) == 3) | |||
| 2474 | printf (" "); | |||
| 2475 | } | |||
| 2476 | ||||
| 2477 | for (j = 0; j < lbytes; j++) | |||
| 2478 | { | |||
| 2479 | k = start[j]; | |||
| 2480 | if (k >= ' ' && k < 0x80) | |||
| 2481 | printf ("%c", k); | |||
| 2482 | else | |||
| 2483 | printf ("."); | |||
| 2484 | } | |||
| 2485 | ||||
| 2486 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2487 | ||||
| 2488 | start += lbytes; | |||
| 2489 | addr += lbytes; | |||
| 2490 | bytes -= lbytes; | |||
| 2491 | } | |||
| 2492 | ||||
| 2493 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2494 | ||||
| 2495 | return 1; | |||
| 2496 | } | |||
| 2497 | ||||
| 2498 | ||||
| 2499 | static int | |||
| 2500 | display_debug_info (struct dwarf_section *section, void *file) | |||
| 2501 | { | |||
| 2502 | return process_debug_info (section, file, 0); | |||
| 2503 | } | |||
| 2504 | ||||
| 2505 | ||||
| 2506 | static int | |||
| 2507 | display_debug_aranges (struct dwarf_section *section, | |||
| 2508 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2509 | { | |||
| 2510 | unsigned char *start = section->start; | |||
| 2511 | unsigned char *end = start + section->size; | |||
| 2512 | ||||
| 2513 | printf (_("The section %s contains:\n\n")("The section %s contains:\n\n"), section->name); | |||
| 2514 | ||||
| 2515 | while (start < end) | |||
| 2516 | { | |||
| 2517 | unsigned char *hdrptr; | |||
| 2518 | DWARF2_Internal_ARange arange; | |||
| 2519 | unsigned char *ranges; | |||
| 2520 | unsigned long length; | |||
| 2521 | unsigned long address; | |||
| 2522 | int excess; | |||
| 2523 | int offset_size; | |||
| 2524 | int initial_length_size; | |||
| 2525 | ||||
| 2526 | hdrptr = start; | |||
| 2527 | ||||
| 2528 | arange.ar_length = byte_get (hdrptr, 4); | |||
| 2529 | hdrptr += 4; | |||
| 2530 | ||||
| 2531 | if (arange.ar_length == 0xffffffff) | |||
| 2532 | { | |||
| 2533 | arange.ar_length = byte_get (hdrptr, 8); | |||
| 2534 | hdrptr += 8; | |||
| 2535 | offset_size = 8; | |||
| 2536 | initial_length_size = 12; | |||
| 2537 | } | |||
| 2538 | else | |||
| 2539 | { | |||
| 2540 | offset_size = 4; | |||
| 2541 | initial_length_size = 4; | |||
| 2542 | } | |||
| 2543 | ||||
| 2544 | arange.ar_version = byte_get (hdrptr, 2); | |||
| 2545 | hdrptr += 2; | |||
| 2546 | ||||
| 2547 | arange.ar_info_offset = byte_get (hdrptr, offset_size); | |||
| 2548 | hdrptr += offset_size; | |||
| 2549 | ||||
| 2550 | arange.ar_pointer_size = byte_get (hdrptr, 1); | |||
| 2551 | hdrptr += 1; | |||
| 2552 | ||||
| 2553 | arange.ar_segment_size = byte_get (hdrptr, 1); | |||
| 2554 | hdrptr += 1; | |||
| 2555 | ||||
| 2556 | if (arange.ar_version != 2 && arange.ar_version != 3) | |||
| 2557 | { | |||
| 2558 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")("Only DWARF 2 and 3 aranges are currently supported.\n")); | |||
| 2559 | break; | |||
| 2560 | } | |||
| 2561 | ||||
| 2562 | printf (_(" Length: %ld\n")(" Length: %ld\n"), arange.ar_length); | |||
| 2563 | printf (_(" Version: %d\n")(" Version: %d\n"), arange.ar_version); | |||
| 2564 | printf (_(" Offset into .debug_info: %lx\n")(" Offset into .debug_info: %lx\n"), arange.ar_info_offset); | |||
| 2565 | printf (_(" Pointer Size: %d\n")(" Pointer Size: %d\n"), arange.ar_pointer_size); | |||
| 2566 | printf (_(" Segment Size: %d\n")(" Segment Size: %d\n"), arange.ar_segment_size); | |||
| 2567 | ||||
| 2568 | printf (_("\n Address Length\n")("\n Address Length\n")); | |||
| 2569 | ||||
| 2570 | ranges = hdrptr; | |||
| 2571 | ||||
| 2572 | /* Must pad to an alignment boundary that is twice the pointer size. */ | |||
| 2573 | excess = (hdrptr - start) % (2 * arange.ar_pointer_size); | |||
| 2574 | if (excess) | |||
| 2575 | ranges += (2 * arange.ar_pointer_size) - excess; | |||
| 2576 | ||||
| 2577 | start += arange.ar_length + initial_length_size; | |||
| 2578 | ||||
| 2579 | while (ranges + 2 * arange.ar_pointer_size <= start) | |||
| 2580 | { | |||
| 2581 | address = byte_get (ranges, arange.ar_pointer_size); | |||
| 2582 | ||||
| 2583 | ranges += arange.ar_pointer_size; | |||
| 2584 | ||||
| 2585 | length = byte_get (ranges, arange.ar_pointer_size); | |||
| 2586 | ||||
| 2587 | ranges += arange.ar_pointer_size; | |||
| 2588 | ||||
| 2589 | printf (" %8.8lx %lu\n", address, length); | |||
| 2590 | } | |||
| 2591 | } | |||
| 2592 | ||||
| 2593 | printf ("\n"); | |||
| 2594 | ||||
| 2595 | return 1; | |||
| 2596 | } | |||
| 2597 | ||||
| 2598 | static int | |||
| 2599 | display_debug_ranges (struct dwarf_section *section, | |||
| 2600 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2601 | { | |||
| 2602 | unsigned char *start = section->start; | |||
| 2603 | unsigned char *section_end; | |||
| 2604 | unsigned long bytes; | |||
| 2605 | unsigned char *section_begin = start; | |||
| 2606 | unsigned int num_range_list = 0; | |||
| 2607 | unsigned long last_offset = 0; | |||
| 2608 | unsigned int first = 0; | |||
| 2609 | unsigned int i; | |||
| 2610 | unsigned int j; | |||
| 2611 | int seen_first_offset = 0; | |||
| 2612 | int use_debug_info = 1; | |||
| 2613 | unsigned char *next; | |||
| 2614 | ||||
| 2615 | bytes = section->size; | |||
| 2616 | section_end = start + bytes; | |||
| 2617 | ||||
| 2618 | if (bytes == 0) | |||
| 2619 | { | |||
| 2620 | printf (_("\nThe %s section is empty.\n")("\nThe %s section is empty.\n"), section->name); | |||
| 2621 | return 0; | |||
| 2622 | } | |||
| 2623 | ||||
| 2624 | load_debug_info (file); | |||
| 2625 | ||||
| 2626 | /* Check the order of range list in .debug_info section. If | |||
| 2627 | offsets of range lists are in the ascending order, we can | |||
| 2628 | use `debug_information' directly. */ | |||
| 2629 | for (i = 0; i < num_debug_info_entries; i++) | |||
| 2630 | { | |||
| 2631 | unsigned int num; | |||
| 2632 | ||||
| 2633 | num = debug_information [i].num_range_lists; | |||
| 2634 | num_range_list += num; | |||
| 2635 | ||||
| 2636 | /* Check if we can use `debug_information' directly. */ | |||
| 2637 | if (use_debug_info && num != 0) | |||
| 2638 | { | |||
| 2639 | if (!seen_first_offset) | |||
| 2640 | { | |||
| 2641 | /* This is the first range list. */ | |||
| 2642 | last_offset = debug_information [i].range_lists [0]; | |||
| 2643 | first = i; | |||
| 2644 | seen_first_offset = 1; | |||
| 2645 | j = 1; | |||
| 2646 | } | |||
| 2647 | else | |||
| 2648 | j = 0; | |||
| 2649 | ||||
| 2650 | for (; j < num; j++) | |||
| 2651 | { | |||
| 2652 | if (last_offset > | |||
| 2653 | debug_information [i].range_lists [j]) | |||
| 2654 | { | |||
| 2655 | use_debug_info = 0; | |||
| 2656 | break; | |||
| 2657 | } | |||
| 2658 | last_offset = debug_information [i].range_lists [j]; | |||
| 2659 | } | |||
| 2660 | } | |||
| 2661 | } | |||
| 2662 | ||||
| 2663 | if (!use_debug_info) | |||
| 2664 | /* FIXME: Should we handle this case? */ | |||
| 2665 | error (_("Range lists in .debug_info section aren't in ascending order!\n")("Range lists in .debug_info section aren't in ascending order!\n" )); | |||
| 2666 | ||||
| 2667 | if (!seen_first_offset) | |||
| 2668 | error (_("No range lists in .debug_info section!\n")("No range lists in .debug_info section!\n")); | |||
| 2669 | ||||
| 2670 | /* DWARF sections under Mach-O have non-zero addresses. */ | |||
| 2671 | if (debug_information [first].range_lists [0] != section->address) | |||
| 2672 | warn (_("Range lists in %s section start at 0x%lx\n")("Range lists in %s section start at 0x%lx\n"), | |||
| 2673 | section->name, debug_information [first].range_lists [0]); | |||
| 2674 | ||||
| 2675 | printf (_("Contents of the %s section:\n\n")("Contents of the %s section:\n\n"), section->name); | |||
| 2676 | printf (_(" Offset Begin End\n")(" Offset Begin End\n")); | |||
| 2677 | ||||
| 2678 | seen_first_offset = 0; | |||
| 2679 | for (i = first; i < num_debug_info_entries; i++) | |||
| 2680 | { | |||
| 2681 | unsigned long begin; | |||
| 2682 | unsigned long end; | |||
| 2683 | unsigned long offset; | |||
| 2684 | unsigned int pointer_size; | |||
| 2685 | unsigned long base_address; | |||
| 2686 | ||||
| 2687 | pointer_size = debug_information [i].pointer_size; | |||
| 2688 | ||||
| 2689 | for (j = 0; j < debug_information [i].num_range_lists; j++) | |||
| 2690 | { | |||
| 2691 | /* DWARF sections under Mach-O have non-zero addresses. */ | |||
| 2692 | offset = debug_information [i].range_lists [j] - section->address; | |||
| 2693 | next = section_begin + offset; | |||
| 2694 | base_address = debug_information [i].base_address; | |||
| 2695 | ||||
| 2696 | if (!seen_first_offset) | |||
| 2697 | seen_first_offset = 1; | |||
| 2698 | else | |||
| 2699 | { | |||
| 2700 | if (start < next) | |||
| 2701 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n")("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |||
| 2702 | (long)(start - section_begin), | |||
| 2703 | (long)(next - section_begin), section->name); | |||
| 2704 | else if (start > next) | |||
| 2705 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n")("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |||
| 2706 | (long)(start - section_begin), | |||
| 2707 | (long)(next - section_begin), section->name); | |||
| 2708 | } | |||
| 2709 | start = next; | |||
| 2710 | ||||
| 2711 | while (1) | |||
| 2712 | { | |||
| 2713 | begin = byte_get (start, pointer_size); | |||
| 2714 | start += pointer_size; | |||
| 2715 | end = byte_get (start, pointer_size); | |||
| 2716 | start += pointer_size; | |||
| 2717 | ||||
| 2718 | if (begin == 0 && end == 0) | |||
| 2719 | { | |||
| 2720 | printf (_(" %8.8lx <End of list>\n")(" %8.8lx <End of list>\n"), offset); | |||
| 2721 | break; | |||
| 2722 | } | |||
| 2723 | ||||
| 2724 | /* Check base address specifiers. */ | |||
| 2725 | if (begin == -1UL && end != -1UL) | |||
| 2726 | { | |||
| 2727 | base_address = end; | |||
| 2728 | printf (" %8.8lx %8.8lx %8.8lx (base address)\n", | |||
| 2729 | offset, begin, end); | |||
| 2730 | continue; | |||
| 2731 | } | |||
| 2732 | ||||
| 2733 | printf (" %8.8lx %8.8lx %8.8lx", | |||
| 2734 | offset, begin + base_address, end + base_address); | |||
| 2735 | ||||
| 2736 | if (begin == end) | |||
| 2737 | fputs (_(" (start == end)")(" (start == end)"), stdout(&__sF[1])); | |||
| 2738 | else if (begin > end) | |||
| 2739 | fputs (_(" (start > end)")(" (start > end)"), stdout(&__sF[1])); | |||
| 2740 | ||||
| 2741 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2742 | } | |||
| 2743 | } | |||
| 2744 | } | |||
| 2745 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 2746 | return 1; | |||
| 2747 | } | |||
| 2748 | ||||
| 2749 | typedef struct Frame_Chunk | |||
| 2750 | { | |||
| 2751 | struct Frame_Chunk *next; | |||
| 2752 | unsigned char *chunk_start; | |||
| 2753 | int ncols; | |||
| 2754 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ | |||
| 2755 | short int *col_type; | |||
| 2756 | int *col_offset; | |||
| 2757 | char *augmentation; | |||
| 2758 | unsigned int code_factor; | |||
| 2759 | int data_factor; | |||
| 2760 | unsigned long pc_begin; | |||
| 2761 | unsigned long pc_range; | |||
| 2762 | int cfa_reg; | |||
| 2763 | int cfa_offset; | |||
| 2764 | int ra; | |||
| 2765 | unsigned char fde_encoding; | |||
| 2766 | unsigned char cfa_exp; | |||
| 2767 | } | |||
| 2768 | Frame_Chunk; | |||
| 2769 | ||||
| 2770 | /* A marker for a col_type that means this column was never referenced | |||
| 2771 | in the frame info. */ | |||
| 2772 | #define DW_CFA_unreferenced(-1) (-1) | |||
| 2773 | /* Like DW_CFA_unreferenced, except indicating that it was referenced before | |||
| 2774 | (and therefore needs space in the columnar output). */ | |||
| 2775 | #define DW_CFA_placeholder(-2) (-2) | |||
| 2776 | ||||
| 2777 | static void | |||
| 2778 | frame_need_space (Frame_Chunk *fc, int reg) | |||
| 2779 | { | |||
| 2780 | int prev = fc->ncols; | |||
| 2781 | ||||
| 2782 | if (reg < fc->ncols) | |||
| 2783 | return; | |||
| 2784 | ||||
| 2785 | fc->ncols = reg + 1; | |||
| 2786 | fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int)); | |||
| 2787 | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); | |||
| 2788 | ||||
| 2789 | while (prev < fc->ncols) | |||
| 2790 | { | |||
| 2791 | fc->col_type[prev] = DW_CFA_unreferenced(-1); | |||
| 2792 | fc->col_offset[prev] = 0; | |||
| 2793 | prev++; | |||
| 2794 | } | |||
| 2795 | } | |||
| 2796 | ||||
| 2797 | static void | |||
| 2798 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs) | |||
| 2799 | { | |||
| 2800 | int r; | |||
| 2801 | char tmp[100]; | |||
| 2802 | ||||
| 2803 | if (*max_regs < fc->ncols) | |||
| 2804 | *max_regs = fc->ncols; | |||
| 2805 | ||||
| 2806 | if (*need_col_headers) | |||
| 2807 | { | |||
| 2808 | *need_col_headers = 0; | |||
| 2809 | ||||
| 2810 | printf (" LOC CFA "); | |||
| 2811 | ||||
| 2812 | for (r = 0; r < *max_regs; r++) | |||
| 2813 | if (fc->col_type[r] != DW_CFA_unreferenced(-1)) | |||
| 2814 | { | |||
| 2815 | if (r == fc->ra) | |||
| 2816 | printf ("ra "); | |||
| 2817 | else | |||
| 2818 | printf ("r%-4d", r); | |||
| 2819 | } | |||
| 2820 | ||||
| 2821 | printf ("\n"); | |||
| 2822 | } | |||
| 2823 | ||||
| 2824 | printf ("%08lx ", fc->pc_begin); | |||
| 2825 | if (fc->cfa_exp) | |||
| 2826 | strcpy (tmp, "exp"); | |||
| 2827 | else | |||
| 2828 | sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset); | |||
| 2829 | printf ("%-8s ", tmp); | |||
| 2830 | ||||
| 2831 | for (r = 0; r < fc->ncols; r++) | |||
| 2832 | { | |||
| 2833 | if (fc->col_type[r] != DW_CFA_unreferenced(-1)) | |||
| 2834 | { | |||
| 2835 | switch (fc->col_type[r]) | |||
| 2836 | { | |||
| 2837 | case DW_CFA_undefined: | |||
| 2838 | strcpy (tmp, "u"); | |||
| 2839 | break; | |||
| 2840 | case DW_CFA_same_value: | |||
| 2841 | strcpy (tmp, "s"); | |||
| 2842 | break; | |||
| 2843 | case DW_CFA_offset: | |||
| 2844 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |||
| 2845 | break; | |||
| 2846 | case DW_CFA_val_offset: | |||
| 2847 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |||
| 2848 | break; | |||
| 2849 | case DW_CFA_register: | |||
| 2850 | sprintf (tmp, "r%d", fc->col_offset[r]); | |||
| 2851 | break; | |||
| 2852 | case DW_CFA_expression: | |||
| 2853 | strcpy (tmp, "exp"); | |||
| 2854 | break; | |||
| 2855 | case DW_CFA_val_expression: | |||
| 2856 | strcpy (tmp, "vexp"); | |||
| 2857 | break; | |||
| 2858 | case DW_CFA_placeholder(-2): | |||
| 2859 | tmp[0] = '\0'; | |||
| 2860 | break; | |||
| 2861 | default: | |||
| 2862 | strcpy (tmp, "n/a"); | |||
| 2863 | break; | |||
| 2864 | } | |||
| 2865 | printf ("%-5s", tmp); | |||
| 2866 | } | |||
| 2867 | } | |||
| 2868 | printf ("\n"); | |||
| 2869 | } | |||
| 2870 | ||||
| 2871 | static int | |||
| 2872 | size_of_encoded_value (int encoding) | |||
| 2873 | { | |||
| 2874 | switch (encoding & 0x7) | |||
| 2875 | { | |||
| 2876 | default: /* ??? */ | |||
| 2877 | case 0: return eh_addr_size; | |||
| 2878 | case 2: return 2; | |||
| 2879 | case 3: return 4; | |||
| 2880 | case 4: return 8; | |||
| 2881 | } | |||
| 2882 | } | |||
| 2883 | ||||
| 2884 | static dwarf_vma | |||
| 2885 | get_encoded_value (unsigned char *data, int encoding) | |||
| 2886 | { | |||
| 2887 | int size = size_of_encoded_value (encoding); | |||
| 2888 | if (encoding & DW_EH_PE_signed0x08) | |||
| 2889 | return byte_get_signed (data, size); | |||
| 2890 | else | |||
| 2891 | return byte_get (data, size); | |||
| 2892 | } | |||
| 2893 | ||||
| 2894 | #define GET(N) byte_get (start, N); start += N | |||
| 2895 | #define LEB() read_leb128 (start, & length_return, 0); start += length_return | |||
| 2896 | #define SLEB() read_leb128 (start, & length_return, 1); start += length_return | |||
| 2897 | ||||
| 2898 | static int | |||
| 2899 | display_debug_frames (struct dwarf_section *section, | |||
| 2900 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 2901 | { | |||
| 2902 | unsigned char *start = section->start; | |||
| 2903 | unsigned char *end = start + section->size; | |||
| 2904 | unsigned char *section_start = start; | |||
| 2905 | Frame_Chunk *chunks = 0; | |||
| 2906 | Frame_Chunk *remembered_state = 0; | |||
| 2907 | Frame_Chunk *rs; | |||
| 2908 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |||
| ||||
| 2909 | unsigned int length_return; | |||
| 2910 | int max_regs = 0; | |||
| 2911 | ||||
| 2912 | printf (_("The section %s contains:\n")("The section %s contains:\n"), section->name); | |||
| 2913 | ||||
| 2914 | while (start < end) | |||
| 2915 | { | |||
| 2916 | unsigned char *saved_start; | |||
| 2917 | unsigned char *block_end; | |||
| 2918 | unsigned long length; | |||
| 2919 | unsigned long cie_id; | |||
| 2920 | Frame_Chunk *fc; | |||
| 2921 | Frame_Chunk *cie; | |||
| 2922 | int need_col_headers = 1; | |||
| 2923 | unsigned char *augmentation_data = NULL((void*)0); | |||
| 2924 | unsigned long augmentation_data_len = 0; | |||
| 2925 | int encoded_ptr_size = eh_addr_size; | |||
| 2926 | int offset_size; | |||
| 2927 | int initial_length_size; | |||
| 2928 | ||||
| 2929 | saved_start = start; | |||
| 2930 | length = byte_get (start, 4); start += 4; | |||
| 2931 | ||||
| 2932 | if (length == 0) | |||
| 2933 | { | |||
| 2934 | printf ("\n%08lx ZERO terminator\n\n", | |||
| 2935 | (unsigned long)(saved_start - section_start)); | |||
| 2936 | return 1; | |||
| 2937 | } | |||
| 2938 | ||||
| 2939 | if (length == 0xffffffff) | |||
| 2940 | { | |||
| 2941 | length = byte_get (start, 8); | |||
| 2942 | start += 8; | |||
| 2943 | offset_size = 8; | |||
| 2944 | initial_length_size = 12; | |||
| 2945 | } | |||
| 2946 | else | |||
| 2947 | { | |||
| 2948 | offset_size = 4; | |||
| 2949 | initial_length_size = 4; | |||
| 2950 | } | |||
| 2951 | ||||
| 2952 | block_end = saved_start + length + initial_length_size; | |||
| 2953 | cie_id = byte_get (start, offset_size); start += offset_size; | |||
| 2954 | ||||
| 2955 | if (is_eh
| |||
| 2956 | { | |||
| 2957 | int version; | |||
| 2958 | ||||
| 2959 | fc = xmalloc (sizeof (Frame_Chunk)); | |||
| 2960 | memset (fc, 0, sizeof (Frame_Chunk)); | |||
| 2961 | ||||
| 2962 | fc->next = chunks; | |||
| 2963 | chunks = fc; | |||
| 2964 | fc->chunk_start = saved_start; | |||
| 2965 | fc->ncols = 0; | |||
| 2966 | fc->col_type = xmalloc (sizeof (short int)); | |||
| 2967 | fc->col_offset = xmalloc (sizeof (int)); | |||
| 2968 | frame_need_space (fc, max_regs-1); | |||
| 2969 | ||||
| 2970 | version = *start++; | |||
| 2971 | ||||
| 2972 | fc->augmentation = (char *) start; | |||
| 2973 | start = (unsigned char *) strchr ((char *) start, '\0') + 1; | |||
| 2974 | ||||
| 2975 | if (fc->augmentation[0] == 'z') | |||
| 2976 | { | |||
| 2977 | fc->code_factor = LEB (); | |||
| 2978 | fc->data_factor = SLEB (); | |||
| 2979 | if (version == 1) | |||
| 2980 | { | |||
| 2981 | fc->ra = GET (1); | |||
| 2982 | } | |||
| 2983 | else | |||
| 2984 | { | |||
| 2985 | fc->ra = LEB (); | |||
| 2986 | } | |||
| 2987 | augmentation_data_len = LEB (); | |||
| 2988 | augmentation_data = start; | |||
| 2989 | start += augmentation_data_len; | |||
| 2990 | } | |||
| 2991 | else if (strcmp (fc->augmentation, "eh") == 0) | |||
| 2992 | { | |||
| 2993 | start += eh_addr_size; | |||
| 2994 | fc->code_factor = LEB (); | |||
| 2995 | fc->data_factor = SLEB (); | |||
| 2996 | if (version == 1) | |||
| 2997 | { | |||
| 2998 | fc->ra = GET (1); | |||
| 2999 | } | |||
| 3000 | else | |||
| 3001 | { | |||
| 3002 | fc->ra = LEB (); | |||
| 3003 | } | |||
| 3004 | } | |||
| 3005 | else | |||
| 3006 | { | |||
| 3007 | fc->code_factor = LEB (); | |||
| 3008 | fc->data_factor = SLEB (); | |||
| 3009 | if (version == 1) | |||
| 3010 | { | |||
| 3011 | fc->ra = GET (1); | |||
| 3012 | } | |||
| 3013 | else | |||
| 3014 | { | |||
| 3015 | fc->ra = LEB (); | |||
| 3016 | } | |||
| 3017 | } | |||
| 3018 | cie = fc; | |||
| 3019 | ||||
| 3020 | if (do_debug_frames_interp) | |||
| 3021 | printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", | |||
| 3022 | (unsigned long)(saved_start - section_start), length, cie_id, | |||
| 3023 | fc->augmentation, fc->code_factor, fc->data_factor, | |||
| 3024 | fc->ra); | |||
| 3025 | else | |||
| 3026 | { | |||
| 3027 | printf ("\n%08lx %08lx %08lx CIE\n", | |||
| 3028 | (unsigned long)(saved_start - section_start), length, cie_id); | |||
| 3029 | printf (" Version: %d\n", version); | |||
| 3030 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |||
| 3031 | printf (" Code alignment factor: %u\n", fc->code_factor); | |||
| 3032 | printf (" Data alignment factor: %d\n", fc->data_factor); | |||
| 3033 | printf (" Return address column: %d\n", fc->ra); | |||
| 3034 | ||||
| 3035 | if (augmentation_data_len) | |||
| 3036 | { | |||
| 3037 | unsigned long i; | |||
| 3038 | printf (" Augmentation data: "); | |||
| 3039 | for (i = 0; i < augmentation_data_len; ++i) | |||
| 3040 | printf (" %02x", augmentation_data[i]); | |||
| 3041 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 3042 | } | |||
| 3043 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 3044 | } | |||
| 3045 | ||||
| 3046 | if (augmentation_data_len) | |||
| 3047 | { | |||
| 3048 | unsigned char *p, *q; | |||
| 3049 | p = (unsigned char *) fc->augmentation + 1; | |||
| 3050 | q = augmentation_data; | |||
| 3051 | ||||
| 3052 | while (1) | |||
| 3053 | { | |||
| 3054 | if (*p == 'L') | |||
| 3055 | q++; | |||
| 3056 | else if (*p == 'P') | |||
| 3057 | q += 1 + size_of_encoded_value (*q); | |||
| 3058 | else if (*p == 'R') | |||
| 3059 | fc->fde_encoding = *q++; | |||
| 3060 | else | |||
| 3061 | break; | |||
| 3062 | p++; | |||
| 3063 | } | |||
| 3064 | ||||
| 3065 | if (fc->fde_encoding) | |||
| 3066 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |||
| 3067 | } | |||
| 3068 | ||||
| 3069 | frame_need_space (fc, fc->ra); | |||
| 3070 | } | |||
| 3071 | else | |||
| 3072 | { | |||
| 3073 | unsigned char *look_for; | |||
| 3074 | static Frame_Chunk fde_fc; | |||
| 3075 | ||||
| 3076 | fc = & fde_fc; | |||
| 3077 | memset (fc, 0, sizeof (Frame_Chunk)); | |||
| 3078 | ||||
| 3079 | look_for = is_eh ? start - 4 - cie_id : section_start + cie_id; | |||
| 3080 | ||||
| 3081 | for (cie = chunks; cie ; cie = cie->next) | |||
| 3082 | if (cie->chunk_start == look_for) | |||
| 3083 | break; | |||
| 3084 | ||||
| 3085 | if (!cie) | |||
| 3086 | { | |||
| 3087 | warn ("Invalid CIE pointer %08lx in FDE at %08lx\n", | |||
| 3088 | cie_id, (unsigned long)(saved_start - section_start)); | |||
| 3089 | start = block_end; | |||
| 3090 | fc->ncols = 0; | |||
| 3091 | fc->col_type = xmalloc (sizeof (short int)); | |||
| 3092 | fc->col_offset = xmalloc (sizeof (int)); | |||
| 3093 | frame_need_space (fc, max_regs - 1); | |||
| 3094 | cie = fc; | |||
| 3095 | fc->augmentation = ""; | |||
| 3096 | fc->fde_encoding = 0; | |||
| 3097 | } | |||
| 3098 | else | |||
| 3099 | { | |||
| 3100 | fc->ncols = cie->ncols; | |||
| 3101 | fc->col_type = xcmalloc (fc->ncols, sizeof (short int)); | |||
| 3102 | fc->col_offset = xcmalloc (fc->ncols, sizeof (int)); | |||
| 3103 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); | |||
| 3104 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |||
| 3105 | fc->augmentation = cie->augmentation; | |||
| 3106 | fc->code_factor = cie->code_factor; | |||
| 3107 | fc->data_factor = cie->data_factor; | |||
| 3108 | fc->cfa_reg = cie->cfa_reg; | |||
| 3109 | fc->cfa_offset = cie->cfa_offset; | |||
| 3110 | fc->ra = cie->ra; | |||
| 3111 | frame_need_space (fc, max_regs-1); | |||
| 3112 | fc->fde_encoding = cie->fde_encoding; | |||
| 3113 | } | |||
| 3114 | ||||
| 3115 | if (fc->fde_encoding) | |||
| 3116 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |||
| 3117 | ||||
| 3118 | fc->pc_begin = get_encoded_value (start, fc->fde_encoding); | |||
| 3119 | if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel0x10 | |||
| 3120 | /* Don't adjust for relocatable file since there's | |||
| 3121 | invariably a pcrel reloc here, which we haven't | |||
| 3122 | applied. */ | |||
| 3123 | && !is_relocatable) | |||
| 3124 | fc->pc_begin += section->address + (start - section_start); | |||
| 3125 | start += encoded_ptr_size; | |||
| 3126 | fc->pc_range = byte_get (start, encoded_ptr_size); | |||
| 3127 | start += encoded_ptr_size; | |||
| 3128 | ||||
| 3129 | if (cie->augmentation[0] == 'z') | |||
| 3130 | { | |||
| 3131 | augmentation_data_len = LEB (); | |||
| 3132 | augmentation_data = start; | |||
| 3133 | start += augmentation_data_len; | |||
| 3134 | } | |||
| 3135 | ||||
| 3136 | printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n", | |||
| 3137 | (unsigned long)(saved_start - section_start), length, cie_id, | |||
| 3138 | (unsigned long)(cie->chunk_start - section_start), | |||
| 3139 | fc->pc_begin, fc->pc_begin + fc->pc_range); | |||
| 3140 | if (! do_debug_frames_interp && augmentation_data_len) | |||
| 3141 | { | |||
| 3142 | unsigned long i; | |||
| 3143 | ||||
| 3144 | printf (" Augmentation data: "); | |||
| 3145 | for (i = 0; i < augmentation_data_len; ++i) | |||
| 3146 | printf (" %02x", augmentation_data[i]); | |||
| 3147 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 3148 | putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n', (&__sF[1]))); | |||
| 3149 | } | |||
| 3150 | } | |||
| 3151 | ||||
| 3152 | /* At this point, fc is the current chunk, cie (if any) is set, and | |||
| 3153 | we're about to interpret instructions for the chunk. */ | |||
| 3154 | /* ??? At present we need to do this always, since this sizes the | |||
| 3155 | fc->col_type and fc->col_offset arrays, which we write into always. | |||
| 3156 | We should probably split the interpreted and non-interpreted bits | |||
| 3157 | into two different routines, since there's so much that doesn't | |||
| 3158 | really overlap between them. */ | |||
| 3159 | if (1 || do_debug_frames_interp) | |||
| 3160 | { | |||
| 3161 | /* Start by making a pass over the chunk, allocating storage | |||
| 3162 | and taking note of what registers are used. */ | |||
| 3163 | unsigned char *tmp = start; | |||
| 3164 | ||||
| 3165 | while (start < block_end) | |||
| 3166 | { | |||
| 3167 | unsigned op, opa; | |||
| 3168 | unsigned long reg, tmp; | |||
| 3169 | ||||
| 3170 | op = *start++; | |||
| 3171 | opa = op & 0x3f; | |||
| 3172 | if (op & 0xc0) | |||
| 3173 | op &= 0xc0; | |||
| 3174 | ||||
| 3175 | /* Warning: if you add any more cases to this switch, be | |||
| 3176 | sure to add them to the corresponding switch below. */ | |||
| 3177 | switch (op) | |||
| 3178 | { | |||
| 3179 | case DW_CFA_advance_loc: | |||
| 3180 | break; | |||
| 3181 | case DW_CFA_offset: | |||
| 3182 | LEB (); | |||
| 3183 | frame_need_space (fc, opa); | |||
| 3184 | fc->col_type[opa] = DW_CFA_undefined; | |||
| 3185 | break; | |||
| 3186 | case DW_CFA_restore: | |||
| 3187 | frame_need_space (fc, opa); | |||
| 3188 | fc->col_type[opa] = DW_CFA_undefined; | |||
| 3189 | break; | |||
| 3190 | case DW_CFA_set_loc: | |||
| 3191 | start += encoded_ptr_size; | |||
| 3192 | break; | |||
| 3193 | case DW_CFA_advance_loc1: | |||
| 3194 | start += 1; | |||
| 3195 | break; | |||
| 3196 | case DW_CFA_advance_loc2: | |||
| 3197 | start += 2; | |||
| 3198 | break; | |||
| 3199 | case DW_CFA_advance_loc4: | |||
| 3200 | start += 4; | |||
| 3201 | break; | |||
| 3202 | case DW_CFA_offset_extended: | |||
| 3203 | case DW_CFA_val_offset: | |||
| 3204 | reg = LEB (); LEB (); | |||
| 3205 | frame_need_space (fc, reg); | |||
| 3206 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3207 | break; | |||
| 3208 | case DW_CFA_restore_extended: | |||
| 3209 | reg = LEB (); | |||
| 3210 | frame_need_space (fc, reg); | |||
| 3211 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3212 | break; | |||
| 3213 | case DW_CFA_undefined: | |||
| 3214 | reg = LEB (); | |||
| 3215 | frame_need_space (fc, reg); | |||
| 3216 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3217 | break; | |||
| 3218 | case DW_CFA_same_value: | |||
| 3219 | reg = LEB (); | |||
| 3220 | frame_need_space (fc, reg); | |||
| 3221 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3222 | break; | |||
| 3223 | case DW_CFA_register: | |||
| 3224 | reg = LEB (); LEB (); | |||
| 3225 | frame_need_space (fc, reg); | |||
| 3226 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3227 | break; | |||
| 3228 | case DW_CFA_def_cfa: | |||
| 3229 | LEB (); LEB (); | |||
| 3230 | break; | |||
| 3231 | case DW_CFA_def_cfa_register: | |||
| 3232 | LEB (); | |||
| 3233 | break; | |||
| 3234 | case DW_CFA_def_cfa_offset: | |||
| 3235 | LEB (); | |||
| 3236 | break; | |||
| 3237 | case DW_CFA_def_cfa_expression: | |||
| 3238 | tmp = LEB (); | |||
| 3239 | start += tmp; | |||
| 3240 | break; | |||
| 3241 | case DW_CFA_expression: | |||
| 3242 | case DW_CFA_val_expression: | |||
| 3243 | reg = LEB (); | |||
| 3244 | tmp = LEB (); | |||
| 3245 | start += tmp; | |||
| 3246 | frame_need_space (fc, reg); | |||
| 3247 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3248 | break; | |||
| 3249 | case DW_CFA_offset_extended_sf: | |||
| 3250 | case DW_CFA_val_offset_sf: | |||
| 3251 | reg = LEB (); SLEB (); | |||
| 3252 | frame_need_space (fc, reg); | |||
| 3253 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3254 | break; | |||
| 3255 | case DW_CFA_def_cfa_sf: | |||
| 3256 | LEB (); SLEB (); | |||
| 3257 | break; | |||
| 3258 | case DW_CFA_def_cfa_offset_sf: | |||
| 3259 | SLEB (); | |||
| 3260 | break; | |||
| 3261 | case DW_CFA_MIPS_advance_loc8: | |||
| 3262 | start += 8; | |||
| 3263 | break; | |||
| 3264 | case DW_CFA_GNU_args_size: | |||
| 3265 | LEB (); | |||
| 3266 | break; | |||
| 3267 | case DW_CFA_GNU_negative_offset_extended: | |||
| 3268 | reg = LEB (); LEB (); | |||
| 3269 | frame_need_space (fc, reg); | |||
| 3270 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3271 | ||||
| 3272 | default: | |||
| 3273 | break; | |||
| 3274 | } | |||
| 3275 | } | |||
| 3276 | start = tmp; | |||
| 3277 | } | |||
| 3278 | ||||
| 3279 | /* Now we know what registers are used, make a second pass over | |||
| 3280 | the chunk, this time actually printing out the info. */ | |||
| 3281 | ||||
| 3282 | while (start < block_end) | |||
| 3283 | { | |||
| 3284 | unsigned op, opa; | |||
| 3285 | unsigned long ul, reg, roffs; | |||
| 3286 | long l, ofs; | |||
| 3287 | dwarf_vma vma; | |||
| 3288 | ||||
| 3289 | op = *start++; | |||
| 3290 | opa = op & 0x3f; | |||
| 3291 | if (op & 0xc0) | |||
| 3292 | op &= 0xc0; | |||
| 3293 | ||||
| 3294 | /* Warning: if you add any more cases to this switch, be | |||
| 3295 | sure to add them to the corresponding switch above. */ | |||
| 3296 | switch (op) | |||
| 3297 | { | |||
| 3298 | case DW_CFA_advance_loc: | |||
| 3299 | if (do_debug_frames_interp) | |||
| 3300 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3301 | else | |||
| 3302 | printf (" DW_CFA_advance_loc: %d to %08lx\n", | |||
| 3303 | opa * fc->code_factor, | |||
| 3304 | fc->pc_begin + opa * fc->code_factor); | |||
| 3305 | fc->pc_begin += opa * fc->code_factor; | |||
| 3306 | break; | |||
| 3307 | ||||
| 3308 | case DW_CFA_offset: | |||
| 3309 | roffs = LEB (); | |||
| 3310 | if (! do_debug_frames_interp) | |||
| 3311 | printf (" DW_CFA_offset: r%d at cfa%+ld\n", | |||
| 3312 | opa, roffs * fc->data_factor); | |||
| 3313 | fc->col_type[opa] = DW_CFA_offset; | |||
| 3314 | fc->col_offset[opa] = roffs * fc->data_factor; | |||
| 3315 | break; | |||
| 3316 | ||||
| 3317 | case DW_CFA_restore: | |||
| 3318 | if (! do_debug_frames_interp) | |||
| 3319 | printf (" DW_CFA_restore: r%d\n", opa); | |||
| 3320 | if ((fc->col_type[opa] = cie->col_type[opa]) == | |||
| 3321 | DW_CFA_unreferenced(-1)) | |||
| 3322 | fc->col_type[opa] = DW_CFA_placeholder(-2); | |||
| 3323 | fc->col_offset[opa] = cie->col_offset[opa]; | |||
| 3324 | break; | |||
| 3325 | ||||
| 3326 | case DW_CFA_set_loc: | |||
| 3327 | vma = get_encoded_value (start, fc->fde_encoding); | |||
| 3328 | if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel0x10 | |||
| 3329 | && !is_relocatable) | |||
| 3330 | vma += section->address + (start - section_start); | |||
| 3331 | start += encoded_ptr_size; | |||
| 3332 | if (do_debug_frames_interp) | |||
| 3333 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3334 | else | |||
| 3335 | printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma); | |||
| 3336 | fc->pc_begin = vma; | |||
| 3337 | break; | |||
| 3338 | ||||
| 3339 | case DW_CFA_advance_loc1: | |||
| 3340 | ofs = byte_get (start, 1); start += 1; | |||
| 3341 | if (do_debug_frames_interp) | |||
| 3342 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3343 | else | |||
| 3344 | printf (" DW_CFA_advance_loc1: %ld to %08lx\n", | |||
| 3345 | ofs * fc->code_factor, | |||
| 3346 | fc->pc_begin + ofs * fc->code_factor); | |||
| 3347 | fc->pc_begin += ofs * fc->code_factor; | |||
| 3348 | break; | |||
| 3349 | ||||
| 3350 | case DW_CFA_advance_loc2: | |||
| 3351 | ofs = byte_get (start, 2); start += 2; | |||
| 3352 | if (do_debug_frames_interp) | |||
| 3353 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3354 | else | |||
| 3355 | printf (" DW_CFA_advance_loc2: %ld to %08lx\n", | |||
| 3356 | ofs * fc->code_factor, | |||
| 3357 | fc->pc_begin + ofs * fc->code_factor); | |||
| 3358 | fc->pc_begin += ofs * fc->code_factor; | |||
| 3359 | break; | |||
| 3360 | ||||
| 3361 | case DW_CFA_advance_loc4: | |||
| 3362 | ofs = byte_get (start, 4); start += 4; | |||
| 3363 | if (do_debug_frames_interp) | |||
| 3364 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3365 | else | |||
| 3366 | printf (" DW_CFA_advance_loc4: %ld to %08lx\n", | |||
| 3367 | ofs * fc->code_factor, | |||
| 3368 | fc->pc_begin + ofs * fc->code_factor); | |||
| 3369 | fc->pc_begin += ofs * fc->code_factor; | |||
| 3370 | break; | |||
| 3371 | ||||
| 3372 | case DW_CFA_offset_extended: | |||
| 3373 | reg = LEB (); | |||
| 3374 | roffs = LEB (); | |||
| 3375 | if (! do_debug_frames_interp) | |||
| 3376 | printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n", | |||
| 3377 | reg, roffs * fc->data_factor); | |||
| 3378 | fc->col_type[reg] = DW_CFA_offset; | |||
| 3379 | fc->col_offset[reg] = roffs * fc->data_factor; | |||
| 3380 | break; | |||
| 3381 | ||||
| 3382 | case DW_CFA_val_offset: | |||
| 3383 | reg = LEB (); | |||
| 3384 | roffs = LEB (); | |||
| 3385 | if (! do_debug_frames_interp) | |||
| 3386 | printf (" DW_CFA_val_offset: r%ld at cfa%+ld\n", | |||
| 3387 | reg, roffs * fc->data_factor); | |||
| 3388 | fc->col_type[reg] = DW_CFA_val_offset; | |||
| 3389 | fc->col_offset[reg] = roffs * fc->data_factor; | |||
| 3390 | break; | |||
| 3391 | ||||
| 3392 | case DW_CFA_restore_extended: | |||
| 3393 | reg = LEB (); | |||
| 3394 | if (! do_debug_frames_interp) | |||
| 3395 | printf (" DW_CFA_restore_extended: r%ld\n", reg); | |||
| 3396 | if ((fc->col_type[opa] = cie->col_type[opa]) == | |||
| 3397 | DW_CFA_unreferenced(-1)) | |||
| 3398 | fc->col_type[opa] = DW_CFA_placeholder(-2); | |||
| 3399 | fc->col_offset[reg] = cie->col_offset[reg]; | |||
| 3400 | break; | |||
| 3401 | ||||
| 3402 | case DW_CFA_undefined: | |||
| 3403 | reg = LEB (); | |||
| 3404 | if (! do_debug_frames_interp) | |||
| 3405 | printf (" DW_CFA_undefined: r%ld\n", reg); | |||
| 3406 | fc->col_type[reg] = DW_CFA_undefined; | |||
| 3407 | fc->col_offset[reg] = 0; | |||
| 3408 | break; | |||
| 3409 | ||||
| 3410 | case DW_CFA_same_value: | |||
| 3411 | reg = LEB (); | |||
| 3412 | if (! do_debug_frames_interp) | |||
| 3413 | printf (" DW_CFA_same_value: r%ld\n", reg); | |||
| 3414 | fc->col_type[reg] = DW_CFA_same_value; | |||
| 3415 | fc->col_offset[reg] = 0; | |||
| 3416 | break; | |||
| 3417 | ||||
| 3418 | case DW_CFA_register: | |||
| 3419 | reg = LEB (); | |||
| 3420 | roffs = LEB (); | |||
| 3421 | if (! do_debug_frames_interp) | |||
| 3422 | printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs); | |||
| 3423 | fc->col_type[reg] = DW_CFA_register; | |||
| 3424 | fc->col_offset[reg] = roffs; | |||
| 3425 | break; | |||
| 3426 | ||||
| 3427 | case DW_CFA_remember_state: | |||
| 3428 | if (! do_debug_frames_interp) | |||
| 3429 | printf (" DW_CFA_remember_state\n"); | |||
| 3430 | rs = xmalloc (sizeof (Frame_Chunk)); | |||
| 3431 | rs->ncols = fc->ncols; | |||
| 3432 | rs->col_type = xcmalloc (rs->ncols, sizeof (short int)); | |||
| 3433 | rs->col_offset = xcmalloc (rs->ncols, sizeof (int)); | |||
| 3434 | memcpy (rs->col_type, fc->col_type, rs->ncols); | |||
| 3435 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int)); | |||
| 3436 | rs->next = remembered_state; | |||
| 3437 | remembered_state = rs; | |||
| 3438 | break; | |||
| 3439 | ||||
| 3440 | case DW_CFA_restore_state: | |||
| 3441 | if (! do_debug_frames_interp) | |||
| 3442 | printf (" DW_CFA_restore_state\n"); | |||
| 3443 | rs = remembered_state; | |||
| 3444 | if (rs) | |||
| 3445 | { | |||
| 3446 | remembered_state = rs->next; | |||
| 3447 | frame_need_space (fc, rs->ncols-1); | |||
| 3448 | memcpy (fc->col_type, rs->col_type, rs->ncols); | |||
| 3449 | memcpy (fc->col_offset, rs->col_offset, | |||
| 3450 | rs->ncols * sizeof (int)); | |||
| 3451 | free (rs->col_type); | |||
| 3452 | free (rs->col_offset); | |||
| 3453 | free (rs); | |||
| 3454 | } | |||
| 3455 | else if (do_debug_frames_interp) | |||
| 3456 | printf ("Mismatched DW_CFA_restore_state\n"); | |||
| 3457 | break; | |||
| 3458 | ||||
| 3459 | case DW_CFA_def_cfa: | |||
| 3460 | fc->cfa_reg = LEB (); | |||
| 3461 | fc->cfa_offset = LEB (); | |||
| 3462 | fc->cfa_exp = 0; | |||
| 3463 | if (! do_debug_frames_interp) | |||
| 3464 | printf (" DW_CFA_def_cfa: r%d ofs %d\n", | |||
| 3465 | fc->cfa_reg, fc->cfa_offset); | |||
| 3466 | break; | |||
| 3467 | ||||
| 3468 | case DW_CFA_def_cfa_register: | |||
| 3469 | fc->cfa_reg = LEB (); | |||
| 3470 | fc->cfa_exp = 0; | |||
| 3471 | if (! do_debug_frames_interp) | |||
| 3472 | printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg); | |||
| 3473 | break; | |||
| 3474 | ||||
| 3475 | case DW_CFA_def_cfa_offset: | |||
| 3476 | fc->cfa_offset = LEB (); | |||
| 3477 | if (! do_debug_frames_interp) | |||
| 3478 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |||
| 3479 | break; | |||
| 3480 | ||||
| 3481 | case DW_CFA_nop: | |||
| 3482 | if (! do_debug_frames_interp) | |||
| 3483 | printf (" DW_CFA_nop\n"); | |||
| 3484 | break; | |||
| 3485 | ||||
| 3486 | case DW_CFA_def_cfa_expression: | |||
| 3487 | ul = LEB (); | |||
| 3488 | if (! do_debug_frames_interp) | |||
| 3489 | { | |||
| 3490 | printf (" DW_CFA_def_cfa_expression ("); | |||
| 3491 | decode_location_expression (start, eh_addr_size, ul, 0); | |||
| 3492 | printf (")\n"); | |||
| 3493 | } | |||
| 3494 | fc->cfa_exp = 1; | |||
| 3495 | start += ul; | |||
| 3496 | break; | |||
| 3497 | ||||
| 3498 | case DW_CFA_expression: | |||
| 3499 | reg = LEB (); | |||
| 3500 | ul = LEB (); | |||
| 3501 | if (! do_debug_frames_interp) | |||
| 3502 | { | |||
| 3503 | printf (" DW_CFA_expression: r%ld (", reg); | |||
| 3504 | decode_location_expression (start, eh_addr_size, ul, 0); | |||
| 3505 | printf (")\n"); | |||
| 3506 | } | |||
| 3507 | fc->col_type[reg] = DW_CFA_expression; | |||
| 3508 | start += ul; | |||
| 3509 | break; | |||
| 3510 | ||||
| 3511 | case DW_CFA_val_expression: | |||
| 3512 | reg = LEB (); | |||
| 3513 | ul = LEB (); | |||
| 3514 | if (! do_debug_frames_interp) | |||
| 3515 | { | |||
| 3516 | printf (" DW_CFA_val_expression: r%ld (", reg); | |||
| 3517 | decode_location_expression (start, eh_addr_size, ul, 0); | |||
| 3518 | printf (")\n"); | |||
| 3519 | } | |||
| 3520 | fc->col_type[reg] = DW_CFA_val_expression; | |||
| 3521 | start += ul; | |||
| 3522 | break; | |||
| 3523 | ||||
| 3524 | case DW_CFA_offset_extended_sf: | |||
| 3525 | reg = LEB (); | |||
| 3526 | l = SLEB (); | |||
| 3527 | frame_need_space (fc, reg); | |||
| 3528 | if (! do_debug_frames_interp) | |||
| 3529 | printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n", | |||
| 3530 | reg, l * fc->data_factor); | |||
| 3531 | fc->col_type[reg] = DW_CFA_offset; | |||
| 3532 | fc->col_offset[reg] = l * fc->data_factor; | |||
| 3533 | break; | |||
| 3534 | ||||
| 3535 | case DW_CFA_val_offset_sf: | |||
| 3536 | reg = LEB (); | |||
| 3537 | l = SLEB (); | |||
| 3538 | frame_need_space (fc, reg); | |||
| 3539 | if (! do_debug_frames_interp) | |||
| 3540 | printf (" DW_CFA_val_offset_sf: r%ld at cfa%+ld\n", | |||
| 3541 | reg, l * fc->data_factor); | |||
| 3542 | fc->col_type[reg] = DW_CFA_val_offset; | |||
| 3543 | fc->col_offset[reg] = l * fc->data_factor; | |||
| 3544 | break; | |||
| 3545 | ||||
| 3546 | case DW_CFA_def_cfa_sf: | |||
| 3547 | fc->cfa_reg = LEB (); | |||
| 3548 | fc->cfa_offset = SLEB (); | |||
| 3549 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |||
| 3550 | fc->cfa_exp = 0; | |||
| 3551 | if (! do_debug_frames_interp) | |||
| 3552 | printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n", | |||
| 3553 | fc->cfa_reg, fc->cfa_offset); | |||
| 3554 | break; | |||
| 3555 | ||||
| 3556 | case DW_CFA_def_cfa_offset_sf: | |||
| 3557 | fc->cfa_offset = SLEB (); | |||
| 3558 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |||
| 3559 | if (! do_debug_frames_interp) | |||
| 3560 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); | |||
| 3561 | break; | |||
| 3562 | ||||
| 3563 | case DW_CFA_MIPS_advance_loc8: | |||
| 3564 | ofs = byte_get (start, 8); start += 8; | |||
| 3565 | if (do_debug_frames_interp) | |||
| 3566 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3567 | else | |||
| 3568 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n", | |||
| 3569 | ofs * fc->code_factor, | |||
| 3570 | fc->pc_begin + ofs * fc->code_factor); | |||
| 3571 | fc->pc_begin += ofs * fc->code_factor; | |||
| 3572 | break; | |||
| 3573 | ||||
| 3574 | case DW_CFA_GNU_window_save: | |||
| 3575 | if (! do_debug_frames_interp) | |||
| 3576 | printf (" DW_CFA_GNU_window_save\n"); | |||
| 3577 | break; | |||
| 3578 | ||||
| 3579 | case DW_CFA_GNU_args_size: | |||
| 3580 | ul = LEB (); | |||
| 3581 | if (! do_debug_frames_interp) | |||
| 3582 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |||
| 3583 | break; | |||
| 3584 | ||||
| 3585 | case DW_CFA_GNU_negative_offset_extended: | |||
| 3586 | reg = LEB (); | |||
| 3587 | l = - LEB (); | |||
| 3588 | frame_need_space (fc, reg); | |||
| 3589 | if (! do_debug_frames_interp) | |||
| 3590 | printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n", | |||
| 3591 | reg, l * fc->data_factor); | |||
| 3592 | fc->col_type[reg] = DW_CFA_offset; | |||
| 3593 | fc->col_offset[reg] = l * fc->data_factor; | |||
| 3594 | break; | |||
| 3595 | ||||
| 3596 | default: | |||
| 3597 | warn (_("unsupported or unknown DW_CFA_%d\n")("unsupported or unknown DW_CFA_%d\n"), op); | |||
| 3598 | start = block_end; | |||
| 3599 | } | |||
| 3600 | } | |||
| 3601 | ||||
| 3602 | if (do_debug_frames_interp) | |||
| 3603 | frame_display_row (fc, &need_col_headers, &max_regs); | |||
| 3604 | ||||
| 3605 | start = block_end; | |||
| 3606 | } | |||
| 3607 | ||||
| 3608 | printf ("\n"); | |||
| 3609 | ||||
| 3610 | return 1; | |||
| 3611 | } | |||
| 3612 | ||||
| 3613 | #undef GET | |||
| 3614 | #undef LEB | |||
| 3615 | #undef SLEB | |||
| 3616 | ||||
| 3617 | static int | |||
| 3618 | display_debug_not_supported (struct dwarf_section *section, | |||
| 3619 | void *file ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
| 3620 | { | |||
| 3621 | printf (_("Displaying the debug contents of section %s is not yet supported.\n")("Displaying the debug contents of section %s is not yet supported.\n" ), | |||
| 3622 | section->name); | |||
| 3623 | ||||
| 3624 | return 1; | |||
| 3625 | } | |||
| 3626 | ||||
| 3627 | void * | |||
| 3628 | cmalloc (size_t nmemb, size_t size) | |||
| 3629 | { | |||
| 3630 | /* Check for overflow. */ | |||
| 3631 | if (nmemb >= ~(size_t) 0 / size) | |||
| 3632 | return NULL((void*)0); | |||
| 3633 | else | |||
| 3634 | return malloc (nmemb * size); | |||
| 3635 | } | |||
| 3636 | ||||
| 3637 | void * | |||
| 3638 | xcmalloc (size_t nmemb, size_t size) | |||
| 3639 | { | |||
| 3640 | /* Check for overflow. */ | |||
| 3641 | if (nmemb >= ~(size_t) 0 / size) | |||
| 3642 | return NULL((void*)0); | |||
| 3643 | else | |||
| 3644 | return xmalloc (nmemb * size); | |||
| 3645 | } | |||
| 3646 | ||||
| 3647 | void * | |||
| 3648 | xcrealloc (void *ptr, size_t nmemb, size_t size) | |||
| 3649 | { | |||
| 3650 | /* Check for overflow. */ | |||
| 3651 | if (nmemb >= ~(size_t) 0 / size) | |||
| 3652 | return NULL((void*)0); | |||
| 3653 | else | |||
| 3654 | return xrealloc (ptr, nmemb * size); | |||
| 3655 | } | |||
| 3656 | ||||
| 3657 | void | |||
| 3658 | error (const char *message, ...) | |||
| 3659 | { | |||
| 3660 | va_list args; | |||
| 3661 | ||||
| 3662 | va_start (args, message)__builtin_va_start(args, message); | |||
| 3663 | fprintf (stderr(&__sF[2]), _("%s: Error: ")("%s: Error: "), program_name); | |||
| 3664 | vfprintf (stderr(&__sF[2]), message, args); | |||
| 3665 | va_end (args)__builtin_va_end(args); | |||
| 3666 | } | |||
| 3667 | ||||
| 3668 | void | |||
| 3669 | warn (const char *message, ...) | |||
| 3670 | { | |||
| 3671 | va_list args; | |||
| 3672 | ||||
| 3673 | va_start (args, message)__builtin_va_start(args, message); | |||
| 3674 | fprintf (stderr(&__sF[2]), _("%s: Warning: ")("%s: Warning: "), program_name); | |||
| 3675 | vfprintf (stderr(&__sF[2]), message, args); | |||
| 3676 | va_end (args)__builtin_va_end(args); | |||
| 3677 | } | |||
| 3678 | ||||
| 3679 | void | |||
| 3680 | free_debug_memory (void) | |||
| 3681 | { | |||
| 3682 | enum dwarf_section_display_enum i; | |||
| 3683 | ||||
| 3684 | free_abbrevs (); | |||
| 3685 | ||||
| 3686 | for (i = 0; i < max; i++) | |||
| 3687 | free_debug_section (i); | |||
| 3688 | ||||
| 3689 | if (debug_information) | |||
| 3690 | { | |||
| 3691 | for (i = 0; i < num_debug_info_entries; i++) | |||
| 3692 | { | |||
| 3693 | if (!debug_information [i].max_loc_offsets) | |||
| 3694 | { | |||
| 3695 | free (debug_information [i].loc_offsets); | |||
| 3696 | free (debug_information [i].have_frame_base); | |||
| 3697 | } | |||
| 3698 | if (!debug_information [i].max_range_lists) | |||
| 3699 | free (debug_information [i].range_lists); | |||
| 3700 | } | |||
| 3701 | free (debug_information); | |||
| 3702 | debug_information = NULL((void*)0); | |||
| 3703 | num_debug_info_entries = 0; | |||
| 3704 | } | |||
| 3705 | ||||
| 3706 | } | |||
| 3707 | ||||
| 3708 | struct dwarf_section_display debug_displays[] = | |||
| 3709 | { | |||
| 3710 | { { ".debug_abbrev", NULL((void*)0), 0, 0 }, | |||
| 3711 | display_debug_abbrev, 0, 0 }, | |||
| 3712 | { { ".debug_aranges", NULL((void*)0), 0, 0 }, | |||
| 3713 | display_debug_aranges, 0, 0 }, | |||
| 3714 | { { ".debug_frame", NULL((void*)0), 0, 0 }, | |||
| 3715 | display_debug_frames, 1, 0 }, | |||
| 3716 | { { ".debug_info", NULL((void*)0), 0, 0 }, | |||
| 3717 | display_debug_info, 1, 0 }, | |||
| 3718 | { { ".debug_line", NULL((void*)0), 0, 0 }, | |||
| 3719 | display_debug_lines, 0, 0 }, | |||
| 3720 | { { ".debug_pubnames", NULL((void*)0), 0, 0 }, | |||
| 3721 | display_debug_pubnames, 0, 0 }, | |||
| 3722 | { { ".eh_frame", NULL((void*)0), 0, 0 }, | |||
| 3723 | display_debug_frames, 1, 1 }, | |||
| 3724 | { { ".debug_macinfo", NULL((void*)0), 0, 0 }, | |||
| 3725 | display_debug_macinfo, 0, 0 }, | |||
| 3726 | { { ".debug_str", NULL((void*)0), 0, 0 }, | |||
| 3727 | display_debug_str, 0, 0 }, | |||
| 3728 | { { ".debug_loc", NULL((void*)0), 0, 0 }, | |||
| 3729 | display_debug_loc, 0, 0 }, | |||
| 3730 | { { ".debug_pubtypes", NULL((void*)0), 0, 0 }, | |||
| 3731 | display_debug_pubnames, 0, 0 }, | |||
| 3732 | { { ".debug_ranges", NULL((void*)0), 0, 0 }, | |||
| 3733 | display_debug_ranges, 0, 0 }, | |||
| 3734 | { { ".debug_static_func", NULL((void*)0), 0, 0 }, | |||
| 3735 | display_debug_not_supported, 0, 0 }, | |||
| 3736 | { { ".debug_static_vars", NULL((void*)0), 0, 0 }, | |||
| 3737 | display_debug_not_supported, 0, 0 }, | |||
| 3738 | { { ".debug_types", NULL((void*)0), 0, 0 }, | |||
| 3739 | display_debug_not_supported, 0, 0 }, | |||
| 3740 | { { ".debug_weaknames", NULL((void*)0), 0, 0 }, | |||
| 3741 | display_debug_not_supported, 0, 0 } | |||
| 3742 | }; |