| 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
| 2 | Copyright (C) 2005-2019 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GNU Binutils. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 19 | 02110-1301, USA. */ |
| 20 | |
| 21 | #include "sysdep.h" |
| 22 | #include "libiberty.h" |
| 23 | #include "bfd.h" |
| 24 | #include "bfd_stdint.h" |
| 25 | #include "bucomm.h" |
| 26 | #include "elfcomm.h" |
| 27 | #include "elf/common.h" |
| 28 | #include "dwarf2.h" |
| 29 | #include "dwarf.h" |
| 30 | #include "gdb/gdb-index.h" |
| 31 | #include "filenames.h" |
| 32 | #include "safe-ctype.h" |
| 33 | #include <assert.h> |
| 34 | |
| 35 | #undef MAX |
| 36 | #undef MIN |
| 37 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 38 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 39 | |
| 40 | static const char *regname (unsigned int regno, int row); |
| 41 | |
| 42 | static int have_frame_base; |
| 43 | static int need_base_address; |
| 44 | |
| 45 | static unsigned int num_debug_info_entries = 0; |
| 46 | static unsigned int alloc_num_debug_info_entries = 0; |
| 47 | static debug_info *debug_information = NULL; |
| 48 | /* Special value for num_debug_info_entries to indicate |
| 49 | that the .debug_info section could not be loaded/parsed. */ |
| 50 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 |
| 51 | |
| 52 | /* A .debug_info section can contain multiple links to separate |
| 53 | DWO object files. We use these structures to record these links. */ |
| 54 | typedef enum dwo_type |
| 55 | { |
| 56 | DWO_NAME, |
| 57 | DWO_DIR, |
| 58 | DWO_ID |
| 59 | } dwo_type; |
| 60 | |
| 61 | typedef struct dwo_info |
| 62 | { |
| 63 | dwo_type type; |
| 64 | const char * value; |
| 65 | struct dwo_info * next; |
| 66 | } dwo_info; |
| 67 | |
| 68 | static dwo_info * first_dwo_info = NULL; |
| 69 | static bfd_boolean need_dwo_info; |
| 70 | |
| 71 | separate_info * first_separate_info = NULL; |
| 72 | |
| 73 | unsigned int eh_addr_size; |
| 74 | |
| 75 | int do_debug_info; |
| 76 | int do_debug_abbrevs; |
| 77 | int do_debug_lines; |
| 78 | int do_debug_pubnames; |
| 79 | int do_debug_pubtypes; |
| 80 | int do_debug_aranges; |
| 81 | int do_debug_ranges; |
| 82 | int do_debug_frames; |
| 83 | int do_debug_frames_interp; |
| 84 | int do_debug_macinfo; |
| 85 | int do_debug_str; |
| 86 | int do_debug_loc; |
| 87 | int do_gdb_index; |
| 88 | int do_trace_info; |
| 89 | int do_trace_abbrevs; |
| 90 | int do_trace_aranges; |
| 91 | int do_debug_addr; |
| 92 | int do_debug_cu_index; |
| 93 | int do_wide; |
| 94 | int do_debug_links; |
| 95 | int do_follow_links; |
| 96 | |
| 97 | int dwarf_cutoff_level = -1; |
| 98 | unsigned long dwarf_start_die; |
| 99 | |
| 100 | int dwarf_check = 0; |
| 101 | |
| 102 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
| 103 | testing whether e.g. a locview list is present. */ |
| 104 | static const dwarf_vma vm1 = -1; |
| 105 | |
| 106 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
| 107 | sections. For version 1 package files, each set is stored in SHNDX_POOL |
| 108 | as a zero-terminated list of section indexes comprising one set of debug |
| 109 | sections from a .dwo file. */ |
| 110 | |
| 111 | static unsigned int *shndx_pool = NULL; |
| 112 | static unsigned int shndx_pool_size = 0; |
| 113 | static unsigned int shndx_pool_used = 0; |
| 114 | |
| 115 | /* For version 2 package files, each set contains an array of section offsets |
| 116 | and an array of section sizes, giving the offset and size of the |
| 117 | contribution from a CU or TU within one of the debug sections. |
| 118 | When displaying debug info from a package file, we need to use these |
| 119 | tables to locate the corresponding contributions to each section. */ |
| 120 | |
| 121 | struct cu_tu_set |
| 122 | { |
| 123 | uint64_t signature; |
| 124 | dwarf_vma section_offsets[DW_SECT_MAX]; |
| 125 | size_t section_sizes[DW_SECT_MAX]; |
| 126 | }; |
| 127 | |
| 128 | static int cu_count = 0; |
| 129 | static int tu_count = 0; |
| 130 | static struct cu_tu_set *cu_sets = NULL; |
| 131 | static struct cu_tu_set *tu_sets = NULL; |
| 132 | |
| 133 | static bfd_boolean load_cu_tu_indexes (void *); |
| 134 | |
| 135 | /* Values for do_debug_lines. */ |
| 136 | #define FLAG_DEBUG_LINES_RAW 1 |
| 137 | #define FLAG_DEBUG_LINES_DECODED 2 |
| 138 | |
| 139 | static unsigned int |
| 140 | size_of_encoded_value (int encoding) |
| 141 | { |
| 142 | switch (encoding & 0x7) |
| 143 | { |
| 144 | default: /* ??? */ |
| 145 | case 0: return eh_addr_size; |
| 146 | case 2: return 2; |
| 147 | case 3: return 4; |
| 148 | case 4: return 8; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | static dwarf_vma |
| 153 | get_encoded_value (unsigned char **pdata, |
| 154 | int encoding, |
| 155 | struct dwarf_section *section, |
| 156 | unsigned char * end) |
| 157 | { |
| 158 | unsigned char * data = * pdata; |
| 159 | unsigned int size = size_of_encoded_value (encoding); |
| 160 | dwarf_vma val; |
| 161 | |
| 162 | if (data + size >= end) |
| 163 | { |
| 164 | warn (_("Encoded value extends past end of section\n")); |
| 165 | * pdata = end; |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /* PR 17512: file: 002-829853-0.004. */ |
| 170 | if (size > 8) |
| 171 | { |
| 172 | warn (_("Encoded size of %d is too large to read\n"), size); |
| 173 | * pdata = end; |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /* PR 17512: file: 1085-5603-0.004. */ |
| 178 | if (size == 0) |
| 179 | { |
| 180 | warn (_("Encoded size of 0 is too small to read\n")); |
| 181 | * pdata = end; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | if (encoding & DW_EH_PE_signed) |
| 186 | val = byte_get_signed (data, size); |
| 187 | else |
| 188 | val = byte_get (data, size); |
| 189 | |
| 190 | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| 191 | val += section->address + (data - section->start); |
| 192 | |
| 193 | * pdata = data + size; |
| 194 | return val; |
| 195 | } |
| 196 | |
| 197 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
| 198 | # ifndef __MINGW32__ |
| 199 | # define DWARF_VMA_FMT "ll" |
| 200 | # define DWARF_VMA_FMT_LONG "%16.16llx" |
| 201 | # else |
| 202 | # define DWARF_VMA_FMT "I64" |
| 203 | # define DWARF_VMA_FMT_LONG "%016I64x" |
| 204 | # endif |
| 205 | #else |
| 206 | # define DWARF_VMA_FMT "l" |
| 207 | # define DWARF_VMA_FMT_LONG "%16.16lx" |
| 208 | #endif |
| 209 | |
| 210 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
| 211 | buffer containing the converted VALUE. The value is converted according |
| 212 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then |
| 213 | it specifies the maximum number of bytes to be displayed in the converted |
| 214 | value and FMTCH is ignored - hex is always used. */ |
| 215 | |
| 216 | static const char * |
| 217 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
| 218 | { |
| 219 | /* As dwarf_vmatoa is used more then once in a printf call |
| 220 | for output, we are cycling through an fixed array of pointers |
| 221 | for return address. */ |
| 222 | static int buf_pos = 0; |
| 223 | static struct dwarf_vmatoa_buf |
| 224 | { |
| 225 | char place[64]; |
| 226 | } buf[16]; |
| 227 | char *ret; |
| 228 | |
| 229 | ret = buf[buf_pos++].place; |
| 230 | buf_pos %= ARRAY_SIZE (buf); |
| 231 | |
| 232 | if (num_bytes) |
| 233 | { |
| 234 | /* Printf does not have a way of specifying a maximum field width for an |
| 235 | integer value, so we print the full value into a buffer and then select |
| 236 | the precision we need. */ |
| 237 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); |
| 238 | if (num_bytes > 8) |
| 239 | num_bytes = 8; |
| 240 | return ret + (16 - 2 * num_bytes); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | char fmt[32]; |
| 245 | |
| 246 | if (fmtch) |
| 247 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); |
| 248 | else |
| 249 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); |
| 250 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
| 251 | return ret; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static inline const char * |
| 256 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) |
| 257 | { |
| 258 | return dwarf_vmatoa_1 (fmtch, value, 0); |
| 259 | } |
| 260 | |
| 261 | /* Print a dwarf_vma value (typically an address, offset or length) in |
| 262 | hexadecimal format, followed by a space. The length of the VALUE (and |
| 263 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ |
| 264 | |
| 265 | static void |
| 266 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) |
| 267 | { |
| 268 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); |
| 269 | } |
| 270 | |
| 271 | /* Print a view number in hexadecimal value, with the same width |
| 272 | print_dwarf_vma would have printed it with the same num_bytes. |
| 273 | Print blanks for zero view, unless force is nonzero. */ |
| 274 | |
| 275 | static void |
| 276 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) |
| 277 | { |
| 278 | int len; |
| 279 | if (!num_bytes) |
| 280 | len = 4; |
| 281 | else |
| 282 | len = num_bytes * 2; |
| 283 | |
| 284 | assert (value == (unsigned long) value); |
| 285 | if (value || force) |
| 286 | printf ("v%0*lx ", len - 1, (unsigned long) value); |
| 287 | else |
| 288 | printf ("%*s", len + 1, ""); |
| 289 | } |
| 290 | |
| 291 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
| 292 | For reentrancy, this uses a buffer provided by the caller. */ |
| 293 | |
| 294 | static const char * |
| 295 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, |
| 296 | unsigned int buf_len) |
| 297 | { |
| 298 | int len = 0; |
| 299 | |
| 300 | if (hvalue == 0) |
| 301 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); |
| 302 | else |
| 303 | { |
| 304 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); |
| 305 | snprintf (buf + len, buf_len - len, |
| 306 | "%08" DWARF_VMA_FMT "x", lvalue); |
| 307 | } |
| 308 | |
| 309 | return buf; |
| 310 | } |
| 311 | |
| 312 | /* Read in a LEB128 encoded value starting at address DATA. |
| 313 | If SIGN is true, return a signed LEB128 value. |
| 314 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. |
| 315 | No bytes will be read at address END or beyond. */ |
| 316 | |
| 317 | dwarf_vma |
| 318 | read_leb128 (unsigned char *data, |
| 319 | unsigned int *length_return, |
| 320 | bfd_boolean sign, |
| 321 | const unsigned char * const end) |
| 322 | { |
| 323 | dwarf_vma result = 0; |
| 324 | unsigned int num_read = 0; |
| 325 | unsigned int shift = 0; |
| 326 | unsigned char byte = 0; |
| 327 | |
| 328 | while (data < end) |
| 329 | { |
| 330 | byte = *data++; |
| 331 | num_read++; |
| 332 | |
| 333 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
| 334 | |
| 335 | shift += 7; |
| 336 | if ((byte & 0x80) == 0) |
| 337 | break; |
| 338 | |
| 339 | /* PR 17512: file: 0ca183b8. |
| 340 | FIXME: Should we signal this error somehow ? */ |
| 341 | if (shift >= sizeof (result) * 8) |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | if (length_return != NULL) |
| 346 | *length_return = num_read; |
| 347 | |
| 348 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) |
| 349 | result |= -((dwarf_vma) 1 << shift); |
| 350 | |
| 351 | return result; |
| 352 | } |
| 353 | |
| 354 | /* Create a signed version to avoid painful typecasts. */ |
| 355 | static inline dwarf_signed_vma |
| 356 | read_sleb128 (unsigned char * data, |
| 357 | unsigned int * length_return, |
| 358 | const unsigned char * const end) |
| 359 | { |
| 360 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); |
| 361 | } |
| 362 | |
| 363 | static inline dwarf_vma |
| 364 | read_uleb128 (unsigned char * data, |
| 365 | unsigned int * length_return, |
| 366 | const unsigned char * const end) |
| 367 | { |
| 368 | return read_leb128 (data, length_return, FALSE, end); |
| 369 | } |
| 370 | |
| 371 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
| 372 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return |
| 373 | |
| 374 | #define READ_ULEB(var) \ |
| 375 | do \ |
| 376 | { \ |
| 377 | dwarf_vma _val; \ |
| 378 | \ |
| 379 | (var) = _val = read_uleb128 (start, &length_return, end); \ |
| 380 | if ((var) != _val) \ |
| 381 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
| 382 | "too large for containing variable\n"), \ |
| 383 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ |
| 384 | start += length_return; \ |
| 385 | } \ |
| 386 | while (0) |
| 387 | |
| 388 | #define READ_SLEB(var) \ |
| 389 | do \ |
| 390 | { \ |
| 391 | dwarf_signed_vma _val; \ |
| 392 | \ |
| 393 | (var) = _val = read_sleb128 (start, &length_return, end); \ |
| 394 | if ((var) != _val) \ |
| 395 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
| 396 | "too large for containing variable\n"), \ |
| 397 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ |
| 398 | start += length_return; \ |
| 399 | } \ |
| 400 | while (0) |
| 401 | |
| 402 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
| 403 | Checks to make sure that the read will not reach or pass END |
| 404 | and that VAL is big enough to hold AMOUNT bytes. */ |
| 405 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| 406 | do \ |
| 407 | { \ |
| 408 | unsigned int amount = (AMOUNT); \ |
| 409 | if (sizeof (VAL) < amount) \ |
| 410 | { \ |
| 411 | error (ngettext ("internal error: attempt to read %d byte " \ |
| 412 | "of data in to %d sized variable", \ |
| 413 | "internal error: attempt to read %d bytes " \ |
| 414 | "of data in to %d sized variable", \ |
| 415 | amount), \ |
| 416 | amount, (int) sizeof (VAL)); \ |
| 417 | amount = sizeof (VAL); \ |
| 418 | } \ |
| 419 | if (((PTR) + amount) >= (END)) \ |
| 420 | { \ |
| 421 | if ((PTR) < (END)) \ |
| 422 | amount = (END) - (PTR); \ |
| 423 | else \ |
| 424 | amount = 0; \ |
| 425 | } \ |
| 426 | if (amount == 0 || amount > 8) \ |
| 427 | VAL = 0; \ |
| 428 | else \ |
| 429 | VAL = byte_get ((PTR), amount); \ |
| 430 | } \ |
| 431 | while (0) |
| 432 | |
| 433 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
| 434 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| 435 | do \ |
| 436 | { \ |
| 437 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ |
| 438 | PTR += AMOUNT; \ |
| 439 | } \ |
| 440 | while (0) |
| 441 | |
| 442 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
| 443 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| 444 | do \ |
| 445 | { \ |
| 446 | unsigned int amount = (AMOUNT); \ |
| 447 | if (((PTR) + amount) >= (END)) \ |
| 448 | { \ |
| 449 | if ((PTR) < (END)) \ |
| 450 | amount = (END) - (PTR); \ |
| 451 | else \ |
| 452 | amount = 0; \ |
| 453 | } \ |
| 454 | if (amount) \ |
| 455 | VAL = byte_get_signed ((PTR), amount); \ |
| 456 | else \ |
| 457 | VAL = 0; \ |
| 458 | } \ |
| 459 | while (0) |
| 460 | |
| 461 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
| 462 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| 463 | do \ |
| 464 | { \ |
| 465 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ |
| 466 | PTR += AMOUNT; \ |
| 467 | } \ |
| 468 | while (0) |
| 469 | |
| 470 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ |
| 471 | do \ |
| 472 | { \ |
| 473 | if (((PTR) + 8) <= (END)) \ |
| 474 | { \ |
| 475 | byte_get_64 ((PTR), (HIGH), (LOW)); \ |
| 476 | } \ |
| 477 | else \ |
| 478 | { \ |
| 479 | * (LOW) = * (HIGH) = 0; \ |
| 480 | } \ |
| 481 | } \ |
| 482 | while (0) |
| 483 | |
| 484 | typedef struct State_Machine_Registers |
| 485 | { |
| 486 | dwarf_vma address; |
| 487 | unsigned int view; |
| 488 | unsigned int file; |
| 489 | unsigned int line; |
| 490 | unsigned int column; |
| 491 | int is_stmt; |
| 492 | int basic_block; |
| 493 | unsigned char op_index; |
| 494 | unsigned char end_sequence; |
| 495 | /* This variable hold the number of the last entry seen |
| 496 | in the File Table. */ |
| 497 | unsigned int last_file_entry; |
| 498 | } SMR; |
| 499 | |
| 500 | static SMR state_machine_regs; |
| 501 | |
| 502 | static void |
| 503 | reset_state_machine (int is_stmt) |
| 504 | { |
| 505 | state_machine_regs.address = 0; |
| 506 | state_machine_regs.view = 0; |
| 507 | state_machine_regs.op_index = 0; |
| 508 | state_machine_regs.file = 1; |
| 509 | state_machine_regs.line = 1; |
| 510 | state_machine_regs.column = 0; |
| 511 | state_machine_regs.is_stmt = is_stmt; |
| 512 | state_machine_regs.basic_block = 0; |
| 513 | state_machine_regs.end_sequence = 0; |
| 514 | state_machine_regs.last_file_entry = 0; |
| 515 | } |
| 516 | |
| 517 | /* Handled an extend line op. |
| 518 | Returns the number of bytes read. */ |
| 519 | |
| 520 | static int |
| 521 | process_extended_line_op (unsigned char * data, |
| 522 | int is_stmt, |
| 523 | unsigned char * end) |
| 524 | { |
| 525 | unsigned char op_code; |
| 526 | unsigned int bytes_read; |
| 527 | unsigned int len; |
| 528 | unsigned char *name; |
| 529 | unsigned char *orig_data = data; |
| 530 | dwarf_vma adr; |
| 531 | |
| 532 | len = read_uleb128 (data, & bytes_read, end); |
| 533 | data += bytes_read; |
| 534 | |
| 535 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
| 536 | { |
| 537 | warn (_("Badly formed extended line op encountered!\n")); |
| 538 | return bytes_read; |
| 539 | } |
| 540 | |
| 541 | len += bytes_read; |
| 542 | op_code = *data++; |
| 543 | |
| 544 | printf (_(" Extended opcode %d: "), op_code); |
| 545 | |
| 546 | switch (op_code) |
| 547 | { |
| 548 | case DW_LNE_end_sequence: |
| 549 | printf (_("End of Sequence\n\n")); |
| 550 | reset_state_machine (is_stmt); |
| 551 | break; |
| 552 | |
| 553 | case DW_LNE_set_address: |
| 554 | /* PR 17512: file: 002-100480-0.004. */ |
| 555 | if (len - bytes_read - 1 > 8) |
| 556 | { |
| 557 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), |
| 558 | len - bytes_read - 1); |
| 559 | adr = 0; |
| 560 | } |
| 561 | else |
| 562 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); |
| 563 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
| 564 | state_machine_regs.address = adr; |
| 565 | state_machine_regs.view = 0; |
| 566 | state_machine_regs.op_index = 0; |
| 567 | break; |
| 568 | |
| 569 | case DW_LNE_define_file: |
| 570 | printf (_("define new File Table entry\n")); |
| 571 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
| 572 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
| 573 | |
| 574 | { |
| 575 | size_t l; |
| 576 | |
| 577 | name = data; |
| 578 | l = strnlen ((char *) data, end - data); |
| 579 | data += len + 1; |
| 580 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 581 | data += bytes_read; |
| 582 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 583 | data += bytes_read; |
| 584 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 585 | data += bytes_read; |
| 586 | printf ("%.*s\n\n", (int) l, name); |
| 587 | } |
| 588 | |
| 589 | if (((unsigned int) (data - orig_data) != len) || data == end) |
| 590 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
| 591 | break; |
| 592 | |
| 593 | case DW_LNE_set_discriminator: |
| 594 | printf (_("set Discriminator to %s\n"), |
| 595 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 596 | break; |
| 597 | |
| 598 | /* HP extensions. */ |
| 599 | case DW_LNE_HP_negate_is_UV_update: |
| 600 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
| 601 | break; |
| 602 | case DW_LNE_HP_push_context: |
| 603 | printf ("DW_LNE_HP_push_context\n"); |
| 604 | break; |
| 605 | case DW_LNE_HP_pop_context: |
| 606 | printf ("DW_LNE_HP_pop_context\n"); |
| 607 | break; |
| 608 | case DW_LNE_HP_set_file_line_column: |
| 609 | printf ("DW_LNE_HP_set_file_line_column\n"); |
| 610 | break; |
| 611 | case DW_LNE_HP_set_routine_name: |
| 612 | printf ("DW_LNE_HP_set_routine_name\n"); |
| 613 | break; |
| 614 | case DW_LNE_HP_set_sequence: |
| 615 | printf ("DW_LNE_HP_set_sequence\n"); |
| 616 | break; |
| 617 | case DW_LNE_HP_negate_post_semantics: |
| 618 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
| 619 | break; |
| 620 | case DW_LNE_HP_negate_function_exit: |
| 621 | printf ("DW_LNE_HP_negate_function_exit\n"); |
| 622 | break; |
| 623 | case DW_LNE_HP_negate_front_end_logical: |
| 624 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
| 625 | break; |
| 626 | case DW_LNE_HP_define_proc: |
| 627 | printf ("DW_LNE_HP_define_proc\n"); |
| 628 | break; |
| 629 | case DW_LNE_HP_source_file_correlation: |
| 630 | { |
| 631 | unsigned char *edata = data + len - bytes_read - 1; |
| 632 | |
| 633 | printf ("DW_LNE_HP_source_file_correlation\n"); |
| 634 | |
| 635 | while (data < edata) |
| 636 | { |
| 637 | unsigned int opc; |
| 638 | |
| 639 | opc = read_uleb128 (data, & bytes_read, edata); |
| 640 | data += bytes_read; |
| 641 | |
| 642 | switch (opc) |
| 643 | { |
| 644 | case DW_LNE_HP_SFC_formfeed: |
| 645 | printf (" DW_LNE_HP_SFC_formfeed\n"); |
| 646 | break; |
| 647 | case DW_LNE_HP_SFC_set_listing_line: |
| 648 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
| 649 | dwarf_vmatoa ("u", |
| 650 | read_uleb128 (data, & bytes_read, edata))); |
| 651 | data += bytes_read; |
| 652 | break; |
| 653 | case DW_LNE_HP_SFC_associate: |
| 654 | printf (" DW_LNE_HP_SFC_associate "); |
| 655 | printf ("(%s", |
| 656 | dwarf_vmatoa ("u", |
| 657 | read_uleb128 (data, & bytes_read, edata))); |
| 658 | data += bytes_read; |
| 659 | printf (",%s", |
| 660 | dwarf_vmatoa ("u", |
| 661 | read_uleb128 (data, & bytes_read, edata))); |
| 662 | data += bytes_read; |
| 663 | printf (",%s)\n", |
| 664 | dwarf_vmatoa ("u", |
| 665 | read_uleb128 (data, & bytes_read, edata))); |
| 666 | data += bytes_read; |
| 667 | break; |
| 668 | default: |
| 669 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
| 670 | data = edata; |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | break; |
| 676 | |
| 677 | default: |
| 678 | { |
| 679 | unsigned int rlen = len - bytes_read - 1; |
| 680 | |
| 681 | if (op_code >= DW_LNE_lo_user |
| 682 | /* The test against DW_LNW_hi_user is redundant due to |
| 683 | the limited range of the unsigned char data type used |
| 684 | for op_code. */ |
| 685 | /*&& op_code <= DW_LNE_hi_user*/) |
| 686 | printf (_("user defined: ")); |
| 687 | else |
| 688 | printf (_("UNKNOWN: ")); |
| 689 | printf (_("length %d ["), rlen); |
| 690 | for (; rlen; rlen--) |
| 691 | printf (" %02x", *data++); |
| 692 | printf ("]\n"); |
| 693 | } |
| 694 | break; |
| 695 | } |
| 696 | |
| 697 | return len; |
| 698 | } |
| 699 | |
| 700 | static const unsigned char * |
| 701 | fetch_indirect_string (dwarf_vma offset) |
| 702 | { |
| 703 | struct dwarf_section *section = &debug_displays [str].section; |
| 704 | const unsigned char * ret; |
| 705 | |
| 706 | if (section->start == NULL) |
| 707 | return (const unsigned char *) _("<no .debug_str section>"); |
| 708 | |
| 709 | if (offset >= section->size) |
| 710 | { |
| 711 | warn (_("DW_FORM_strp offset too big: %s\n"), |
| 712 | dwarf_vmatoa ("x", offset)); |
| 713 | return (const unsigned char *) _("<offset is too big>"); |
| 714 | } |
| 715 | |
| 716 | ret = section->start + offset; |
| 717 | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
| 718 | NUL byte. Since our caller is expecting to receive a well formed C |
| 719 | string we test for the lack of a terminating byte here. */ |
| 720 | if (strnlen ((const char *) ret, section->size - offset) |
| 721 | == section->size - offset) |
| 722 | ret = (const unsigned char *) |
| 723 | _("<no NUL byte at end of .debug_str section>"); |
| 724 | |
| 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | static const unsigned char * |
| 729 | fetch_indirect_line_string (dwarf_vma offset) |
| 730 | { |
| 731 | struct dwarf_section *section = &debug_displays [line_str].section; |
| 732 | const unsigned char * ret; |
| 733 | |
| 734 | if (section->start == NULL) |
| 735 | return (const unsigned char *) _("<no .debug_line_str section>"); |
| 736 | |
| 737 | if (offset >= section->size) |
| 738 | { |
| 739 | warn (_("DW_FORM_line_strp offset too big: %s\n"), |
| 740 | dwarf_vmatoa ("x", offset)); |
| 741 | return (const unsigned char *) _("<offset is too big>"); |
| 742 | } |
| 743 | |
| 744 | ret = section->start + offset; |
| 745 | /* Unfortunately we cannot rely upon the .debug_line_str section ending |
| 746 | with a NUL byte. Since our caller is expecting to receive a well formed |
| 747 | C string we test for the lack of a terminating byte here. */ |
| 748 | if (strnlen ((const char *) ret, section->size - offset) |
| 749 | == section->size - offset) |
| 750 | ret = (const unsigned char *) |
| 751 | _("<no NUL byte at end of .debug_line_str section>"); |
| 752 | |
| 753 | return ret; |
| 754 | } |
| 755 | |
| 756 | static const char * |
| 757 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
| 758 | dwarf_vma offset_size, bfd_boolean dwo) |
| 759 | { |
| 760 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; |
| 761 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; |
| 762 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; |
| 763 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; |
| 764 | dwarf_vma index_offset = idx * offset_size; |
| 765 | dwarf_vma str_offset; |
| 766 | const char * ret; |
| 767 | |
| 768 | if (index_section->start == NULL) |
| 769 | return (dwo ? _("<no .debug_str_offsets.dwo section>") |
| 770 | : _("<no .debug_str_offsets section>")); |
| 771 | |
| 772 | if (this_set != NULL) |
| 773 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; |
| 774 | if (index_offset >= index_section->size) |
| 775 | { |
| 776 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), |
| 777 | dwarf_vmatoa ("x", index_offset)); |
| 778 | return _("<index offset is too big>"); |
| 779 | } |
| 780 | |
| 781 | if (str_section->start == NULL) |
| 782 | return (dwo ? _("<no .debug_str.dwo section>") |
| 783 | : _("<no .debug_str section>")); |
| 784 | |
| 785 | str_offset = byte_get (index_section->start + index_offset, offset_size); |
| 786 | str_offset -= str_section->address; |
| 787 | if (str_offset >= str_section->size) |
| 788 | { |
| 789 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), |
| 790 | dwarf_vmatoa ("x", str_offset)); |
| 791 | return _("<indirect index offset is too big>"); |
| 792 | } |
| 793 | |
| 794 | ret = (const char *) str_section->start + str_offset; |
| 795 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. |
| 796 | Since our caller is expecting to receive a well formed C string we test |
| 797 | for the lack of a terminating byte here. */ |
| 798 | if (strnlen (ret, str_section->size - str_offset) |
| 799 | == str_section->size - str_offset) |
| 800 | ret = (const char *) _("<no NUL byte at end of section>"); |
| 801 | |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static const char * |
| 806 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) |
| 807 | { |
| 808 | struct dwarf_section *section = &debug_displays [debug_addr].section; |
| 809 | |
| 810 | if (section->start == NULL) |
| 811 | return (_("<no .debug_addr section>")); |
| 812 | |
| 813 | if (offset + bytes > section->size) |
| 814 | { |
| 815 | warn (_("Offset into section %s too big: %s\n"), |
| 816 | section->name, dwarf_vmatoa ("x", offset)); |
| 817 | return "<offset too big>"; |
| 818 | } |
| 819 | |
| 820 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | /* FIXME: There are better and more efficient ways to handle |
| 825 | these structures. For now though, I just want something that |
| 826 | is simple to implement. */ |
| 827 | typedef struct abbrev_attr |
| 828 | { |
| 829 | unsigned long attribute; |
| 830 | unsigned long form; |
| 831 | bfd_signed_vma implicit_const; |
| 832 | struct abbrev_attr *next; |
| 833 | } |
| 834 | abbrev_attr; |
| 835 | |
| 836 | typedef struct abbrev_entry |
| 837 | { |
| 838 | unsigned long entry; |
| 839 | unsigned long tag; |
| 840 | int children; |
| 841 | struct abbrev_attr *first_attr; |
| 842 | struct abbrev_attr *last_attr; |
| 843 | struct abbrev_entry *next; |
| 844 | } |
| 845 | abbrev_entry; |
| 846 | |
| 847 | static abbrev_entry *first_abbrev = NULL; |
| 848 | static abbrev_entry *last_abbrev = NULL; |
| 849 | |
| 850 | static void |
| 851 | free_abbrevs (void) |
| 852 | { |
| 853 | abbrev_entry *abbrv; |
| 854 | |
| 855 | for (abbrv = first_abbrev; abbrv;) |
| 856 | { |
| 857 | abbrev_entry *next_abbrev = abbrv->next; |
| 858 | abbrev_attr *attr; |
| 859 | |
| 860 | for (attr = abbrv->first_attr; attr;) |
| 861 | { |
| 862 | abbrev_attr *next_attr = attr->next; |
| 863 | |
| 864 | free (attr); |
| 865 | attr = next_attr; |
| 866 | } |
| 867 | |
| 868 | free (abbrv); |
| 869 | abbrv = next_abbrev; |
| 870 | } |
| 871 | |
| 872 | last_abbrev = first_abbrev = NULL; |
| 873 | } |
| 874 | |
| 875 | static void |
| 876 | add_abbrev (unsigned long number, unsigned long tag, int children) |
| 877 | { |
| 878 | abbrev_entry *entry; |
| 879 | |
| 880 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
| 881 | if (entry == NULL) |
| 882 | /* ugg */ |
| 883 | return; |
| 884 | |
| 885 | entry->entry = number; |
| 886 | entry->tag = tag; |
| 887 | entry->children = children; |
| 888 | entry->first_attr = NULL; |
| 889 | entry->last_attr = NULL; |
| 890 | entry->next = NULL; |
| 891 | |
| 892 | if (first_abbrev == NULL) |
| 893 | first_abbrev = entry; |
| 894 | else |
| 895 | last_abbrev->next = entry; |
| 896 | |
| 897 | last_abbrev = entry; |
| 898 | } |
| 899 | |
| 900 | static void |
| 901 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
| 902 | bfd_signed_vma implicit_const) |
| 903 | { |
| 904 | abbrev_attr *attr; |
| 905 | |
| 906 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
| 907 | if (attr == NULL) |
| 908 | /* ugg */ |
| 909 | return; |
| 910 | |
| 911 | attr->attribute = attribute; |
| 912 | attr->form = form; |
| 913 | attr->implicit_const = implicit_const; |
| 914 | attr->next = NULL; |
| 915 | |
| 916 | if (last_abbrev->first_attr == NULL) |
| 917 | last_abbrev->first_attr = attr; |
| 918 | else |
| 919 | last_abbrev->last_attr->next = attr; |
| 920 | |
| 921 | last_abbrev->last_attr = attr; |
| 922 | } |
| 923 | |
| 924 | /* Processes the (partial) contents of a .debug_abbrev section. |
| 925 | Returns NULL if the end of the section was encountered. |
| 926 | Returns the address after the last byte read if the end of |
| 927 | an abbreviation set was found. */ |
| 928 | |
| 929 | static unsigned char * |
| 930 | process_abbrev_section (unsigned char *start, unsigned char *end) |
| 931 | { |
| 932 | if (first_abbrev != NULL) |
| 933 | return NULL; |
| 934 | |
| 935 | while (start < end) |
| 936 | { |
| 937 | unsigned int bytes_read; |
| 938 | unsigned long entry; |
| 939 | unsigned long tag; |
| 940 | unsigned long attribute; |
| 941 | int children; |
| 942 | |
| 943 | entry = read_uleb128 (start, & bytes_read, end); |
| 944 | start += bytes_read; |
| 945 | |
| 946 | /* A single zero is supposed to end the section according |
| 947 | to the standard. If there's more, then signal that to |
| 948 | the caller. */ |
| 949 | if (start == end) |
| 950 | return NULL; |
| 951 | if (entry == 0) |
| 952 | return start; |
| 953 | |
| 954 | tag = read_uleb128 (start, & bytes_read, end); |
| 955 | start += bytes_read; |
| 956 | if (start == end) |
| 957 | return NULL; |
| 958 | |
| 959 | children = *start++; |
| 960 | |
| 961 | add_abbrev (entry, tag, children); |
| 962 | |
| 963 | do |
| 964 | { |
| 965 | unsigned long form; |
| 966 | /* Initialize it due to a false compiler warning. */ |
| 967 | bfd_signed_vma implicit_const = -1; |
| 968 | |
| 969 | attribute = read_uleb128 (start, & bytes_read, end); |
| 970 | start += bytes_read; |
| 971 | if (start == end) |
| 972 | break; |
| 973 | |
| 974 | form = read_uleb128 (start, & bytes_read, end); |
| 975 | start += bytes_read; |
| 976 | if (start == end) |
| 977 | break; |
| 978 | |
| 979 | if (form == DW_FORM_implicit_const) |
| 980 | { |
| 981 | implicit_const = read_sleb128 (start, & bytes_read, end); |
| 982 | start += bytes_read; |
| 983 | if (start == end) |
| 984 | break; |
| 985 | } |
| 986 | |
| 987 | add_abbrev_attr (attribute, form, implicit_const); |
| 988 | } |
| 989 | while (attribute != 0); |
| 990 | } |
| 991 | |
| 992 | /* Report the missing single zero which ends the section. */ |
| 993 | error (_(".debug_abbrev section not zero terminated\n")); |
| 994 | |
| 995 | return NULL; |
| 996 | } |
| 997 | |
| 998 | static const char * |
| 999 | get_TAG_name (unsigned long tag) |
| 1000 | { |
| 1001 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
| 1002 | |
| 1003 | if (name == NULL) |
| 1004 | { |
| 1005 | static char buffer[100]; |
| 1006 | |
| 1007 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
| 1008 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); |
| 1009 | else |
| 1010 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); |
| 1011 | return buffer; |
| 1012 | } |
| 1013 | |
| 1014 | return name; |
| 1015 | } |
| 1016 | |
| 1017 | static const char * |
| 1018 | get_FORM_name (unsigned long form) |
| 1019 | { |
| 1020 | const char *name; |
| 1021 | |
| 1022 | if (form == 0) |
| 1023 | return "DW_FORM value: 0"; |
| 1024 | |
| 1025 | name = get_DW_FORM_name (form); |
| 1026 | if (name == NULL) |
| 1027 | { |
| 1028 | static char buffer[100]; |
| 1029 | |
| 1030 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
| 1031 | return buffer; |
| 1032 | } |
| 1033 | |
| 1034 | return name; |
| 1035 | } |
| 1036 | |
| 1037 | static const char * |
| 1038 | get_IDX_name (unsigned long idx) |
| 1039 | { |
| 1040 | const char *name = get_DW_IDX_name ((unsigned int) idx); |
| 1041 | |
| 1042 | if (name == NULL) |
| 1043 | { |
| 1044 | static char buffer[100]; |
| 1045 | |
| 1046 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); |
| 1047 | return buffer; |
| 1048 | } |
| 1049 | |
| 1050 | return name; |
| 1051 | } |
| 1052 | |
| 1053 | static unsigned char * |
| 1054 | display_block (unsigned char *data, |
| 1055 | dwarf_vma length, |
| 1056 | const unsigned char * const end, char delimiter) |
| 1057 | { |
| 1058 | dwarf_vma maxlen; |
| 1059 | |
| 1060 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
| 1061 | if (data > end) |
| 1062 | return (unsigned char *) end; |
| 1063 | |
| 1064 | maxlen = (dwarf_vma) (end - data); |
| 1065 | length = length > maxlen ? maxlen : length; |
| 1066 | |
| 1067 | while (length --) |
| 1068 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); |
| 1069 | |
| 1070 | return data; |
| 1071 | } |
| 1072 | |
| 1073 | static int |
| 1074 | decode_location_expression (unsigned char * data, |
| 1075 | unsigned int pointer_size, |
| 1076 | unsigned int offset_size, |
| 1077 | int dwarf_version, |
| 1078 | dwarf_vma length, |
| 1079 | dwarf_vma cu_offset, |
| 1080 | struct dwarf_section * section) |
| 1081 | { |
| 1082 | unsigned op; |
| 1083 | unsigned int bytes_read; |
| 1084 | dwarf_vma uvalue; |
| 1085 | dwarf_signed_vma svalue; |
| 1086 | unsigned char *end = data + length; |
| 1087 | int need_frame_base = 0; |
| 1088 | |
| 1089 | while (data < end) |
| 1090 | { |
| 1091 | op = *data++; |
| 1092 | |
| 1093 | switch (op) |
| 1094 | { |
| 1095 | case DW_OP_addr: |
| 1096 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1097 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); |
| 1098 | break; |
| 1099 | case DW_OP_deref: |
| 1100 | printf ("DW_OP_deref"); |
| 1101 | break; |
| 1102 | case DW_OP_const1u: |
| 1103 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1104 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); |
| 1105 | break; |
| 1106 | case DW_OP_const1s: |
| 1107 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
| 1108 | printf ("DW_OP_const1s: %ld", (long) svalue); |
| 1109 | break; |
| 1110 | case DW_OP_const2u: |
| 1111 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| 1112 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
| 1113 | break; |
| 1114 | case DW_OP_const2s: |
| 1115 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| 1116 | printf ("DW_OP_const2s: %ld", (long) svalue); |
| 1117 | break; |
| 1118 | case DW_OP_const4u: |
| 1119 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| 1120 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); |
| 1121 | break; |
| 1122 | case DW_OP_const4s: |
| 1123 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| 1124 | printf ("DW_OP_const4s: %ld", (long) svalue); |
| 1125 | break; |
| 1126 | case DW_OP_const8u: |
| 1127 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| 1128 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); |
| 1129 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| 1130 | printf ("%lu", (unsigned long) uvalue); |
| 1131 | break; |
| 1132 | case DW_OP_const8s: |
| 1133 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| 1134 | printf ("DW_OP_const8s: %ld ", (long) svalue); |
| 1135 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| 1136 | printf ("%ld", (long) svalue); |
| 1137 | break; |
| 1138 | case DW_OP_constu: |
| 1139 | printf ("DW_OP_constu: %s", |
| 1140 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| 1141 | data += bytes_read; |
| 1142 | break; |
| 1143 | case DW_OP_consts: |
| 1144 | printf ("DW_OP_consts: %s", |
| 1145 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| 1146 | data += bytes_read; |
| 1147 | break; |
| 1148 | case DW_OP_dup: |
| 1149 | printf ("DW_OP_dup"); |
| 1150 | break; |
| 1151 | case DW_OP_drop: |
| 1152 | printf ("DW_OP_drop"); |
| 1153 | break; |
| 1154 | case DW_OP_over: |
| 1155 | printf ("DW_OP_over"); |
| 1156 | break; |
| 1157 | case DW_OP_pick: |
| 1158 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1159 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); |
| 1160 | break; |
| 1161 | case DW_OP_swap: |
| 1162 | printf ("DW_OP_swap"); |
| 1163 | break; |
| 1164 | case DW_OP_rot: |
| 1165 | printf ("DW_OP_rot"); |
| 1166 | break; |
| 1167 | case DW_OP_xderef: |
| 1168 | printf ("DW_OP_xderef"); |
| 1169 | break; |
| 1170 | case DW_OP_abs: |
| 1171 | printf ("DW_OP_abs"); |
| 1172 | break; |
| 1173 | case DW_OP_and: |
| 1174 | printf ("DW_OP_and"); |
| 1175 | break; |
| 1176 | case DW_OP_div: |
| 1177 | printf ("DW_OP_div"); |
| 1178 | break; |
| 1179 | case DW_OP_minus: |
| 1180 | printf ("DW_OP_minus"); |
| 1181 | break; |
| 1182 | case DW_OP_mod: |
| 1183 | printf ("DW_OP_mod"); |
| 1184 | break; |
| 1185 | case DW_OP_mul: |
| 1186 | printf ("DW_OP_mul"); |
| 1187 | break; |
| 1188 | case DW_OP_neg: |
| 1189 | printf ("DW_OP_neg"); |
| 1190 | break; |
| 1191 | case DW_OP_not: |
| 1192 | printf ("DW_OP_not"); |
| 1193 | break; |
| 1194 | case DW_OP_or: |
| 1195 | printf ("DW_OP_or"); |
| 1196 | break; |
| 1197 | case DW_OP_plus: |
| 1198 | printf ("DW_OP_plus"); |
| 1199 | break; |
| 1200 | case DW_OP_plus_uconst: |
| 1201 | printf ("DW_OP_plus_uconst: %s", |
| 1202 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| 1203 | data += bytes_read; |
| 1204 | break; |
| 1205 | case DW_OP_shl: |
| 1206 | printf ("DW_OP_shl"); |
| 1207 | break; |
| 1208 | case DW_OP_shr: |
| 1209 | printf ("DW_OP_shr"); |
| 1210 | break; |
| 1211 | case DW_OP_shra: |
| 1212 | printf ("DW_OP_shra"); |
| 1213 | break; |
| 1214 | case DW_OP_xor: |
| 1215 | printf ("DW_OP_xor"); |
| 1216 | break; |
| 1217 | case DW_OP_bra: |
| 1218 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| 1219 | printf ("DW_OP_bra: %ld", (long) svalue); |
| 1220 | break; |
| 1221 | case DW_OP_eq: |
| 1222 | printf ("DW_OP_eq"); |
| 1223 | break; |
| 1224 | case DW_OP_ge: |
| 1225 | printf ("DW_OP_ge"); |
| 1226 | break; |
| 1227 | case DW_OP_gt: |
| 1228 | printf ("DW_OP_gt"); |
| 1229 | break; |
| 1230 | case DW_OP_le: |
| 1231 | printf ("DW_OP_le"); |
| 1232 | break; |
| 1233 | case DW_OP_lt: |
| 1234 | printf ("DW_OP_lt"); |
| 1235 | break; |
| 1236 | case DW_OP_ne: |
| 1237 | printf ("DW_OP_ne"); |
| 1238 | break; |
| 1239 | case DW_OP_skip: |
| 1240 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| 1241 | printf ("DW_OP_skip: %ld", (long) svalue); |
| 1242 | break; |
| 1243 | |
| 1244 | case DW_OP_lit0: |
| 1245 | case DW_OP_lit1: |
| 1246 | case DW_OP_lit2: |
| 1247 | case DW_OP_lit3: |
| 1248 | case DW_OP_lit4: |
| 1249 | case DW_OP_lit5: |
| 1250 | case DW_OP_lit6: |
| 1251 | case DW_OP_lit7: |
| 1252 | case DW_OP_lit8: |
| 1253 | case DW_OP_lit9: |
| 1254 | case DW_OP_lit10: |
| 1255 | case DW_OP_lit11: |
| 1256 | case DW_OP_lit12: |
| 1257 | case DW_OP_lit13: |
| 1258 | case DW_OP_lit14: |
| 1259 | case DW_OP_lit15: |
| 1260 | case DW_OP_lit16: |
| 1261 | case DW_OP_lit17: |
| 1262 | case DW_OP_lit18: |
| 1263 | case DW_OP_lit19: |
| 1264 | case DW_OP_lit20: |
| 1265 | case DW_OP_lit21: |
| 1266 | case DW_OP_lit22: |
| 1267 | case DW_OP_lit23: |
| 1268 | case DW_OP_lit24: |
| 1269 | case DW_OP_lit25: |
| 1270 | case DW_OP_lit26: |
| 1271 | case DW_OP_lit27: |
| 1272 | case DW_OP_lit28: |
| 1273 | case DW_OP_lit29: |
| 1274 | case DW_OP_lit30: |
| 1275 | case DW_OP_lit31: |
| 1276 | printf ("DW_OP_lit%d", op - DW_OP_lit0); |
| 1277 | break; |
| 1278 | |
| 1279 | case DW_OP_reg0: |
| 1280 | case DW_OP_reg1: |
| 1281 | case DW_OP_reg2: |
| 1282 | case DW_OP_reg3: |
| 1283 | case DW_OP_reg4: |
| 1284 | case DW_OP_reg5: |
| 1285 | case DW_OP_reg6: |
| 1286 | case DW_OP_reg7: |
| 1287 | case DW_OP_reg8: |
| 1288 | case DW_OP_reg9: |
| 1289 | case DW_OP_reg10: |
| 1290 | case DW_OP_reg11: |
| 1291 | case DW_OP_reg12: |
| 1292 | case DW_OP_reg13: |
| 1293 | case DW_OP_reg14: |
| 1294 | case DW_OP_reg15: |
| 1295 | case DW_OP_reg16: |
| 1296 | case DW_OP_reg17: |
| 1297 | case DW_OP_reg18: |
| 1298 | case DW_OP_reg19: |
| 1299 | case DW_OP_reg20: |
| 1300 | case DW_OP_reg21: |
| 1301 | case DW_OP_reg22: |
| 1302 | case DW_OP_reg23: |
| 1303 | case DW_OP_reg24: |
| 1304 | case DW_OP_reg25: |
| 1305 | case DW_OP_reg26: |
| 1306 | case DW_OP_reg27: |
| 1307 | case DW_OP_reg28: |
| 1308 | case DW_OP_reg29: |
| 1309 | case DW_OP_reg30: |
| 1310 | case DW_OP_reg31: |
| 1311 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
| 1312 | regname (op - DW_OP_reg0, 1)); |
| 1313 | break; |
| 1314 | |
| 1315 | case DW_OP_breg0: |
| 1316 | case DW_OP_breg1: |
| 1317 | case DW_OP_breg2: |
| 1318 | case DW_OP_breg3: |
| 1319 | case DW_OP_breg4: |
| 1320 | case DW_OP_breg5: |
| 1321 | case DW_OP_breg6: |
| 1322 | case DW_OP_breg7: |
| 1323 | case DW_OP_breg8: |
| 1324 | case DW_OP_breg9: |
| 1325 | case DW_OP_breg10: |
| 1326 | case DW_OP_breg11: |
| 1327 | case DW_OP_breg12: |
| 1328 | case DW_OP_breg13: |
| 1329 | case DW_OP_breg14: |
| 1330 | case DW_OP_breg15: |
| 1331 | case DW_OP_breg16: |
| 1332 | case DW_OP_breg17: |
| 1333 | case DW_OP_breg18: |
| 1334 | case DW_OP_breg19: |
| 1335 | case DW_OP_breg20: |
| 1336 | case DW_OP_breg21: |
| 1337 | case DW_OP_breg22: |
| 1338 | case DW_OP_breg23: |
| 1339 | case DW_OP_breg24: |
| 1340 | case DW_OP_breg25: |
| 1341 | case DW_OP_breg26: |
| 1342 | case DW_OP_breg27: |
| 1343 | case DW_OP_breg28: |
| 1344 | case DW_OP_breg29: |
| 1345 | case DW_OP_breg30: |
| 1346 | case DW_OP_breg31: |
| 1347 | printf ("DW_OP_breg%d (%s): %s", |
| 1348 | op - DW_OP_breg0, |
| 1349 | regname (op - DW_OP_breg0, 1), |
| 1350 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| 1351 | data += bytes_read; |
| 1352 | break; |
| 1353 | |
| 1354 | case DW_OP_regx: |
| 1355 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1356 | data += bytes_read; |
| 1357 | printf ("DW_OP_regx: %s (%s)", |
| 1358 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
| 1359 | break; |
| 1360 | case DW_OP_fbreg: |
| 1361 | need_frame_base = 1; |
| 1362 | printf ("DW_OP_fbreg: %s", |
| 1363 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| 1364 | data += bytes_read; |
| 1365 | break; |
| 1366 | case DW_OP_bregx: |
| 1367 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1368 | data += bytes_read; |
| 1369 | printf ("DW_OP_bregx: %s (%s) %s", |
| 1370 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), |
| 1371 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| 1372 | data += bytes_read; |
| 1373 | break; |
| 1374 | case DW_OP_piece: |
| 1375 | printf ("DW_OP_piece: %s", |
| 1376 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| 1377 | data += bytes_read; |
| 1378 | break; |
| 1379 | case DW_OP_deref_size: |
| 1380 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1381 | printf ("DW_OP_deref_size: %ld", (long) uvalue); |
| 1382 | break; |
| 1383 | case DW_OP_xderef_size: |
| 1384 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1385 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); |
| 1386 | break; |
| 1387 | case DW_OP_nop: |
| 1388 | printf ("DW_OP_nop"); |
| 1389 | break; |
| 1390 | |
| 1391 | /* DWARF 3 extensions. */ |
| 1392 | case DW_OP_push_object_address: |
| 1393 | printf ("DW_OP_push_object_address"); |
| 1394 | break; |
| 1395 | case DW_OP_call2: |
| 1396 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| 1397 | this ought to be an 8-byte wide computation. */ |
| 1398 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| 1399 | printf ("DW_OP_call2: <0x%s>", |
| 1400 | dwarf_vmatoa ("x", svalue + cu_offset)); |
| 1401 | break; |
| 1402 | case DW_OP_call4: |
| 1403 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| 1404 | this ought to be an 8-byte wide computation. */ |
| 1405 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| 1406 | printf ("DW_OP_call4: <0x%s>", |
| 1407 | dwarf_vmatoa ("x", svalue + cu_offset)); |
| 1408 | break; |
| 1409 | case DW_OP_call_ref: |
| 1410 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| 1411 | this ought to be an 8-byte wide computation. */ |
| 1412 | if (dwarf_version == -1) |
| 1413 | { |
| 1414 | printf (_("(DW_OP_call_ref in frame info)")); |
| 1415 | /* No way to tell where the next op is, so just bail. */ |
| 1416 | return need_frame_base; |
| 1417 | } |
| 1418 | if (dwarf_version == 2) |
| 1419 | { |
| 1420 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1421 | } |
| 1422 | else |
| 1423 | { |
| 1424 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| 1425 | } |
| 1426 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| 1427 | break; |
| 1428 | case DW_OP_form_tls_address: |
| 1429 | printf ("DW_OP_form_tls_address"); |
| 1430 | break; |
| 1431 | case DW_OP_call_frame_cfa: |
| 1432 | printf ("DW_OP_call_frame_cfa"); |
| 1433 | break; |
| 1434 | case DW_OP_bit_piece: |
| 1435 | printf ("DW_OP_bit_piece: "); |
| 1436 | printf (_("size: %s "), |
| 1437 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| 1438 | data += bytes_read; |
| 1439 | printf (_("offset: %s "), |
| 1440 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| 1441 | data += bytes_read; |
| 1442 | break; |
| 1443 | |
| 1444 | /* DWARF 4 extensions. */ |
| 1445 | case DW_OP_stack_value: |
| 1446 | printf ("DW_OP_stack_value"); |
| 1447 | break; |
| 1448 | |
| 1449 | case DW_OP_implicit_value: |
| 1450 | printf ("DW_OP_implicit_value"); |
| 1451 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1452 | data += bytes_read; |
| 1453 | data = display_block (data, uvalue, end, ' '); |
| 1454 | break; |
| 1455 | |
| 1456 | /* GNU extensions. */ |
| 1457 | case DW_OP_GNU_push_tls_address: |
| 1458 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
| 1459 | break; |
| 1460 | case DW_OP_GNU_uninit: |
| 1461 | printf ("DW_OP_GNU_uninit"); |
| 1462 | /* FIXME: Is there data associated with this OP ? */ |
| 1463 | break; |
| 1464 | case DW_OP_GNU_encoded_addr: |
| 1465 | { |
| 1466 | int encoding = 0; |
| 1467 | dwarf_vma addr; |
| 1468 | |
| 1469 | if (data < end) |
| 1470 | encoding = *data++; |
| 1471 | addr = get_encoded_value (&data, encoding, section, end); |
| 1472 | |
| 1473 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); |
| 1474 | print_dwarf_vma (addr, pointer_size); |
| 1475 | } |
| 1476 | break; |
| 1477 | case DW_OP_implicit_pointer: |
| 1478 | case DW_OP_GNU_implicit_pointer: |
| 1479 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| 1480 | this ought to be an 8-byte wide computation. */ |
| 1481 | if (dwarf_version == -1) |
| 1482 | { |
| 1483 | printf (_("(%s in frame info)"), |
| 1484 | (op == DW_OP_implicit_pointer |
| 1485 | ? "DW_OP_implicit_pointer" |
| 1486 | : "DW_OP_GNU_implicit_pointer")); |
| 1487 | /* No way to tell where the next op is, so just bail. */ |
| 1488 | return need_frame_base; |
| 1489 | } |
| 1490 | if (dwarf_version == 2) |
| 1491 | { |
| 1492 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1493 | } |
| 1494 | else |
| 1495 | { |
| 1496 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| 1497 | } |
| 1498 | printf ("%s: <0x%s> %s", |
| 1499 | (op == DW_OP_implicit_pointer |
| 1500 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), |
| 1501 | dwarf_vmatoa ("x", uvalue), |
| 1502 | dwarf_vmatoa ("d", read_sleb128 (data, |
| 1503 | &bytes_read, end))); |
| 1504 | data += bytes_read; |
| 1505 | break; |
| 1506 | case DW_OP_entry_value: |
| 1507 | case DW_OP_GNU_entry_value: |
| 1508 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1509 | data += bytes_read; |
| 1510 | /* PR 17531: file: 0cc9cd00. */ |
| 1511 | if (uvalue > (dwarf_vma) (end - data)) |
| 1512 | uvalue = end - data; |
| 1513 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
| 1514 | : "DW_OP_GNU_entry_value")); |
| 1515 | if (decode_location_expression (data, pointer_size, offset_size, |
| 1516 | dwarf_version, uvalue, |
| 1517 | cu_offset, section)) |
| 1518 | need_frame_base = 1; |
| 1519 | putchar (')'); |
| 1520 | data += uvalue; |
| 1521 | if (data > end) |
| 1522 | data = end; |
| 1523 | break; |
| 1524 | case DW_OP_const_type: |
| 1525 | case DW_OP_GNU_const_type: |
| 1526 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1527 | data += bytes_read; |
| 1528 | printf ("%s: <0x%s> ", |
| 1529 | (op == DW_OP_const_type ? "DW_OP_const_type" |
| 1530 | : "DW_OP_GNU_const_type"), |
| 1531 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
| 1532 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1533 | data = display_block (data, uvalue, end, ' '); |
| 1534 | break; |
| 1535 | case DW_OP_regval_type: |
| 1536 | case DW_OP_GNU_regval_type: |
| 1537 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1538 | data += bytes_read; |
| 1539 | printf ("%s: %s (%s)", |
| 1540 | (op == DW_OP_regval_type ? "DW_OP_regval_type" |
| 1541 | : "DW_OP_GNU_regval_type"), |
| 1542 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
| 1543 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1544 | data += bytes_read; |
| 1545 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
| 1546 | break; |
| 1547 | case DW_OP_deref_type: |
| 1548 | case DW_OP_GNU_deref_type: |
| 1549 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1550 | printf ("%s: %ld", |
| 1551 | (op == DW_OP_deref_type ? "DW_OP_deref_type" |
| 1552 | : "DW_OP_GNU_deref_type"), |
| 1553 | (long) uvalue); |
| 1554 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1555 | data += bytes_read; |
| 1556 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
| 1557 | break; |
| 1558 | case DW_OP_convert: |
| 1559 | case DW_OP_GNU_convert: |
| 1560 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1561 | data += bytes_read; |
| 1562 | printf ("%s <0x%s>", |
| 1563 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), |
| 1564 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
| 1565 | break; |
| 1566 | case DW_OP_reinterpret: |
| 1567 | case DW_OP_GNU_reinterpret: |
| 1568 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1569 | data += bytes_read; |
| 1570 | printf ("%s <0x%s>", |
| 1571 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" |
| 1572 | : "DW_OP_GNU_reinterpret"), |
| 1573 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
| 1574 | break; |
| 1575 | case DW_OP_GNU_parameter_ref: |
| 1576 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| 1577 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
| 1578 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
| 1579 | break; |
| 1580 | case DW_OP_GNU_addr_index: |
| 1581 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1582 | data += bytes_read; |
| 1583 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| 1584 | break; |
| 1585 | case DW_OP_GNU_const_index: |
| 1586 | uvalue = read_uleb128 (data, &bytes_read, end); |
| 1587 | data += bytes_read; |
| 1588 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| 1589 | break; |
| 1590 | case DW_OP_GNU_variable_value: |
| 1591 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| 1592 | this ought to be an 8-byte wide computation. */ |
| 1593 | if (dwarf_version == -1) |
| 1594 | { |
| 1595 | printf (_("(DW_OP_GNU_variable_value in frame info)")); |
| 1596 | /* No way to tell where the next op is, so just bail. */ |
| 1597 | return need_frame_base; |
| 1598 | } |
| 1599 | if (dwarf_version == 2) |
| 1600 | { |
| 1601 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1602 | } |
| 1603 | else |
| 1604 | { |
| 1605 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| 1606 | } |
| 1607 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| 1608 | break; |
| 1609 | |
| 1610 | /* HP extensions. */ |
| 1611 | case DW_OP_HP_is_value: |
| 1612 | printf ("DW_OP_HP_is_value"); |
| 1613 | /* FIXME: Is there data associated with this OP ? */ |
| 1614 | break; |
| 1615 | case DW_OP_HP_fltconst4: |
| 1616 | printf ("DW_OP_HP_fltconst4"); |
| 1617 | /* FIXME: Is there data associated with this OP ? */ |
| 1618 | break; |
| 1619 | case DW_OP_HP_fltconst8: |
| 1620 | printf ("DW_OP_HP_fltconst8"); |
| 1621 | /* FIXME: Is there data associated with this OP ? */ |
| 1622 | break; |
| 1623 | case DW_OP_HP_mod_range: |
| 1624 | printf ("DW_OP_HP_mod_range"); |
| 1625 | /* FIXME: Is there data associated with this OP ? */ |
| 1626 | break; |
| 1627 | case DW_OP_HP_unmod_range: |
| 1628 | printf ("DW_OP_HP_unmod_range"); |
| 1629 | /* FIXME: Is there data associated with this OP ? */ |
| 1630 | break; |
| 1631 | case DW_OP_HP_tls: |
| 1632 | printf ("DW_OP_HP_tls"); |
| 1633 | /* FIXME: Is there data associated with this OP ? */ |
| 1634 | break; |
| 1635 | |
| 1636 | /* PGI (STMicroelectronics) extensions. */ |
| 1637 | case DW_OP_PGI_omp_thread_num: |
| 1638 | /* Pushes the thread number for the current thread as it would be |
| 1639 | returned by the standard OpenMP library function: |
| 1640 | omp_get_thread_num(). The "current thread" is the thread for |
| 1641 | which the expression is being evaluated. */ |
| 1642 | printf ("DW_OP_PGI_omp_thread_num"); |
| 1643 | break; |
| 1644 | |
| 1645 | default: |
| 1646 | if (op >= DW_OP_lo_user |
| 1647 | && op <= DW_OP_hi_user) |
| 1648 | printf (_("(User defined location op 0x%x)"), op); |
| 1649 | else |
| 1650 | printf (_("(Unknown location op 0x%x)"), op); |
| 1651 | /* No way to tell where the next op is, so just bail. */ |
| 1652 | return need_frame_base; |
| 1653 | } |
| 1654 | |
| 1655 | /* Separate the ops. */ |
| 1656 | if (data < end) |
| 1657 | printf ("; "); |
| 1658 | } |
| 1659 | |
| 1660 | return need_frame_base; |
| 1661 | } |
| 1662 | |
| 1663 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
| 1664 | This is used for DWARF package files. */ |
| 1665 | |
| 1666 | static struct cu_tu_set * |
| 1667 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) |
| 1668 | { |
| 1669 | struct cu_tu_set *p; |
| 1670 | unsigned int nsets; |
| 1671 | unsigned int dw_sect; |
| 1672 | |
| 1673 | if (do_types) |
| 1674 | { |
| 1675 | p = tu_sets; |
| 1676 | nsets = tu_count; |
| 1677 | dw_sect = DW_SECT_TYPES; |
| 1678 | } |
| 1679 | else |
| 1680 | { |
| 1681 | p = cu_sets; |
| 1682 | nsets = cu_count; |
| 1683 | dw_sect = DW_SECT_INFO; |
| 1684 | } |
| 1685 | while (nsets > 0) |
| 1686 | { |
| 1687 | if (p->section_offsets [dw_sect] == cu_offset) |
| 1688 | return p; |
| 1689 | p++; |
| 1690 | nsets--; |
| 1691 | } |
| 1692 | return NULL; |
| 1693 | } |
| 1694 | |
| 1695 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
| 1696 | static void |
| 1697 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) |
| 1698 | { |
| 1699 | dwarf_vma tmp = * low_bits; |
| 1700 | |
| 1701 | tmp += inc; |
| 1702 | |
| 1703 | /* FIXME: There is probably a better way of handling this: |
| 1704 | |
| 1705 | We need to cope with dwarf_vma being a 32-bit or 64-bit |
| 1706 | type. Plus regardless of its size LOW_BITS is meant to |
| 1707 | only hold 32-bits, so if there is overflow or wrap around |
| 1708 | we must propagate into HIGH_BITS. */ |
| 1709 | if (tmp < * low_bits) |
| 1710 | { |
| 1711 | ++ * high_bits; |
| 1712 | } |
| 1713 | else if (sizeof (tmp) > 8 |
| 1714 | && (tmp >> 31) > 1) |
| 1715 | { |
| 1716 | ++ * high_bits; |
| 1717 | tmp &= 0xFFFFFFFF; |
| 1718 | } |
| 1719 | |
| 1720 | * low_bits = tmp; |
| 1721 | } |
| 1722 | |
| 1723 | static const char * |
| 1724 | fetch_alt_indirect_string (dwarf_vma offset) |
| 1725 | { |
| 1726 | separate_info * i; |
| 1727 | |
| 1728 | if (! do_follow_links) |
| 1729 | return ""; |
| 1730 | |
| 1731 | if (first_separate_info == NULL) |
| 1732 | return _("<no links available>"); |
| 1733 | |
| 1734 | for (i = first_separate_info; i != NULL; i = i->next) |
| 1735 | { |
| 1736 | struct dwarf_section * section; |
| 1737 | const char * ret; |
| 1738 | |
| 1739 | if (! load_debug_section (separate_debug_str, i->handle)) |
| 1740 | continue; |
| 1741 | |
| 1742 | section = &debug_displays [separate_debug_str].section; |
| 1743 | |
| 1744 | if (section->start == NULL) |
| 1745 | continue; |
| 1746 | |
| 1747 | if (offset >= section->size) |
| 1748 | continue; |
| 1749 | |
| 1750 | ret = (const char *) (section->start + offset); |
| 1751 | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
| 1752 | NUL byte. Since our caller is expecting to receive a well formed C |
| 1753 | string we test for the lack of a terminating byte here. */ |
| 1754 | if (strnlen ((const char *) ret, section->size - offset) |
| 1755 | == section->size - offset) |
| 1756 | return _("<no NUL byte at end of alt .debug_str section>"); |
| 1757 | |
| 1758 | return ret; |
| 1759 | } |
| 1760 | |
| 1761 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
| 1762 | dwarf_vmatoa ("x", offset)); |
| 1763 | return _("<offset is too big>"); |
| 1764 | } |
| 1765 | |
| 1766 | static const char * |
| 1767 | get_AT_name (unsigned long attribute) |
| 1768 | { |
| 1769 | const char *name; |
| 1770 | |
| 1771 | if (attribute == 0) |
| 1772 | return "DW_AT value: 0"; |
| 1773 | |
| 1774 | /* One value is shared by the MIPS and HP extensions: */ |
| 1775 | if (attribute == DW_AT_MIPS_fde) |
| 1776 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; |
| 1777 | |
| 1778 | name = get_DW_AT_name (attribute); |
| 1779 | |
| 1780 | if (name == NULL) |
| 1781 | { |
| 1782 | static char buffer[100]; |
| 1783 | |
| 1784 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), |
| 1785 | attribute); |
| 1786 | return buffer; |
| 1787 | } |
| 1788 | |
| 1789 | return name; |
| 1790 | } |
| 1791 | |
| 1792 | static void |
| 1793 | add_dwo_info (const char * field, dwo_type type) |
| 1794 | { |
| 1795 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); |
| 1796 | |
| 1797 | dwinfo->type = type; |
| 1798 | dwinfo->value = field; |
| 1799 | dwinfo->next = first_dwo_info; |
| 1800 | first_dwo_info = dwinfo; |
| 1801 | } |
| 1802 | |
| 1803 | static void |
| 1804 | add_dwo_name (const char * name) |
| 1805 | { |
| 1806 | add_dwo_info (name, DWO_NAME); |
| 1807 | } |
| 1808 | |
| 1809 | static void |
| 1810 | add_dwo_dir (const char * dir) |
| 1811 | { |
| 1812 | add_dwo_info (dir, DWO_DIR); |
| 1813 | } |
| 1814 | |
| 1815 | static void |
| 1816 | add_dwo_id (const char * id) |
| 1817 | { |
| 1818 | add_dwo_info (id, DWO_ID); |
| 1819 | } |
| 1820 | |
| 1821 | static void |
| 1822 | free_dwo_info (void) |
| 1823 | { |
| 1824 | dwo_info * dwinfo; |
| 1825 | dwo_info * next; |
| 1826 | |
| 1827 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) |
| 1828 | { |
| 1829 | next = dwinfo->next; |
| 1830 | free (dwinfo); |
| 1831 | } |
| 1832 | first_dwo_info = NULL; |
| 1833 | } |
| 1834 | |
| 1835 | static unsigned char * |
| 1836 | read_and_display_attr_value (unsigned long attribute, |
| 1837 | unsigned long form, |
| 1838 | dwarf_signed_vma implicit_const, |
| 1839 | unsigned char * data, |
| 1840 | unsigned char * end, |
| 1841 | dwarf_vma cu_offset, |
| 1842 | dwarf_vma pointer_size, |
| 1843 | dwarf_vma offset_size, |
| 1844 | int dwarf_version, |
| 1845 | debug_info * debug_info_p, |
| 1846 | int do_loc, |
| 1847 | struct dwarf_section * section, |
| 1848 | struct cu_tu_set * this_set, |
| 1849 | char delimiter) |
| 1850 | { |
| 1851 | dwarf_vma uvalue = 0; |
| 1852 | unsigned char *block_start = NULL; |
| 1853 | unsigned char * orig_data = data; |
| 1854 | unsigned int bytes_read; |
| 1855 | |
| 1856 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
| 1857 | { |
| 1858 | warn (_("Corrupt attribute\n")); |
| 1859 | return data; |
| 1860 | } |
| 1861 | |
| 1862 | switch (form) |
| 1863 | { |
| 1864 | default: |
| 1865 | break; |
| 1866 | |
| 1867 | case DW_FORM_ref_addr: |
| 1868 | if (dwarf_version == 2) |
| 1869 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1870 | else if (dwarf_version == 3 || dwarf_version == 4) |
| 1871 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| 1872 | else |
| 1873 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
| 1874 | |
| 1875 | break; |
| 1876 | |
| 1877 | case DW_FORM_addr: |
| 1878 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| 1879 | break; |
| 1880 | |
| 1881 | case DW_FORM_strp: |
| 1882 | case DW_FORM_line_strp: |
| 1883 | case DW_FORM_sec_offset: |
| 1884 | case DW_FORM_GNU_ref_alt: |
| 1885 | case DW_FORM_GNU_strp_alt: |
| 1886 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| 1887 | break; |
| 1888 | |
| 1889 | case DW_FORM_flag_present: |
| 1890 | uvalue = 1; |
| 1891 | break; |
| 1892 | |
| 1893 | case DW_FORM_ref1: |
| 1894 | case DW_FORM_flag: |
| 1895 | case DW_FORM_data1: |
| 1896 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| 1897 | break; |
| 1898 | |
| 1899 | case DW_FORM_ref2: |
| 1900 | case DW_FORM_data2: |
| 1901 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| 1902 | break; |
| 1903 | |
| 1904 | case DW_FORM_ref4: |
| 1905 | case DW_FORM_data4: |
| 1906 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| 1907 | break; |
| 1908 | |
| 1909 | case DW_FORM_sdata: |
| 1910 | uvalue = read_sleb128 (data, & bytes_read, end); |
| 1911 | data += bytes_read; |
| 1912 | break; |
| 1913 | |
| 1914 | case DW_FORM_GNU_str_index: |
| 1915 | uvalue = read_uleb128 (data, & bytes_read, end); |
| 1916 | data += bytes_read; |
| 1917 | break; |
| 1918 | |
| 1919 | case DW_FORM_ref_udata: |
| 1920 | case DW_FORM_udata: |
| 1921 | uvalue = read_uleb128 (data, & bytes_read, end); |
| 1922 | data += bytes_read; |
| 1923 | break; |
| 1924 | |
| 1925 | case DW_FORM_indirect: |
| 1926 | form = read_uleb128 (data, & bytes_read, end); |
| 1927 | data += bytes_read; |
| 1928 | if (!do_loc) |
| 1929 | printf ("%c%s", delimiter, get_FORM_name (form)); |
| 1930 | if (form == DW_FORM_implicit_const) |
| 1931 | { |
| 1932 | implicit_const = read_sleb128 (data, & bytes_read, end); |
| 1933 | data += bytes_read; |
| 1934 | } |
| 1935 | return read_and_display_attr_value (attribute, form, implicit_const, data, |
| 1936 | end, cu_offset, pointer_size, |
| 1937 | offset_size, dwarf_version, |
| 1938 | debug_info_p, do_loc, |
| 1939 | section, this_set, delimiter); |
| 1940 | case DW_FORM_GNU_addr_index: |
| 1941 | uvalue = read_uleb128 (data, & bytes_read, end); |
| 1942 | data += bytes_read; |
| 1943 | break; |
| 1944 | } |
| 1945 | |
| 1946 | switch (form) |
| 1947 | { |
| 1948 | case DW_FORM_ref_addr: |
| 1949 | if (!do_loc) |
| 1950 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
| 1951 | break; |
| 1952 | |
| 1953 | case DW_FORM_GNU_ref_alt: |
| 1954 | if (!do_loc) |
| 1955 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
| 1956 | /* FIXME: Follow the reference... */ |
| 1957 | break; |
| 1958 | |
| 1959 | case DW_FORM_ref1: |
| 1960 | case DW_FORM_ref2: |
| 1961 | case DW_FORM_ref4: |
| 1962 | case DW_FORM_ref_udata: |
| 1963 | if (!do_loc) |
| 1964 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
| 1965 | break; |
| 1966 | |
| 1967 | case DW_FORM_data4: |
| 1968 | case DW_FORM_addr: |
| 1969 | case DW_FORM_sec_offset: |
| 1970 | if (!do_loc) |
| 1971 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
| 1972 | break; |
| 1973 | |
| 1974 | case DW_FORM_flag_present: |
| 1975 | case DW_FORM_flag: |
| 1976 | case DW_FORM_data1: |
| 1977 | case DW_FORM_data2: |
| 1978 | case DW_FORM_sdata: |
| 1979 | case DW_FORM_udata: |
| 1980 | if (!do_loc) |
| 1981 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
| 1982 | break; |
| 1983 | |
| 1984 | case DW_FORM_implicit_const: |
| 1985 | if (!do_loc) |
| 1986 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); |
| 1987 | break; |
| 1988 | |
| 1989 | case DW_FORM_ref8: |
| 1990 | case DW_FORM_data8: |
| 1991 | if (!do_loc) |
| 1992 | { |
| 1993 | dwarf_vma high_bits; |
| 1994 | dwarf_vma utmp; |
| 1995 | char buf[64]; |
| 1996 | |
| 1997 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
| 1998 | utmp = uvalue; |
| 1999 | if (form == DW_FORM_ref8) |
| 2000 | add64 (& high_bits, & utmp, cu_offset); |
| 2001 | printf ("%c0x%s", delimiter, |
| 2002 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
| 2003 | } |
| 2004 | |
| 2005 | if ((do_loc || do_debug_loc || do_debug_ranges) |
| 2006 | && num_debug_info_entries == 0) |
| 2007 | { |
| 2008 | if (sizeof (uvalue) == 8) |
| 2009 | SAFE_BYTE_GET (uvalue, data, 8, end); |
| 2010 | else |
| 2011 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
| 2012 | } |
| 2013 | |
| 2014 | data += 8; |
| 2015 | break; |
| 2016 | |
| 2017 | case DW_FORM_data16: |
| 2018 | if (!do_loc) |
| 2019 | { |
| 2020 | dwarf_vma left_high_bits, left_low_bits; |
| 2021 | dwarf_vma right_high_bits, right_low_bits; |
| 2022 | |
| 2023 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); |
| 2024 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); |
| 2025 | if (byte_get == byte_get_little_endian) |
| 2026 | { |
| 2027 | /* Swap them. */ |
| 2028 | left_high_bits ^= right_high_bits; |
| 2029 | right_high_bits ^= left_high_bits; |
| 2030 | left_high_bits ^= right_high_bits; |
| 2031 | left_low_bits ^= right_low_bits; |
| 2032 | right_low_bits ^= left_low_bits; |
| 2033 | left_low_bits ^= right_low_bits; |
| 2034 | } |
| 2035 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" |
| 2036 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", |
| 2037 | left_high_bits, left_low_bits, right_high_bits, |
| 2038 | right_low_bits); |
| 2039 | } |
| 2040 | data += 16; |
| 2041 | break; |
| 2042 | |
| 2043 | case DW_FORM_string: |
| 2044 | if (!do_loc) |
| 2045 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
| 2046 | data += strnlen ((char *) data, end - data) + 1; |
| 2047 | break; |
| 2048 | |
| 2049 | case DW_FORM_block: |
| 2050 | case DW_FORM_exprloc: |
| 2051 | uvalue = read_uleb128 (data, & bytes_read, end); |
| 2052 | block_start = data + bytes_read; |
| 2053 | if (block_start >= end) |
| 2054 | { |
| 2055 | warn (_("Block ends prematurely\n")); |
| 2056 | uvalue = 0; |
| 2057 | block_start = end; |
| 2058 | } |
| 2059 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
| 2060 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute |
| 2061 | block_start + uvalue here. */ |
| 2062 | data = block_start + uvalue; |
| 2063 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
| 2064 | if (block_start + uvalue > end || data < block_start) |
| 2065 | { |
| 2066 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| 2067 | uvalue = end - block_start; |
| 2068 | } |
| 2069 | if (do_loc) |
| 2070 | data = block_start + uvalue; |
| 2071 | else |
| 2072 | data = display_block (block_start, uvalue, end, delimiter); |
| 2073 | break; |
| 2074 | |
| 2075 | case DW_FORM_block1: |
| 2076 | SAFE_BYTE_GET (uvalue, data, 1, end); |
| 2077 | block_start = data + 1; |
| 2078 | if (block_start >= end) |
| 2079 | { |
| 2080 | warn (_("Block ends prematurely\n")); |
| 2081 | uvalue = 0; |
| 2082 | block_start = end; |
| 2083 | } |
| 2084 | data = block_start + uvalue; |
| 2085 | if (block_start + uvalue > end || data < block_start) |
| 2086 | { |
| 2087 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| 2088 | uvalue = end - block_start; |
| 2089 | } |
| 2090 | if (do_loc) |
| 2091 | data = block_start + uvalue; |
| 2092 | else |
| 2093 | data = display_block (block_start, uvalue, end, delimiter); |
| 2094 | break; |
| 2095 | |
| 2096 | case DW_FORM_block2: |
| 2097 | SAFE_BYTE_GET (uvalue, data, 2, end); |
| 2098 | block_start = data + 2; |
| 2099 | if (block_start >= end) |
| 2100 | { |
| 2101 | warn (_("Block ends prematurely\n")); |
| 2102 | uvalue = 0; |
| 2103 | block_start = end; |
| 2104 | } |
| 2105 | data = block_start + uvalue; |
| 2106 | if (block_start + uvalue > end || data < block_start) |
| 2107 | { |
| 2108 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| 2109 | uvalue = end - block_start; |
| 2110 | } |
| 2111 | if (do_loc) |
| 2112 | data = block_start + uvalue; |
| 2113 | else |
| 2114 | data = display_block (block_start, uvalue, end, delimiter); |
| 2115 | break; |
| 2116 | |
| 2117 | case DW_FORM_block4: |
| 2118 | SAFE_BYTE_GET (uvalue, data, 4, end); |
| 2119 | block_start = data + 4; |
| 2120 | /* PR 17512: file: 3371-3907-0.004. */ |
| 2121 | if (block_start >= end) |
| 2122 | { |
| 2123 | warn (_("Block ends prematurely\n")); |
| 2124 | uvalue = 0; |
| 2125 | block_start = end; |
| 2126 | } |
| 2127 | data = block_start + uvalue; |
| 2128 | if (block_start + uvalue > end |
| 2129 | /* PR 17531: file: 5b5f0592. */ |
| 2130 | || data < block_start) |
| 2131 | { |
| 2132 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| 2133 | uvalue = end - block_start; |
| 2134 | } |
| 2135 | if (do_loc) |
| 2136 | data = block_start + uvalue; |
| 2137 | else |
| 2138 | data = display_block (block_start, uvalue, end, delimiter); |
| 2139 | break; |
| 2140 | |
| 2141 | case DW_FORM_strp: |
| 2142 | if (!do_loc) |
| 2143 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
| 2144 | dwarf_vmatoa ("x", uvalue), |
| 2145 | fetch_indirect_string (uvalue)); |
| 2146 | break; |
| 2147 | |
| 2148 | case DW_FORM_line_strp: |
| 2149 | if (!do_loc) |
| 2150 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, |
| 2151 | dwarf_vmatoa ("x", uvalue), |
| 2152 | fetch_indirect_line_string (uvalue)); |
| 2153 | break; |
| 2154 | |
| 2155 | case DW_FORM_GNU_str_index: |
| 2156 | if (!do_loc) |
| 2157 | { |
| 2158 | const char * suffix = strrchr (section->name, '.'); |
| 2159 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; |
| 2160 | |
| 2161 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
| 2162 | dwarf_vmatoa ("x", uvalue), |
| 2163 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); |
| 2164 | } |
| 2165 | break; |
| 2166 | |
| 2167 | case DW_FORM_GNU_strp_alt: |
| 2168 | if (!do_loc) |
| 2169 | { |
| 2170 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, |
| 2171 | dwarf_vmatoa ("x", uvalue), |
| 2172 | fetch_alt_indirect_string (uvalue)); |
| 2173 | } |
| 2174 | break; |
| 2175 | |
| 2176 | case DW_FORM_indirect: |
| 2177 | /* Handled above. */ |
| 2178 | break; |
| 2179 | |
| 2180 | case DW_FORM_ref_sig8: |
| 2181 | if (!do_loc) |
| 2182 | { |
| 2183 | dwarf_vma high_bits; |
| 2184 | char buf[64]; |
| 2185 | |
| 2186 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
| 2187 | printf ("%csignature: 0x%s", delimiter, |
| 2188 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
| 2189 | } |
| 2190 | data += 8; |
| 2191 | break; |
| 2192 | |
| 2193 | case DW_FORM_GNU_addr_index: |
| 2194 | if (!do_loc) |
| 2195 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
| 2196 | dwarf_vmatoa ("x", uvalue), |
| 2197 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); |
| 2198 | break; |
| 2199 | |
| 2200 | default: |
| 2201 | warn (_("Unrecognized form: %lu\n"), form); |
| 2202 | break; |
| 2203 | } |
| 2204 | |
| 2205 | if ((do_loc || do_debug_loc || do_debug_ranges) |
| 2206 | && num_debug_info_entries == 0 |
| 2207 | && debug_info_p != NULL) |
| 2208 | { |
| 2209 | switch (attribute) |
| 2210 | { |
| 2211 | case DW_AT_frame_base: |
| 2212 | have_frame_base = 1; |
| 2213 | /* Fall through. */ |
| 2214 | case DW_AT_location: |
| 2215 | case DW_AT_GNU_locviews: |
| 2216 | case DW_AT_string_length: |
| 2217 | case DW_AT_return_addr: |
| 2218 | case DW_AT_data_member_location: |
| 2219 | case DW_AT_vtable_elem_location: |
| 2220 | case DW_AT_segment: |
| 2221 | case DW_AT_static_link: |
| 2222 | case DW_AT_use_location: |
| 2223 | case DW_AT_call_value: |
| 2224 | case DW_AT_GNU_call_site_value: |
| 2225 | case DW_AT_call_data_value: |
| 2226 | case DW_AT_GNU_call_site_data_value: |
| 2227 | case DW_AT_call_target: |
| 2228 | case DW_AT_GNU_call_site_target: |
| 2229 | case DW_AT_call_target_clobbered: |
| 2230 | case DW_AT_GNU_call_site_target_clobbered: |
| 2231 | if ((dwarf_version < 4 |
| 2232 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| 2233 | || form == DW_FORM_sec_offset) |
| 2234 | { |
| 2235 | /* Process location list. */ |
| 2236 | unsigned int lmax = debug_info_p->max_loc_offsets; |
| 2237 | unsigned int num = debug_info_p->num_loc_offsets; |
| 2238 | |
| 2239 | if (lmax == 0 || num >= lmax) |
| 2240 | { |
| 2241 | lmax += 1024; |
| 2242 | debug_info_p->loc_offsets = (dwarf_vma *) |
| 2243 | xcrealloc (debug_info_p->loc_offsets, |
| 2244 | lmax, sizeof (*debug_info_p->loc_offsets)); |
| 2245 | debug_info_p->loc_views = (dwarf_vma *) |
| 2246 | xcrealloc (debug_info_p->loc_views, |
| 2247 | lmax, sizeof (*debug_info_p->loc_views)); |
| 2248 | debug_info_p->have_frame_base = (int *) |
| 2249 | xcrealloc (debug_info_p->have_frame_base, |
| 2250 | lmax, sizeof (*debug_info_p->have_frame_base)); |
| 2251 | debug_info_p->max_loc_offsets = lmax; |
| 2252 | } |
| 2253 | if (this_set != NULL) |
| 2254 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
| 2255 | debug_info_p->have_frame_base [num] = have_frame_base; |
| 2256 | if (attribute != DW_AT_GNU_locviews) |
| 2257 | { |
| 2258 | /* Corrupt DWARF info can produce more offsets than views. |
| 2259 | See PR 23062 for an example. */ |
| 2260 | if (debug_info_p->num_loc_offsets |
| 2261 | > debug_info_p->num_loc_views) |
| 2262 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); |
| 2263 | else |
| 2264 | { |
| 2265 | debug_info_p->loc_offsets [num] = uvalue; |
| 2266 | debug_info_p->num_loc_offsets++; |
| 2267 | } |
| 2268 | } |
| 2269 | else |
| 2270 | { |
| 2271 | assert (debug_info_p->num_loc_views <= num); |
| 2272 | num = debug_info_p->num_loc_views; |
| 2273 | if (num > debug_info_p->num_loc_offsets) |
| 2274 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); |
| 2275 | else |
| 2276 | { |
| 2277 | debug_info_p->loc_views [num] = uvalue; |
| 2278 | debug_info_p->num_loc_views++; |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | break; |
| 2283 | |
| 2284 | case DW_AT_low_pc: |
| 2285 | if (need_base_address) |
| 2286 | debug_info_p->base_address = uvalue; |
| 2287 | break; |
| 2288 | |
| 2289 | case DW_AT_GNU_addr_base: |
| 2290 | debug_info_p->addr_base = uvalue; |
| 2291 | break; |
| 2292 | |
| 2293 | case DW_AT_GNU_ranges_base: |
| 2294 | debug_info_p->ranges_base = uvalue; |
| 2295 | break; |
| 2296 | |
| 2297 | case DW_AT_ranges: |
| 2298 | if ((dwarf_version < 4 |
| 2299 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| 2300 | || form == DW_FORM_sec_offset) |
| 2301 | { |
| 2302 | /* Process range list. */ |
| 2303 | unsigned int lmax = debug_info_p->max_range_lists; |
| 2304 | unsigned int num = debug_info_p->num_range_lists; |
| 2305 | |
| 2306 | if (lmax == 0 || num >= lmax) |
| 2307 | { |
| 2308 | lmax += 1024; |
| 2309 | debug_info_p->range_lists = (dwarf_vma *) |
| 2310 | xcrealloc (debug_info_p->range_lists, |
| 2311 | lmax, sizeof (*debug_info_p->range_lists)); |
| 2312 | debug_info_p->max_range_lists = lmax; |
| 2313 | } |
| 2314 | debug_info_p->range_lists [num] = uvalue; |
| 2315 | debug_info_p->num_range_lists++; |
| 2316 | } |
| 2317 | break; |
| 2318 | |
| 2319 | case DW_AT_GNU_dwo_name: |
| 2320 | case DW_AT_dwo_name: |
| 2321 | if (need_dwo_info) |
| 2322 | switch (form) |
| 2323 | { |
| 2324 | case DW_FORM_strp: |
| 2325 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
| 2326 | break; |
| 2327 | case DW_FORM_GNU_str_index: |
| 2328 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
| 2329 | break; |
| 2330 | case DW_FORM_string: |
| 2331 | add_dwo_name ((const char *) orig_data); |
| 2332 | break; |
| 2333 | default: |
| 2334 | warn (_("Unsupported form (%s) for attribute %s\n"), |
| 2335 | get_FORM_name (form), get_AT_name (attribute)); |
| 2336 | break; |
| 2337 | } |
| 2338 | break; |
| 2339 | |
| 2340 | case DW_AT_comp_dir: |
| 2341 | /* FIXME: Also extract a build-id in a CU/TU. */ |
| 2342 | if (need_dwo_info) |
| 2343 | switch (form) |
| 2344 | { |
| 2345 | case DW_FORM_strp: |
| 2346 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
| 2347 | break; |
| 2348 | case DW_FORM_line_strp: |
| 2349 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
| 2350 | break; |
| 2351 | case DW_FORM_GNU_str_index: |
| 2352 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
| 2353 | break; |
| 2354 | case DW_FORM_string: |
| 2355 | add_dwo_dir ((const char *) orig_data); |
| 2356 | break; |
| 2357 | default: |
| 2358 | warn (_("Unsupported form (%s) for attribute %s\n"), |
| 2359 | get_FORM_name (form), get_AT_name (attribute)); |
| 2360 | break; |
| 2361 | } |
| 2362 | break; |
| 2363 | |
| 2364 | case DW_AT_GNU_dwo_id: |
| 2365 | if (need_dwo_info) |
| 2366 | switch (form) |
| 2367 | { |
| 2368 | case DW_FORM_data8: |
| 2369 | /* FIXME: Record the length of the ID as well ? */ |
| 2370 | add_dwo_id ((const char *) (data - 8)); |
| 2371 | break; |
| 2372 | default: |
| 2373 | warn (_("Unsupported form (%s) for attribute %s\n"), |
| 2374 | get_FORM_name (form), get_AT_name (attribute)); |
| 2375 | break; |
| 2376 | } |
| 2377 | break; |
| 2378 | |
| 2379 | default: |
| 2380 | break; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | if (do_loc || attribute == 0) |
| 2385 | return data; |
| 2386 | |
| 2387 | /* For some attributes we can display further information. */ |
| 2388 | switch (attribute) |
| 2389 | { |
| 2390 | case DW_AT_inline: |
| 2391 | printf ("\t"); |
| 2392 | switch (uvalue) |
| 2393 | { |
| 2394 | case DW_INL_not_inlined: |
| 2395 | printf (_("(not inlined)")); |
| 2396 | break; |
| 2397 | case DW_INL_inlined: |
| 2398 | printf (_("(inlined)")); |
| 2399 | break; |
| 2400 | case DW_INL_declared_not_inlined: |
| 2401 | printf (_("(declared as inline but ignored)")); |
| 2402 | break; |
| 2403 | case DW_INL_declared_inlined: |
| 2404 | printf (_("(declared as inline and inlined)")); |
| 2405 | break; |
| 2406 | default: |
| 2407 | printf (_(" (Unknown inline attribute value: %s)"), |
| 2408 | dwarf_vmatoa ("x", uvalue)); |
| 2409 | break; |
| 2410 | } |
| 2411 | break; |
| 2412 | |
| 2413 | case DW_AT_language: |
| 2414 | printf ("\t"); |
| 2415 | switch (uvalue) |
| 2416 | { |
| 2417 | /* Ordered by the numeric value of these constants. */ |
| 2418 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
| 2419 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
| 2420 | case DW_LANG_Ada83: printf ("(Ada)"); break; |
| 2421 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
| 2422 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
| 2423 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; |
| 2424 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
| 2425 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; |
| 2426 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
| 2427 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
| 2428 | /* DWARF 2.1 values. */ |
| 2429 | case DW_LANG_Java: printf ("(Java)"); break; |
| 2430 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
| 2431 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; |
| 2432 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; |
| 2433 | /* DWARF 3 values. */ |
| 2434 | case DW_LANG_PLI: printf ("(PLI)"); break; |
| 2435 | case DW_LANG_ObjC: printf ("(Objective C)"); break; |
| 2436 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; |
| 2437 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; |
| 2438 | case DW_LANG_D: printf ("(D)"); break; |
| 2439 | /* DWARF 4 values. */ |
| 2440 | case DW_LANG_Python: printf ("(Python)"); break; |
| 2441 | /* DWARF 5 values. */ |
| 2442 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
| 2443 | case DW_LANG_Go: printf ("(Go)"); break; |
| 2444 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
| 2445 | case DW_LANG_Haskell: printf ("(Haskell)"); break; |
| 2446 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; |
| 2447 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
| 2448 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
| 2449 | case DW_LANG_Rust: printf ("(Rust)"); break; |
| 2450 | case DW_LANG_C11: printf ("(C11)"); break; |
| 2451 | case DW_LANG_Swift: printf ("(Swift)"); break; |
| 2452 | case DW_LANG_Julia: printf ("(Julia)"); break; |
| 2453 | case DW_LANG_Dylan: printf ("(Dylan)"); break; |
| 2454 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
| 2455 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
| 2456 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; |
| 2457 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
| 2458 | /* MIPS extension. */ |
| 2459 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; |
| 2460 | /* UPC extension. */ |
| 2461 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; |
| 2462 | default: |
| 2463 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
| 2464 | printf (_("(implementation defined: %s)"), |
| 2465 | dwarf_vmatoa ("x", uvalue)); |
| 2466 | else |
| 2467 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
| 2468 | break; |
| 2469 | } |
| 2470 | break; |
| 2471 | |
| 2472 | case DW_AT_encoding: |
| 2473 | printf ("\t"); |
| 2474 | switch (uvalue) |
| 2475 | { |
| 2476 | case DW_ATE_void: printf ("(void)"); break; |
| 2477 | case DW_ATE_address: printf ("(machine address)"); break; |
| 2478 | case DW_ATE_boolean: printf ("(boolean)"); break; |
| 2479 | case DW_ATE_complex_float: printf ("(complex float)"); break; |
| 2480 | case DW_ATE_float: printf ("(float)"); break; |
| 2481 | case DW_ATE_signed: printf ("(signed)"); break; |
| 2482 | case DW_ATE_signed_char: printf ("(signed char)"); break; |
| 2483 | case DW_ATE_unsigned: printf ("(unsigned)"); break; |
| 2484 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; |
| 2485 | /* DWARF 2.1 values: */ |
| 2486 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
| 2487 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; |
| 2488 | /* DWARF 3 values: */ |
| 2489 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; |
| 2490 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; |
| 2491 | case DW_ATE_edited: printf ("(edited)"); break; |
| 2492 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; |
| 2493 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; |
| 2494 | /* DWARF 4 values: */ |
| 2495 | case DW_ATE_UTF: printf ("(unicode string)"); break; |
| 2496 | /* DWARF 5 values: */ |
| 2497 | case DW_ATE_UCS: printf ("(UCS)"); break; |
| 2498 | case DW_ATE_ASCII: printf ("(ASCII)"); break; |
| 2499 | |
| 2500 | /* HP extensions: */ |
| 2501 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; |
| 2502 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; |
| 2503 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; |
| 2504 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; |
| 2505 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; |
| 2506 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; |
| 2507 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; |
| 2508 | |
| 2509 | default: |
| 2510 | if (uvalue >= DW_ATE_lo_user |
| 2511 | && uvalue <= DW_ATE_hi_user) |
| 2512 | printf (_("(user defined type)")); |
| 2513 | else |
| 2514 | printf (_("(unknown type)")); |
| 2515 | break; |
| 2516 | } |
| 2517 | break; |
| 2518 | |
| 2519 | case DW_AT_accessibility: |
| 2520 | printf ("\t"); |
| 2521 | switch (uvalue) |
| 2522 | { |
| 2523 | case DW_ACCESS_public: printf ("(public)"); break; |
| 2524 | case DW_ACCESS_protected: printf ("(protected)"); break; |
| 2525 | case DW_ACCESS_private: printf ("(private)"); break; |
| 2526 | default: |
| 2527 | printf (_("(unknown accessibility)")); |
| 2528 | break; |
| 2529 | } |
| 2530 | break; |
| 2531 | |
| 2532 | case DW_AT_visibility: |
| 2533 | printf ("\t"); |
| 2534 | switch (uvalue) |
| 2535 | { |
| 2536 | case DW_VIS_local: printf ("(local)"); break; |
| 2537 | case DW_VIS_exported: printf ("(exported)"); break; |
| 2538 | case DW_VIS_qualified: printf ("(qualified)"); break; |
| 2539 | default: printf (_("(unknown visibility)")); break; |
| 2540 | } |
| 2541 | break; |
| 2542 | |
| 2543 | case DW_AT_endianity: |
| 2544 | printf ("\t"); |
| 2545 | switch (uvalue) |
| 2546 | { |
| 2547 | case DW_END_default: printf ("(default)"); break; |
| 2548 | case DW_END_big: printf ("(big)"); break; |
| 2549 | case DW_END_little: printf ("(little)"); break; |
| 2550 | default: |
| 2551 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) |
| 2552 | printf (_("(user specified)")); |
| 2553 | else |
| 2554 | printf (_("(unknown endianity)")); |
| 2555 | break; |
| 2556 | } |
| 2557 | break; |
| 2558 | |
| 2559 | case DW_AT_virtuality: |
| 2560 | printf ("\t"); |
| 2561 | switch (uvalue) |
| 2562 | { |
| 2563 | case DW_VIRTUALITY_none: printf ("(none)"); break; |
| 2564 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; |
| 2565 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; |
| 2566 | default: printf (_("(unknown virtuality)")); break; |
| 2567 | } |
| 2568 | break; |
| 2569 | |
| 2570 | case DW_AT_identifier_case: |
| 2571 | printf ("\t"); |
| 2572 | switch (uvalue) |
| 2573 | { |
| 2574 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; |
| 2575 | case DW_ID_up_case: printf ("(up_case)"); break; |
| 2576 | case DW_ID_down_case: printf ("(down_case)"); break; |
| 2577 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; |
| 2578 | default: printf (_("(unknown case)")); break; |
| 2579 | } |
| 2580 | break; |
| 2581 | |
| 2582 | case DW_AT_calling_convention: |
| 2583 | printf ("\t"); |
| 2584 | switch (uvalue) |
| 2585 | { |
| 2586 | case DW_CC_normal: printf ("(normal)"); break; |
| 2587 | case DW_CC_program: printf ("(program)"); break; |
| 2588 | case DW_CC_nocall: printf ("(nocall)"); break; |
| 2589 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
| 2590 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; |
| 2591 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; |
| 2592 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; |
| 2593 | default: |
| 2594 | if (uvalue >= DW_CC_lo_user |
| 2595 | && uvalue <= DW_CC_hi_user) |
| 2596 | printf (_("(user defined)")); |
| 2597 | else |
| 2598 | printf (_("(unknown convention)")); |
| 2599 | } |
| 2600 | break; |
| 2601 | |
| 2602 | case DW_AT_ordering: |
| 2603 | printf ("\t"); |
| 2604 | switch (uvalue) |
| 2605 | { |
| 2606 | case 255: |
| 2607 | case -1: printf (_("(undefined)")); break; |
| 2608 | case 0: printf ("(row major)"); break; |
| 2609 | case 1: printf ("(column major)"); break; |
| 2610 | } |
| 2611 | break; |
| 2612 | |
| 2613 | case DW_AT_decimal_sign: |
| 2614 | printf ("\t"); |
| 2615 | switch (uvalue) |
| 2616 | { |
| 2617 | case DW_DS_unsigned: printf (_("(unsigned)")); break; |
| 2618 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; |
| 2619 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; |
| 2620 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; |
| 2621 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; |
| 2622 | default: printf (_("(unrecognised)")); break; |
| 2623 | } |
| 2624 | break; |
| 2625 | |
| 2626 | case DW_AT_defaulted: |
| 2627 | printf ("\t"); |
| 2628 | switch (uvalue) |
| 2629 | { |
| 2630 | case DW_DEFAULTED_no: printf (_("(no)")); break; |
| 2631 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; |
| 2632 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; |
| 2633 | default: printf (_("(unrecognised)")); break; |
| 2634 | } |
| 2635 | break; |
| 2636 | |
| 2637 | case DW_AT_discr_list: |
| 2638 | printf ("\t"); |
| 2639 | switch (uvalue) |
| 2640 | { |
| 2641 | case DW_DSC_label: printf (_("(label)")); break; |
| 2642 | case DW_DSC_range: printf (_("(range)")); break; |
| 2643 | default: printf (_("(unrecognised)")); break; |
| 2644 | } |
| 2645 | break; |
| 2646 | |
| 2647 | case DW_AT_frame_base: |
| 2648 | have_frame_base = 1; |
| 2649 | /* Fall through. */ |
| 2650 | case DW_AT_location: |
| 2651 | case DW_AT_string_length: |
| 2652 | case DW_AT_return_addr: |
| 2653 | case DW_AT_data_member_location: |
| 2654 | case DW_AT_vtable_elem_location: |
| 2655 | case DW_AT_segment: |
| 2656 | case DW_AT_static_link: |
| 2657 | case DW_AT_use_location: |
| 2658 | case DW_AT_call_value: |
| 2659 | case DW_AT_GNU_call_site_value: |
| 2660 | case DW_AT_call_data_value: |
| 2661 | case DW_AT_GNU_call_site_data_value: |
| 2662 | case DW_AT_call_target: |
| 2663 | case DW_AT_GNU_call_site_target: |
| 2664 | case DW_AT_call_target_clobbered: |
| 2665 | case DW_AT_GNU_call_site_target_clobbered: |
| 2666 | if ((dwarf_version < 4 |
| 2667 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| 2668 | || form == DW_FORM_sec_offset) |
| 2669 | printf (_(" (location list)")); |
| 2670 | /* Fall through. */ |
| 2671 | case DW_AT_allocated: |
| 2672 | case DW_AT_associated: |
| 2673 | case DW_AT_data_location: |
| 2674 | case DW_AT_stride: |
| 2675 | case DW_AT_upper_bound: |
| 2676 | case DW_AT_lower_bound: |
| 2677 | if (block_start) |
| 2678 | { |
| 2679 | int need_frame_base; |
| 2680 | |
| 2681 | printf ("\t("); |
| 2682 | need_frame_base = decode_location_expression (block_start, |
| 2683 | pointer_size, |
| 2684 | offset_size, |
| 2685 | dwarf_version, |
| 2686 | uvalue, |
| 2687 | cu_offset, section); |
| 2688 | printf (")"); |
| 2689 | if (need_frame_base && !have_frame_base) |
| 2690 | printf (_(" [without DW_AT_frame_base]")); |
| 2691 | } |
| 2692 | break; |
| 2693 | |
| 2694 | case DW_AT_data_bit_offset: |
| 2695 | case DW_AT_byte_size: |
| 2696 | case DW_AT_bit_size: |
| 2697 | case DW_AT_string_length_byte_size: |
| 2698 | case DW_AT_string_length_bit_size: |
| 2699 | case DW_AT_bit_stride: |
| 2700 | if (form == DW_FORM_exprloc) |
| 2701 | { |
| 2702 | printf ("\t("); |
| 2703 | (void) decode_location_expression (block_start, pointer_size, |
| 2704 | offset_size, dwarf_version, |
| 2705 | uvalue, cu_offset, section); |
| 2706 | printf (")"); |
| 2707 | } |
| 2708 | break; |
| 2709 | |
| 2710 | case DW_AT_import: |
| 2711 | { |
| 2712 | if (form == DW_FORM_ref_sig8 |
| 2713 | || form == DW_FORM_GNU_ref_alt) |
| 2714 | break; |
| 2715 | |
| 2716 | if (form == DW_FORM_ref1 |
| 2717 | || form == DW_FORM_ref2 |
| 2718 | || form == DW_FORM_ref4 |
| 2719 | || form == DW_FORM_ref_udata) |
| 2720 | uvalue += cu_offset; |
| 2721 | |
| 2722 | if (uvalue >= section->size) |
| 2723 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
| 2724 | dwarf_vmatoa ("x", uvalue), |
| 2725 | (unsigned long) (orig_data - section->start)); |
| 2726 | else |
| 2727 | { |
| 2728 | unsigned long abbrev_number; |
| 2729 | abbrev_entry * entry; |
| 2730 | |
| 2731 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
| 2732 | |
| 2733 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
| 2734 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
| 2735 | use different abbrev table, and we don't track .debug_info chunks |
| 2736 | yet. */ |
| 2737 | if (form != DW_FORM_ref_addr) |
| 2738 | { |
| 2739 | for (entry = first_abbrev; entry != NULL; entry = entry->next) |
| 2740 | if (entry->entry == abbrev_number) |
| 2741 | break; |
| 2742 | if (entry != NULL) |
| 2743 | printf (" (%s)", get_TAG_name (entry->tag)); |
| 2744 | } |
| 2745 | printf ("]"); |
| 2746 | } |
| 2747 | } |
| 2748 | break; |
| 2749 | |
| 2750 | default: |
| 2751 | break; |
| 2752 | } |
| 2753 | |
| 2754 | return data; |
| 2755 | } |
| 2756 | |
| 2757 | static unsigned char * |
| 2758 | read_and_display_attr (unsigned long attribute, |
| 2759 | unsigned long form, |
| 2760 | dwarf_signed_vma implicit_const, |
| 2761 | unsigned char * data, |
| 2762 | unsigned char * end, |
| 2763 | dwarf_vma cu_offset, |
| 2764 | dwarf_vma pointer_size, |
| 2765 | dwarf_vma offset_size, |
| 2766 | int dwarf_version, |
| 2767 | debug_info * debug_info_p, |
| 2768 | int do_loc, |
| 2769 | struct dwarf_section * section, |
| 2770 | struct cu_tu_set * this_set) |
| 2771 | { |
| 2772 | if (!do_loc) |
| 2773 | printf (" %-18s:", get_AT_name (attribute)); |
| 2774 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
| 2775 | cu_offset, pointer_size, offset_size, |
| 2776 | dwarf_version, debug_info_p, |
| 2777 | do_loc, section, this_set, ' '); |
| 2778 | if (!do_loc) |
| 2779 | printf ("\n"); |
| 2780 | return data; |
| 2781 | } |
| 2782 | |
| 2783 | /* Like load_debug_section, but if the ordinary call fails, and we are |
| 2784 | following debug links, then attempt to load the requested section |
| 2785 | from one of the separate debug info files. */ |
| 2786 | |
| 2787 | static bfd_boolean |
| 2788 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
| 2789 | void * handle) |
| 2790 | { |
| 2791 | if (load_debug_section (sec_enum, handle)) |
| 2792 | { |
| 2793 | if (debug_displays[sec_enum].section.filename == NULL) |
| 2794 | { |
| 2795 | /* See if we can associate a filename with this section. */ |
| 2796 | separate_info * i; |
| 2797 | |
| 2798 | for (i = first_separate_info; i != NULL; i = i->next) |
| 2799 | if (i->handle == handle) |
| 2800 | { |
| 2801 | debug_displays[sec_enum].section.filename = i->filename; |
| 2802 | break; |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | return TRUE; |
| 2807 | } |
| 2808 | |
| 2809 | if (do_follow_links) |
| 2810 | { |
| 2811 | separate_info * i; |
| 2812 | |
| 2813 | for (i = first_separate_info; i != NULL; i = i->next) |
| 2814 | { |
| 2815 | if (load_debug_section (sec_enum, i->handle)) |
| 2816 | { |
| 2817 | debug_displays[sec_enum].section.filename = i->filename; |
| 2818 | |
| 2819 | /* FIXME: We should check to see if any of the remaining debug info |
| 2820 | files also contain this section, and, umm, do something about it. */ |
| 2821 | return TRUE; |
| 2822 | } |
| 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | return FALSE; |
| 2827 | } |
| 2828 | |
| 2829 | static void |
| 2830 | introduce (struct dwarf_section * section, bfd_boolean raw) |
| 2831 | { |
| 2832 | if (raw) |
| 2833 | { |
| 2834 | if (do_follow_links && section->filename) |
| 2835 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), |
| 2836 | section->name, section->filename); |
| 2837 | else |
| 2838 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); |
| 2839 | } |
| 2840 | else |
| 2841 | { |
| 2842 | if (do_follow_links && section->filename) |
| 2843 | printf (_("Contents of the %s section (loaded from %s):\n\n"), |
| 2844 | section->name, section->filename); |
| 2845 | else |
| 2846 | printf (_("Contents of the %s section:\n\n"), section->name); |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | /* Process the contents of a .debug_info section. |
| 2851 | If do_loc is TRUE then we are scanning for location lists and dwo tags |
| 2852 | and we do not want to display anything to the user. |
| 2853 | If do_types is TRUE, we are processing a .debug_types section instead of |
| 2854 | a .debug_info section. |
| 2855 | The information displayed is restricted by the values in DWARF_START_DIE |
| 2856 | and DWARF_CUTOFF_LEVEL. |
| 2857 | Returns TRUE upon success. Otherwise an error or warning message is |
| 2858 | printed and FALSE is returned. */ |
| 2859 | |
| 2860 | static bfd_boolean |
| 2861 | process_debug_info (struct dwarf_section * section, |
| 2862 | void * file, |
| 2863 | enum dwarf_section_display_enum abbrev_sec, |
| 2864 | bfd_boolean do_loc, |
| 2865 | bfd_boolean do_types) |
| 2866 | { |
| 2867 | unsigned char *start = section->start; |
| 2868 | unsigned char *end = start + section->size; |
| 2869 | unsigned char *section_begin; |
| 2870 | unsigned int unit; |
| 2871 | unsigned int num_units = 0; |
| 2872 | |
| 2873 | if ((do_loc || do_debug_loc || do_debug_ranges) |
| 2874 | && num_debug_info_entries == 0 |
| 2875 | && ! do_types) |
| 2876 | { |
| 2877 | dwarf_vma length; |
| 2878 | |
| 2879 | /* First scan the section to get the number of comp units. */ |
| 2880 | for (section_begin = start, num_units = 0; section_begin < end; |
| 2881 | num_units ++) |
| 2882 | { |
| 2883 | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
| 2884 | will be the length. For a 64-bit DWARF section, it'll be |
| 2885 | the escape code 0xffffffff followed by an 8 byte length. */ |
| 2886 | SAFE_BYTE_GET (length, section_begin, 4, end); |
| 2887 | |
| 2888 | if (length == 0xffffffff) |
| 2889 | { |
| 2890 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
| 2891 | section_begin += length + 12; |
| 2892 | } |
| 2893 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
| 2894 | { |
| 2895 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
| 2896 | dwarf_vmatoa ("x", length), section->name); |
| 2897 | return FALSE; |
| 2898 | } |
| 2899 | else |
| 2900 | section_begin += length + 4; |
| 2901 | |
| 2902 | /* Negative values are illegal, they may even cause infinite |
| 2903 | looping. This can happen if we can't accurately apply |
| 2904 | relocations to an object file, or if the file is corrupt. */ |
| 2905 | if ((signed long) length <= 0 || section_begin < start) |
| 2906 | { |
| 2907 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
| 2908 | dwarf_vmatoa ("x", length), section->name); |
| 2909 | return FALSE; |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | if (num_units == 0) |
| 2914 | { |
| 2915 | error (_("No comp units in %s section ?\n"), section->name); |
| 2916 | return FALSE; |
| 2917 | } |
| 2918 | |
| 2919 | /* Then allocate an array to hold the information. */ |
| 2920 | debug_information = (debug_info *) cmalloc (num_units, |
| 2921 | sizeof (* debug_information)); |
| 2922 | if (debug_information == NULL) |
| 2923 | { |
| 2924 | error (_("Not enough memory for a debug info array of %u entries\n"), |
| 2925 | num_units); |
| 2926 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
| 2927 | return FALSE; |
| 2928 | } |
| 2929 | |
| 2930 | /* PR 17531: file: 92ca3797. |
| 2931 | We cannot rely upon the debug_information array being initialised |
| 2932 | before it is used. A corrupt file could easily contain references |
| 2933 | to a unit for which information has not been made available. So |
| 2934 | we ensure that the array is zeroed here. */ |
| 2935 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
| 2936 | |
| 2937 | alloc_num_debug_info_entries = num_units; |
| 2938 | } |
| 2939 | |
| 2940 | if (!do_loc) |
| 2941 | { |
| 2942 | load_debug_section_with_follow (str, file); |
| 2943 | load_debug_section_with_follow (line_str, file); |
| 2944 | load_debug_section_with_follow (str_dwo, file); |
| 2945 | load_debug_section_with_follow (str_index, file); |
| 2946 | load_debug_section_with_follow (str_index_dwo, file); |
| 2947 | load_debug_section_with_follow (debug_addr, file); |
| 2948 | } |
| 2949 | |
| 2950 | load_debug_section_with_follow (abbrev_sec, file); |
| 2951 | if (debug_displays [abbrev_sec].section.start == NULL) |
| 2952 | { |
| 2953 | warn (_("Unable to locate %s section!\n"), |
| 2954 | debug_displays [abbrev_sec].section.uncompressed_name); |
| 2955 | return FALSE; |
| 2956 | } |
| 2957 | |
| 2958 | if (!do_loc && dwarf_start_die == 0) |
| 2959 | introduce (section, FALSE); |
| 2960 | |
| 2961 | for (section_begin = start, unit = 0; start < end; unit++) |
| 2962 | { |
| 2963 | DWARF2_Internal_CompUnit compunit; |
| 2964 | unsigned char *hdrptr; |
| 2965 | unsigned char *tags; |
| 2966 | int level, last_level, saved_level; |
| 2967 | dwarf_vma cu_offset; |
| 2968 | unsigned long sec_off; |
| 2969 | unsigned int offset_size; |
| 2970 | unsigned int initial_length_size; |
| 2971 | dwarf_vma signature_high = 0; |
| 2972 | dwarf_vma signature_low = 0; |
| 2973 | dwarf_vma type_offset = 0; |
| 2974 | struct cu_tu_set *this_set; |
| 2975 | dwarf_vma abbrev_base; |
| 2976 | size_t abbrev_size; |
| 2977 | |
| 2978 | hdrptr = start; |
| 2979 | |
| 2980 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
| 2981 | |
| 2982 | if (compunit.cu_length == 0xffffffff) |
| 2983 | { |
| 2984 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
| 2985 | offset_size = 8; |
| 2986 | initial_length_size = 12; |
| 2987 | } |
| 2988 | else |
| 2989 | { |
| 2990 | offset_size = 4; |
| 2991 | initial_length_size = 4; |
| 2992 | } |
| 2993 | |
| 2994 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
| 2995 | |
| 2996 | cu_offset = start - section_begin; |
| 2997 | |
| 2998 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
| 2999 | |
| 3000 | if (compunit.cu_version < 5) |
| 3001 | { |
| 3002 | compunit.cu_unit_type = DW_UT_compile; |
| 3003 | /* Initialize it due to a false compiler warning. */ |
| 3004 | compunit.cu_pointer_size = -1; |
| 3005 | } |
| 3006 | else |
| 3007 | { |
| 3008 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); |
| 3009 | do_types = (compunit.cu_unit_type == DW_UT_type); |
| 3010 | |
| 3011 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); |
| 3012 | } |
| 3013 | |
| 3014 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
| 3015 | |
| 3016 | if (this_set == NULL) |
| 3017 | { |
| 3018 | abbrev_base = 0; |
| 3019 | abbrev_size = debug_displays [abbrev_sec].section.size; |
| 3020 | } |
| 3021 | else |
| 3022 | { |
| 3023 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
| 3024 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
| 3025 | } |
| 3026 | |
| 3027 | if (compunit.cu_version < 5) |
| 3028 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); |
| 3029 | |
| 3030 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
| 3031 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) |
| 3032 | { |
| 3033 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), |
| 3034 | compunit.cu_pointer_size, offset_size); |
| 3035 | compunit.cu_pointer_size = offset_size; |
| 3036 | } |
| 3037 | |
| 3038 | if (do_types) |
| 3039 | { |
| 3040 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
| 3041 | hdrptr += 8; |
| 3042 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
| 3043 | } |
| 3044 | |
| 3045 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
| 3046 | + initial_length_size)) |
| 3047 | { |
| 3048 | start = section_begin + cu_offset + compunit.cu_length |
| 3049 | + initial_length_size; |
| 3050 | continue; |
| 3051 | } |
| 3052 | |
| 3053 | if ((do_loc || do_debug_loc || do_debug_ranges) |
| 3054 | && num_debug_info_entries == 0 |
| 3055 | && ! do_types) |
| 3056 | { |
| 3057 | debug_information [unit].cu_offset = cu_offset; |
| 3058 | debug_information [unit].pointer_size |
| 3059 | = compunit.cu_pointer_size; |
| 3060 | debug_information [unit].offset_size = offset_size; |
| 3061 | debug_information [unit].dwarf_version = compunit.cu_version; |
| 3062 | debug_information [unit].base_address = 0; |
| 3063 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
| 3064 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; |
| 3065 | debug_information [unit].loc_offsets = NULL; |
| 3066 | debug_information [unit].have_frame_base = NULL; |
| 3067 | debug_information [unit].max_loc_offsets = 0; |
| 3068 | debug_information [unit].num_loc_offsets = 0; |
| 3069 | debug_information [unit].range_lists = NULL; |
| 3070 | debug_information [unit].max_range_lists= 0; |
| 3071 | debug_information [unit].num_range_lists = 0; |
| 3072 | } |
| 3073 | |
| 3074 | if (!do_loc && dwarf_start_die == 0) |
| 3075 | { |
| 3076 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
| 3077 | dwarf_vmatoa ("x", cu_offset)); |
| 3078 | printf (_(" Length: 0x%s (%s)\n"), |
| 3079 | dwarf_vmatoa ("x", compunit.cu_length), |
| 3080 | offset_size == 8 ? "64-bit" : "32-bit"); |
| 3081 | printf (_(" Version: %d\n"), compunit.cu_version); |
| 3082 | printf (_(" Abbrev Offset: 0x%s\n"), |
| 3083 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); |
| 3084 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
| 3085 | if (do_types) |
| 3086 | { |
| 3087 | char buf[64]; |
| 3088 | |
| 3089 | printf (_(" Signature: 0x%s\n"), |
| 3090 | dwarf_vmatoa64 (signature_high, signature_low, |
| 3091 | buf, sizeof (buf))); |
| 3092 | printf (_(" Type Offset: 0x%s\n"), |
| 3093 | dwarf_vmatoa ("x", type_offset)); |
| 3094 | } |
| 3095 | if (this_set != NULL) |
| 3096 | { |
| 3097 | dwarf_vma *offsets = this_set->section_offsets; |
| 3098 | size_t *sizes = this_set->section_sizes; |
| 3099 | |
| 3100 | printf (_(" Section contributions:\n")); |
| 3101 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), |
| 3102 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), |
| 3103 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); |
| 3104 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), |
| 3105 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), |
| 3106 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); |
| 3107 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), |
| 3108 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), |
| 3109 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); |
| 3110 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), |
| 3111 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), |
| 3112 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | sec_off = cu_offset + initial_length_size; |
| 3117 | if (sec_off + compunit.cu_length < sec_off |
| 3118 | || sec_off + compunit.cu_length > section->size) |
| 3119 | { |
| 3120 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
| 3121 | section->name, |
| 3122 | (unsigned long) cu_offset, |
| 3123 | dwarf_vmatoa ("x", compunit.cu_length)); |
| 3124 | num_units = unit; |
| 3125 | break; |
| 3126 | } |
| 3127 | |
| 3128 | tags = hdrptr; |
| 3129 | start += compunit.cu_length + initial_length_size; |
| 3130 | |
| 3131 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
| 3132 | { |
| 3133 | warn (_("CU at offset %s contains corrupt or " |
| 3134 | "unsupported version number: %d.\n"), |
| 3135 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); |
| 3136 | continue; |
| 3137 | } |
| 3138 | |
| 3139 | if (compunit.cu_unit_type != DW_UT_compile |
| 3140 | && compunit.cu_unit_type != DW_UT_type) |
| 3141 | { |
| 3142 | warn (_("CU at offset %s contains corrupt or " |
| 3143 | "unsupported unit type: %d.\n"), |
| 3144 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); |
| 3145 | continue; |
| 3146 | } |
| 3147 | |
| 3148 | free_abbrevs (); |
| 3149 | |
| 3150 | /* Process the abbrevs used by this compilation unit. */ |
| 3151 | if (compunit.cu_abbrev_offset >= abbrev_size) |
| 3152 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
| 3153 | (unsigned long) compunit.cu_abbrev_offset, |
| 3154 | (unsigned long) abbrev_size); |
| 3155 | /* PR 17531: file:4bcd9ce9. */ |
| 3156 | else if ((abbrev_base + abbrev_size) |
| 3157 | > debug_displays [abbrev_sec].section.size) |
| 3158 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), |
| 3159 | (unsigned long) abbrev_base + abbrev_size, |
| 3160 | (unsigned long) debug_displays [abbrev_sec].section.size); |
| 3161 | else |
| 3162 | process_abbrev_section |
| 3163 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
| 3164 | + abbrev_base + compunit.cu_abbrev_offset), |
| 3165 | ((unsigned char *) debug_displays [abbrev_sec].section.start |
| 3166 | + abbrev_base + abbrev_size)); |
| 3167 | |
| 3168 | level = 0; |
| 3169 | last_level = level; |
| 3170 | saved_level = -1; |
| 3171 | while (tags < start) |
| 3172 | { |
| 3173 | unsigned int bytes_read; |
| 3174 | unsigned long abbrev_number; |
| 3175 | unsigned long die_offset; |
| 3176 | abbrev_entry *entry; |
| 3177 | abbrev_attr *attr; |
| 3178 | int do_printing = 1; |
| 3179 | |
| 3180 | die_offset = tags - section_begin; |
| 3181 | |
| 3182 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
| 3183 | tags += bytes_read; |
| 3184 | |
| 3185 | /* A null DIE marks the end of a list of siblings or it may also be |
| 3186 | a section padding. */ |
| 3187 | if (abbrev_number == 0) |
| 3188 | { |
| 3189 | /* Check if it can be a section padding for the last CU. */ |
| 3190 | if (level == 0 && start == end) |
| 3191 | { |
| 3192 | unsigned char *chk; |
| 3193 | |
| 3194 | for (chk = tags; chk < start; chk++) |
| 3195 | if (*chk != 0) |
| 3196 | break; |
| 3197 | if (chk == start) |
| 3198 | break; |
| 3199 | } |
| 3200 | |
| 3201 | if (!do_loc && die_offset >= dwarf_start_die |
| 3202 | && (dwarf_cutoff_level == -1 |
| 3203 | || level < dwarf_cutoff_level)) |
| 3204 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
| 3205 | level, die_offset); |
| 3206 | |
| 3207 | --level; |
| 3208 | if (level < 0) |
| 3209 | { |
| 3210 | static unsigned num_bogus_warns = 0; |
| 3211 | |
| 3212 | if (num_bogus_warns < 3) |
| 3213 | { |
| 3214 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
| 3215 | die_offset, section->name); |
| 3216 | num_bogus_warns ++; |
| 3217 | if (num_bogus_warns == 3) |
| 3218 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); |
| 3219 | } |
| 3220 | } |
| 3221 | if (dwarf_start_die != 0 && level < saved_level) |
| 3222 | return TRUE; |
| 3223 | continue; |
| 3224 | } |
| 3225 | |
| 3226 | if (!do_loc) |
| 3227 | { |
| 3228 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) |
| 3229 | do_printing = 0; |
| 3230 | else |
| 3231 | { |
| 3232 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) |
| 3233 | saved_level = level; |
| 3234 | do_printing = (dwarf_cutoff_level == -1 |
| 3235 | || level < dwarf_cutoff_level); |
| 3236 | if (do_printing) |
| 3237 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), |
| 3238 | level, die_offset, abbrev_number); |
| 3239 | else if (dwarf_cutoff_level == -1 |
| 3240 | || last_level < dwarf_cutoff_level) |
| 3241 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); |
| 3242 | last_level = level; |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | /* Scan through the abbreviation list until we reach the |
| 3247 | correct entry. */ |
| 3248 | for (entry = first_abbrev; |
| 3249 | entry && entry->entry != abbrev_number; |
| 3250 | entry = entry->next) |
| 3251 | continue; |
| 3252 | |
| 3253 | if (entry == NULL) |
| 3254 | { |
| 3255 | if (!do_loc && do_printing) |
| 3256 | { |
| 3257 | printf ("\n"); |
| 3258 | fflush (stdout); |
| 3259 | } |
| 3260 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
| 3261 | die_offset, abbrev_number); |
| 3262 | return FALSE; |
| 3263 | } |
| 3264 | |
| 3265 | if (!do_loc && do_printing) |
| 3266 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
| 3267 | |
| 3268 | switch (entry->tag) |
| 3269 | { |
| 3270 | default: |
| 3271 | need_base_address = 0; |
| 3272 | break; |
| 3273 | case DW_TAG_compile_unit: |
| 3274 | need_base_address = 1; |
| 3275 | need_dwo_info = do_loc; |
| 3276 | break; |
| 3277 | case DW_TAG_entry_point: |
| 3278 | case DW_TAG_subprogram: |
| 3279 | need_base_address = 0; |
| 3280 | /* Assuming that there is no DW_AT_frame_base. */ |
| 3281 | have_frame_base = 0; |
| 3282 | break; |
| 3283 | } |
| 3284 | |
| 3285 | debug_info *debug_info_p = |
| 3286 | (debug_information && unit < alloc_num_debug_info_entries) |
| 3287 | ? debug_information + unit : NULL; |
| 3288 | |
| 3289 | assert (!debug_info_p |
| 3290 | || (debug_info_p->num_loc_offsets |
| 3291 | == debug_info_p->num_loc_views)); |
| 3292 | |
| 3293 | for (attr = entry->first_attr; |
| 3294 | attr && attr->attribute; |
| 3295 | attr = attr->next) |
| 3296 | { |
| 3297 | if (! do_loc && do_printing) |
| 3298 | /* Show the offset from where the tag was extracted. */ |
| 3299 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
| 3300 | tags = read_and_display_attr (attr->attribute, |
| 3301 | attr->form, |
| 3302 | attr->implicit_const, |
| 3303 | tags, |
| 3304 | end, |
| 3305 | cu_offset, |
| 3306 | compunit.cu_pointer_size, |
| 3307 | offset_size, |
| 3308 | compunit.cu_version, |
| 3309 | debug_info_p, |
| 3310 | do_loc || ! do_printing, |
| 3311 | section, |
| 3312 | this_set); |
| 3313 | } |
| 3314 | |
| 3315 | /* If a locview attribute appears before a location one, |
| 3316 | make sure we don't associate it with an earlier |
| 3317 | loclist. */ |
| 3318 | if (debug_info_p) |
| 3319 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) |
| 3320 | { |
| 3321 | case 1: |
| 3322 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; |
| 3323 | debug_info_p->num_loc_views++; |
| 3324 | assert (debug_info_p->num_loc_views |
| 3325 | == debug_info_p->num_loc_offsets); |
| 3326 | break; |
| 3327 | |
| 3328 | case 0: |
| 3329 | break; |
| 3330 | |
| 3331 | case -1: |
| 3332 | warn(_("DIE has locviews without loclist\n")); |
| 3333 | debug_info_p->num_loc_views--; |
| 3334 | break; |
| 3335 | |
| 3336 | default: |
| 3337 | assert (0); |
| 3338 | } |
| 3339 | |
| 3340 | if (entry->children) |
| 3341 | ++level; |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | /* Set num_debug_info_entries here so that it can be used to check if |
| 3346 | we need to process .debug_loc and .debug_ranges sections. */ |
| 3347 | if ((do_loc || do_debug_loc || do_debug_ranges) |
| 3348 | && num_debug_info_entries == 0 |
| 3349 | && ! do_types) |
| 3350 | { |
| 3351 | if (num_units > alloc_num_debug_info_entries) |
| 3352 | num_debug_info_entries = alloc_num_debug_info_entries; |
| 3353 | else |
| 3354 | num_debug_info_entries = num_units; |
| 3355 | } |
| 3356 | |
| 3357 | if (!do_loc) |
| 3358 | printf ("\n"); |
| 3359 | |
| 3360 | return TRUE; |
| 3361 | } |
| 3362 | |
| 3363 | /* Locate and scan the .debug_info section in the file and record the pointer |
| 3364 | sizes and offsets for the compilation units in it. Usually an executable |
| 3365 | will have just one pointer size, but this is not guaranteed, and so we try |
| 3366 | not to make any assumptions. Returns zero upon failure, or the number of |
| 3367 | compilation units upon success. */ |
| 3368 | |
| 3369 | static unsigned int |
| 3370 | load_debug_info (void * file) |
| 3371 | { |
| 3372 | /* If we have already tried and failed to load the .debug_info |
| 3373 | section then do not bother to repeat the task. */ |
| 3374 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
| 3375 | return 0; |
| 3376 | |
| 3377 | /* If we already have the information there is nothing else to do. */ |
| 3378 | if (num_debug_info_entries > 0) |
| 3379 | return num_debug_info_entries; |
| 3380 | |
| 3381 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
| 3382 | (void) load_cu_tu_indexes (file); |
| 3383 | |
| 3384 | if (load_debug_section_with_follow (info, file) |
| 3385 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
| 3386 | return num_debug_info_entries; |
| 3387 | |
| 3388 | if (load_debug_section_with_follow (info_dwo, file) |
| 3389 | && process_debug_info (&debug_displays [info_dwo].section, file, |
| 3390 | abbrev_dwo, TRUE, FALSE)) |
| 3391 | return num_debug_info_entries; |
| 3392 | |
| 3393 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
| 3394 | return 0; |
| 3395 | } |
| 3396 | |
| 3397 | /* Read a DWARF .debug_line section header starting at DATA. |
| 3398 | Upon success returns an updated DATA pointer and the LINFO |
| 3399 | structure and the END_OF_SEQUENCE pointer will be filled in. |
| 3400 | Otherwise returns NULL. */ |
| 3401 | |
| 3402 | static unsigned char * |
| 3403 | read_debug_line_header (struct dwarf_section * section, |
| 3404 | unsigned char * data, |
| 3405 | unsigned char * end, |
| 3406 | DWARF2_Internal_LineInfo * linfo, |
| 3407 | unsigned char ** end_of_sequence) |
| 3408 | { |
| 3409 | unsigned char *hdrptr; |
| 3410 | unsigned int initial_length_size; |
| 3411 | unsigned char address_size, segment_selector_size; |
| 3412 | |
| 3413 | /* Extract information from the Line Number Program Header. |
| 3414 | (section 6.2.4 in the Dwarf3 doc). */ |
| 3415 | hdrptr = data; |
| 3416 | |
| 3417 | /* Get and check the length of the block. */ |
| 3418 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); |
| 3419 | |
| 3420 | if (linfo->li_length == 0xffffffff) |
| 3421 | { |
| 3422 | /* This section is 64-bit DWARF 3. */ |
| 3423 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
| 3424 | linfo->li_offset_size = 8; |
| 3425 | initial_length_size = 12; |
| 3426 | } |
| 3427 | else |
| 3428 | { |
| 3429 | linfo->li_offset_size = 4; |
| 3430 | initial_length_size = 4; |
| 3431 | } |
| 3432 | |
| 3433 | if (linfo->li_length + initial_length_size > section->size) |
| 3434 | { |
| 3435 | /* If the length field has a relocation against it, then we should |
| 3436 | not complain if it is inaccurate (and probably negative). This |
| 3437 | happens in object files when the .debug_line section is actually |
| 3438 | comprised of several different .debug_line.* sections, (some of |
| 3439 | which may be removed by linker garbage collection), and a relocation |
| 3440 | is used to compute the correct length once that is done. */ |
| 3441 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
| 3442 | { |
| 3443 | linfo->li_length = (end - data) - initial_length_size; |
| 3444 | } |
| 3445 | else |
| 3446 | { |
| 3447 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
| 3448 | (long) linfo->li_length); |
| 3449 | return NULL; |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | /* Get and check the version number. */ |
| 3454 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); |
| 3455 | |
| 3456 | if (linfo->li_version != 2 |
| 3457 | && linfo->li_version != 3 |
| 3458 | && linfo->li_version != 4 |
| 3459 | && linfo->li_version != 5) |
| 3460 | { |
| 3461 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
| 3462 | "is currently supported.\n")); |
| 3463 | return NULL; |
| 3464 | } |
| 3465 | |
| 3466 | if (linfo->li_version >= 5) |
| 3467 | { |
| 3468 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); |
| 3469 | |
| 3470 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); |
| 3471 | if (segment_selector_size != 0) |
| 3472 | { |
| 3473 | warn (_("The %s section contains " |
| 3474 | "unsupported segment selector size: %d.\n"), |
| 3475 | section->name, segment_selector_size); |
| 3476 | return 0; |
| 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, |
| 3481 | linfo->li_offset_size, end); |
| 3482 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
| 3483 | |
| 3484 | if (linfo->li_version >= 4) |
| 3485 | { |
| 3486 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
| 3487 | |
| 3488 | if (linfo->li_max_ops_per_insn == 0) |
| 3489 | { |
| 3490 | warn (_("Invalid maximum operations per insn.\n")); |
| 3491 | return NULL; |
| 3492 | } |
| 3493 | } |
| 3494 | else |
| 3495 | linfo->li_max_ops_per_insn = 1; |
| 3496 | |
| 3497 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
| 3498 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
| 3499 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
| 3500 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); |
| 3501 | |
| 3502 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
| 3503 | /* PR 17512: file:002-117414-0.004. */ |
| 3504 | if (* end_of_sequence > end) |
| 3505 | { |
| 3506 | warn (_("Line length %s extends beyond end of section\n"), |
| 3507 | dwarf_vmatoa ("u", linfo->li_length)); |
| 3508 | * end_of_sequence = end; |
| 3509 | return NULL; |
| 3510 | } |
| 3511 | |
| 3512 | return hdrptr; |
| 3513 | } |
| 3514 | |
| 3515 | static unsigned char * |
| 3516 | display_formatted_table (unsigned char * data, |
| 3517 | unsigned char * start, |
| 3518 | unsigned char * end, |
| 3519 | const DWARF2_Internal_LineInfo * linfo, |
| 3520 | struct dwarf_section * section, |
| 3521 | bfd_boolean is_dir) |
| 3522 | { |
| 3523 | unsigned char *format_start, format_count, *format, formati; |
| 3524 | dwarf_vma data_count, datai; |
| 3525 | unsigned int bytes_read, namepass, last_entry = 0; |
| 3526 | |
| 3527 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
| 3528 | format_start = data; |
| 3529 | for (formati = 0; formati < format_count; formati++) |
| 3530 | { |
| 3531 | read_uleb128 (data, & bytes_read, end); |
| 3532 | data += bytes_read; |
| 3533 | read_uleb128 (data, & bytes_read, end); |
| 3534 | data += bytes_read; |
| 3535 | if (data == end) |
| 3536 | { |
| 3537 | if (is_dir) |
| 3538 | warn (_("Corrupt directory format table entry\n")); |
| 3539 | else |
| 3540 | warn (_("Corrupt file name format table entry\n")); |
| 3541 | return data; |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | data_count = read_uleb128 (data, & bytes_read, end); |
| 3546 | data += bytes_read; |
| 3547 | if (data == end) |
| 3548 | { |
| 3549 | if (is_dir) |
| 3550 | warn (_("Corrupt directory list\n")); |
| 3551 | else |
| 3552 | warn (_("Corrupt file name list\n")); |
| 3553 | return data; |
| 3554 | } |
| 3555 | |
| 3556 | if (data_count == 0) |
| 3557 | { |
| 3558 | if (is_dir) |
| 3559 | printf (_("\n The Directory Table is empty.\n")); |
| 3560 | else |
| 3561 | printf (_("\n The File Name Table is empty.\n")); |
| 3562 | return data; |
| 3563 | } |
| 3564 | |
| 3565 | if (is_dir) |
| 3566 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
| 3567 | (long) (data - start)); |
| 3568 | else |
| 3569 | printf (_("\n The File Name Table (offset 0x%lx):\n"), |
| 3570 | (long) (data - start)); |
| 3571 | |
| 3572 | printf (_(" Entry")); |
| 3573 | /* Delay displaying name as the last entry for better screen layout. */ |
| 3574 | for (namepass = 0; namepass < 2; namepass++) |
| 3575 | { |
| 3576 | format = format_start; |
| 3577 | for (formati = 0; formati < format_count; formati++) |
| 3578 | { |
| 3579 | dwarf_vma content_type; |
| 3580 | |
| 3581 | content_type = read_uleb128 (format, & bytes_read, end); |
| 3582 | format += bytes_read; |
| 3583 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
| 3584 | switch (content_type) |
| 3585 | { |
| 3586 | case DW_LNCT_path: |
| 3587 | printf (_("\tName")); |
| 3588 | break; |
| 3589 | case DW_LNCT_directory_index: |
| 3590 | printf (_("\tDir")); |
| 3591 | break; |
| 3592 | case DW_LNCT_timestamp: |
| 3593 | printf (_("\tTime")); |
| 3594 | break; |
| 3595 | case DW_LNCT_size: |
| 3596 | printf (_("\tSize")); |
| 3597 | break; |
| 3598 | case DW_LNCT_MD5: |
| 3599 | printf (_("\tMD5")); |
| 3600 | break; |
| 3601 | default: |
| 3602 | printf (_("\t(Unknown format content type %s)"), |
| 3603 | dwarf_vmatoa ("u", content_type)); |
| 3604 | } |
| 3605 | read_uleb128 (format, & bytes_read, end); |
| 3606 | format += bytes_read; |
| 3607 | } |
| 3608 | } |
| 3609 | putchar ('\n'); |
| 3610 | |
| 3611 | for (datai = 0; datai < data_count; datai++) |
| 3612 | { |
| 3613 | unsigned char *datapass = data; |
| 3614 | |
| 3615 | printf (" %d", last_entry++); |
| 3616 | /* Delay displaying name as the last entry for better screen layout. */ |
| 3617 | for (namepass = 0; namepass < 2; namepass++) |
| 3618 | { |
| 3619 | format = format_start; |
| 3620 | data = datapass; |
| 3621 | for (formati = 0; formati < format_count; formati++) |
| 3622 | { |
| 3623 | dwarf_vma content_type, form; |
| 3624 | |
| 3625 | content_type = read_uleb128 (format, & bytes_read, end); |
| 3626 | format += bytes_read; |
| 3627 | form = read_uleb128 (format, & bytes_read, end); |
| 3628 | format += bytes_read; |
| 3629 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, |
| 3630 | linfo->li_offset_size, |
| 3631 | linfo->li_version, NULL, |
| 3632 | ((content_type == DW_LNCT_path) != (namepass == 1)), |
| 3633 | section, NULL, '\t'); |
| 3634 | } |
| 3635 | } |
| 3636 | if (data == end) |
| 3637 | { |
| 3638 | if (is_dir) |
| 3639 | warn (_("Corrupt directory entries list\n")); |
| 3640 | else |
| 3641 | warn (_("Corrupt file name entries list\n")); |
| 3642 | return data; |
| 3643 | } |
| 3644 | putchar ('\n'); |
| 3645 | } |
| 3646 | return data; |
| 3647 | } |
| 3648 | |
| 3649 | static int |
| 3650 | display_debug_lines_raw (struct dwarf_section * section, |
| 3651 | unsigned char * data, |
| 3652 | unsigned char * end, |
| 3653 | void * file) |
| 3654 | { |
| 3655 | unsigned char *start = section->start; |
| 3656 | int verbose_view = 0; |
| 3657 | |
| 3658 | introduce (section, TRUE); |
| 3659 | |
| 3660 | while (data < end) |
| 3661 | { |
| 3662 | static DWARF2_Internal_LineInfo saved_linfo; |
| 3663 | DWARF2_Internal_LineInfo linfo; |
| 3664 | unsigned char *standard_opcodes; |
| 3665 | unsigned char *end_of_sequence; |
| 3666 | int i; |
| 3667 | |
| 3668 | if (const_strneq (section->name, ".debug_line.") |
| 3669 | /* Note: the following does not apply to .debug_line.dwo sections. |
| 3670 | These are full debug_line sections. */ |
| 3671 | && strcmp (section->name, ".debug_line.dwo") != 0) |
| 3672 | { |
| 3673 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
| 3674 | section containing just the Line Number Statements. They are |
| 3675 | created by the assembler and intended to be used alongside gcc's |
| 3676 | -ffunction-sections command line option. When the linker's |
| 3677 | garbage collection decides to discard a .text.<foo> section it |
| 3678 | can then also discard the line number information in .debug_line.<foo>. |
| 3679 | |
| 3680 | Since the section is a fragment it does not have the details |
| 3681 | needed to fill out a LineInfo structure, so instead we use the |
| 3682 | details from the last full debug_line section that we processed. */ |
| 3683 | end_of_sequence = end; |
| 3684 | standard_opcodes = NULL; |
| 3685 | linfo = saved_linfo; |
| 3686 | /* PR 17531: file: 0522b371. */ |
| 3687 | if (linfo.li_line_range == 0) |
| 3688 | { |
| 3689 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
| 3690 | return 0; |
| 3691 | } |
| 3692 | reset_state_machine (linfo.li_default_is_stmt); |
| 3693 | } |
| 3694 | else |
| 3695 | { |
| 3696 | unsigned char * hdrptr; |
| 3697 | |
| 3698 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
| 3699 | & end_of_sequence)) == NULL) |
| 3700 | return 0; |
| 3701 | |
| 3702 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
| 3703 | printf (_(" Length: %ld\n"), (long) linfo.li_length); |
| 3704 | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
| 3705 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
| 3706 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
| 3707 | if (linfo.li_version >= 4) |
| 3708 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); |
| 3709 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
| 3710 | printf (_(" Line Base: %d\n"), linfo.li_line_base); |
| 3711 | printf (_(" Line Range: %d\n"), linfo.li_line_range); |
| 3712 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); |
| 3713 | |
| 3714 | /* PR 17512: file: 1665-6428-0.004. */ |
| 3715 | if (linfo.li_line_range == 0) |
| 3716 | { |
| 3717 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
| 3718 | linfo.li_line_range = 1; |
| 3719 | } |
| 3720 | |
| 3721 | reset_state_machine (linfo.li_default_is_stmt); |
| 3722 | |
| 3723 | /* Display the contents of the Opcodes table. */ |
| 3724 | standard_opcodes = hdrptr; |
| 3725 | |
| 3726 | /* PR 17512: file: 002-417945-0.004. */ |
| 3727 | if (standard_opcodes + linfo.li_opcode_base >= end) |
| 3728 | { |
| 3729 | warn (_("Line Base extends beyond end of section\n")); |
| 3730 | return 0; |
| 3731 | } |
| 3732 | |
| 3733 | printf (_("\n Opcodes:\n")); |
| 3734 | |
| 3735 | for (i = 1; i < linfo.li_opcode_base; i++) |
| 3736 | printf (ngettext (" Opcode %d has %d arg\n", |
| 3737 | " Opcode %d has %d args\n", |
| 3738 | standard_opcodes[i - 1]), |
| 3739 | i, standard_opcodes[i - 1]); |
| 3740 | |
| 3741 | /* Display the contents of the Directory table. */ |
| 3742 | data = standard_opcodes + linfo.li_opcode_base - 1; |
| 3743 | |
| 3744 | if (linfo.li_version >= 5) |
| 3745 | { |
| 3746 | load_debug_section_with_follow (line_str, file); |
| 3747 | |
| 3748 | data = display_formatted_table (data, start, end, &linfo, section, |
| 3749 | TRUE); |
| 3750 | data = display_formatted_table (data, start, end, &linfo, section, |
| 3751 | FALSE); |
| 3752 | } |
| 3753 | else |
| 3754 | { |
| 3755 | if (*data == 0) |
| 3756 | printf (_("\n The Directory Table is empty.\n")); |
| 3757 | else |
| 3758 | { |
| 3759 | unsigned int last_dir_entry = 0; |
| 3760 | |
| 3761 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
| 3762 | (long)(data - start)); |
| 3763 | |
| 3764 | while (data < end && *data != 0) |
| 3765 | { |
| 3766 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
| 3767 | |
| 3768 | data += strnlen ((char *) data, end - data) + 1; |
| 3769 | } |
| 3770 | |
| 3771 | /* PR 17512: file: 002-132094-0.004. */ |
| 3772 | if (data >= end - 1) |
| 3773 | break; |
| 3774 | } |
| 3775 | |
| 3776 | /* Skip the NUL at the end of the table. */ |
| 3777 | data++; |
| 3778 | |
| 3779 | /* Display the contents of the File Name table. */ |
| 3780 | if (*data == 0) |
| 3781 | printf (_("\n The File Name Table is empty.\n")); |
| 3782 | else |
| 3783 | { |
| 3784 | printf (_("\n The File Name Table (offset 0x%lx):\n"), |
| 3785 | (long)(data - start)); |
| 3786 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
| 3787 | |
| 3788 | while (data < end && *data != 0) |
| 3789 | { |
| 3790 | unsigned char *name; |
| 3791 | unsigned int bytes_read; |
| 3792 | |
| 3793 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
| 3794 | name = data; |
| 3795 | data += strnlen ((char *) data, end - data) + 1; |
| 3796 | |
| 3797 | printf ("%s\t", |
| 3798 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 3799 | data += bytes_read; |
| 3800 | printf ("%s\t", |
| 3801 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 3802 | data += bytes_read; |
| 3803 | printf ("%s\t", |
| 3804 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| 3805 | data += bytes_read; |
| 3806 | printf ("%.*s\n", (int)(end - name), name); |
| 3807 | |
| 3808 | if (data == end) |
| 3809 | { |
| 3810 | warn (_("Corrupt file name table entry\n")); |
| 3811 | break; |
| 3812 | } |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | /* Skip the NUL at the end of the table. */ |
| 3817 | data++; |
| 3818 | } |
| 3819 | |
| 3820 | putchar ('\n'); |
| 3821 | saved_linfo = linfo; |
| 3822 | } |
| 3823 | |
| 3824 | /* Now display the statements. */ |
| 3825 | if (data >= end_of_sequence) |
| 3826 | printf (_(" No Line Number Statements.\n")); |
| 3827 | else |
| 3828 | { |
| 3829 | printf (_(" Line Number Statements:\n")); |
| 3830 | |
| 3831 | while (data < end_of_sequence) |
| 3832 | { |
| 3833 | unsigned char op_code; |
| 3834 | dwarf_signed_vma adv; |
| 3835 | dwarf_vma uladv; |
| 3836 | unsigned int bytes_read; |
| 3837 | |
| 3838 | printf (" [0x%08lx]", (long)(data - start)); |
| 3839 | |
| 3840 | op_code = *data++; |
| 3841 | |
| 3842 | if (op_code >= linfo.li_opcode_base) |
| 3843 | { |
| 3844 | op_code -= linfo.li_opcode_base; |
| 3845 | uladv = (op_code / linfo.li_line_range); |
| 3846 | if (linfo.li_max_ops_per_insn == 1) |
| 3847 | { |
| 3848 | uladv *= linfo.li_min_insn_length; |
| 3849 | state_machine_regs.address += uladv; |
| 3850 | if (uladv) |
| 3851 | state_machine_regs.view = 0; |
| 3852 | printf (_(" Special opcode %d: " |
| 3853 | "advance Address by %s to 0x%s%s"), |
| 3854 | op_code, dwarf_vmatoa ("u", uladv), |
| 3855 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 3856 | verbose_view && uladv |
| 3857 | ? _(" (reset view)") : ""); |
| 3858 | } |
| 3859 | else |
| 3860 | { |
| 3861 | unsigned addrdelta |
| 3862 | = ((state_machine_regs.op_index + uladv) |
| 3863 | / linfo.li_max_ops_per_insn) |
| 3864 | * linfo.li_min_insn_length; |
| 3865 | |
| 3866 | state_machine_regs.address += addrdelta; |
| 3867 | state_machine_regs.op_index |
| 3868 | = (state_machine_regs.op_index + uladv) |
| 3869 | % linfo.li_max_ops_per_insn; |
| 3870 | if (addrdelta) |
| 3871 | state_machine_regs.view = 0; |
| 3872 | printf (_(" Special opcode %d: " |
| 3873 | "advance Address by %s to 0x%s[%d]%s"), |
| 3874 | op_code, dwarf_vmatoa ("u", uladv), |
| 3875 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 3876 | state_machine_regs.op_index, |
| 3877 | verbose_view && addrdelta |
| 3878 | ? _(" (reset view)") : ""); |
| 3879 | } |
| 3880 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
| 3881 | state_machine_regs.line += adv; |
| 3882 | printf (_(" and Line by %s to %d"), |
| 3883 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
| 3884 | if (verbose_view || state_machine_regs.view) |
| 3885 | printf (_(" (view %u)\n"), state_machine_regs.view); |
| 3886 | else |
| 3887 | putchar ('\n'); |
| 3888 | state_machine_regs.view++; |
| 3889 | } |
| 3890 | else switch (op_code) |
| 3891 | { |
| 3892 | case DW_LNS_extended_op: |
| 3893 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); |
| 3894 | break; |
| 3895 | |
| 3896 | case DW_LNS_copy: |
| 3897 | printf (_(" Copy")); |
| 3898 | if (verbose_view || state_machine_regs.view) |
| 3899 | printf (_(" (view %u)\n"), state_machine_regs.view); |
| 3900 | else |
| 3901 | putchar ('\n'); |
| 3902 | state_machine_regs.view++; |
| 3903 | break; |
| 3904 | |
| 3905 | case DW_LNS_advance_pc: |
| 3906 | uladv = read_uleb128 (data, & bytes_read, end); |
| 3907 | data += bytes_read; |
| 3908 | if (linfo.li_max_ops_per_insn == 1) |
| 3909 | { |
| 3910 | uladv *= linfo.li_min_insn_length; |
| 3911 | state_machine_regs.address += uladv; |
| 3912 | if (uladv) |
| 3913 | state_machine_regs.view = 0; |
| 3914 | printf (_(" Advance PC by %s to 0x%s%s\n"), |
| 3915 | dwarf_vmatoa ("u", uladv), |
| 3916 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 3917 | verbose_view && uladv |
| 3918 | ? _(" (reset view)") : ""); |
| 3919 | } |
| 3920 | else |
| 3921 | { |
| 3922 | unsigned addrdelta |
| 3923 | = ((state_machine_regs.op_index + uladv) |
| 3924 | / linfo.li_max_ops_per_insn) |
| 3925 | * linfo.li_min_insn_length; |
| 3926 | state_machine_regs.address |
| 3927 | += addrdelta; |
| 3928 | state_machine_regs.op_index |
| 3929 | = (state_machine_regs.op_index + uladv) |
| 3930 | % linfo.li_max_ops_per_insn; |
| 3931 | if (addrdelta) |
| 3932 | state_machine_regs.view = 0; |
| 3933 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), |
| 3934 | dwarf_vmatoa ("u", uladv), |
| 3935 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 3936 | state_machine_regs.op_index, |
| 3937 | verbose_view && addrdelta |
| 3938 | ? _(" (reset view)") : ""); |
| 3939 | } |
| 3940 | break; |
| 3941 | |
| 3942 | case DW_LNS_advance_line: |
| 3943 | adv = read_sleb128 (data, & bytes_read, end); |
| 3944 | data += bytes_read; |
| 3945 | state_machine_regs.line += adv; |
| 3946 | printf (_(" Advance Line by %s to %d\n"), |
| 3947 | dwarf_vmatoa ("d", adv), |
| 3948 | state_machine_regs.line); |
| 3949 | break; |
| 3950 | |
| 3951 | case DW_LNS_set_file: |
| 3952 | adv = read_uleb128 (data, & bytes_read, end); |
| 3953 | data += bytes_read; |
| 3954 | printf (_(" Set File Name to entry %s in the File Name Table\n"), |
| 3955 | dwarf_vmatoa ("d", adv)); |
| 3956 | state_machine_regs.file = adv; |
| 3957 | break; |
| 3958 | |
| 3959 | case DW_LNS_set_column: |
| 3960 | uladv = read_uleb128 (data, & bytes_read, end); |
| 3961 | data += bytes_read; |
| 3962 | printf (_(" Set column to %s\n"), |
| 3963 | dwarf_vmatoa ("u", uladv)); |
| 3964 | state_machine_regs.column = uladv; |
| 3965 | break; |
| 3966 | |
| 3967 | case DW_LNS_negate_stmt: |
| 3968 | adv = state_machine_regs.is_stmt; |
| 3969 | adv = ! adv; |
| 3970 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); |
| 3971 | state_machine_regs.is_stmt = adv; |
| 3972 | break; |
| 3973 | |
| 3974 | case DW_LNS_set_basic_block: |
| 3975 | printf (_(" Set basic block\n")); |
| 3976 | state_machine_regs.basic_block = 1; |
| 3977 | break; |
| 3978 | |
| 3979 | case DW_LNS_const_add_pc: |
| 3980 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
| 3981 | if (linfo.li_max_ops_per_insn) |
| 3982 | { |
| 3983 | uladv *= linfo.li_min_insn_length; |
| 3984 | state_machine_regs.address += uladv; |
| 3985 | if (uladv) |
| 3986 | state_machine_regs.view = 0; |
| 3987 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), |
| 3988 | dwarf_vmatoa ("u", uladv), |
| 3989 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 3990 | verbose_view && uladv |
| 3991 | ? _(" (reset view)") : ""); |
| 3992 | } |
| 3993 | else |
| 3994 | { |
| 3995 | unsigned addrdelta |
| 3996 | = ((state_machine_regs.op_index + uladv) |
| 3997 | / linfo.li_max_ops_per_insn) |
| 3998 | * linfo.li_min_insn_length; |
| 3999 | state_machine_regs.address |
| 4000 | += addrdelta; |
| 4001 | state_machine_regs.op_index |
| 4002 | = (state_machine_regs.op_index + uladv) |
| 4003 | % linfo.li_max_ops_per_insn; |
| 4004 | if (addrdelta) |
| 4005 | state_machine_regs.view = 0; |
| 4006 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), |
| 4007 | dwarf_vmatoa ("u", uladv), |
| 4008 | dwarf_vmatoa ("x", state_machine_regs.address), |
| 4009 | state_machine_regs.op_index, |
| 4010 | verbose_view && addrdelta |
| 4011 | ? _(" (reset view)") : ""); |
| 4012 | } |
| 4013 | break; |
| 4014 | |
| 4015 | case DW_LNS_fixed_advance_pc: |
| 4016 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
| 4017 | state_machine_regs.address += uladv; |
| 4018 | state_machine_regs.op_index = 0; |
| 4019 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), |
| 4020 | dwarf_vmatoa ("u", uladv), |
| 4021 | dwarf_vmatoa ("x", state_machine_regs.address)); |
| 4022 | /* Do NOT reset view. */ |
| 4023 | break; |
| 4024 | |
| 4025 | case DW_LNS_set_prologue_end: |
| 4026 | printf (_(" Set prologue_end to true\n")); |
| 4027 | break; |
| 4028 | |
| 4029 | case DW_LNS_set_epilogue_begin: |
| 4030 | printf (_(" Set epilogue_begin to true\n")); |
| 4031 | break; |
| 4032 | |
| 4033 | case DW_LNS_set_isa: |
| 4034 | uladv = read_uleb128 (data, & bytes_read, end); |
| 4035 | data += bytes_read; |
| 4036 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); |
| 4037 | break; |
| 4038 | |
| 4039 | default: |
| 4040 | printf (_(" Unknown opcode %d with operands: "), op_code); |
| 4041 | |
| 4042 | if (standard_opcodes != NULL) |
| 4043 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
| 4044 | { |
| 4045 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, |
| 4046 | &bytes_read, end)), |
| 4047 | i == 1 ? "" : ", "); |
| 4048 | data += bytes_read; |
| 4049 | } |
| 4050 | putchar ('\n'); |
| 4051 | break; |
| 4052 | } |
| 4053 | } |
| 4054 | putchar ('\n'); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | return 1; |
| 4059 | } |
| 4060 | |
| 4061 | typedef struct |
| 4062 | { |
| 4063 | unsigned char *name; |
| 4064 | unsigned int directory_index; |
| 4065 | unsigned int modification_date; |
| 4066 | unsigned int length; |
| 4067 | } File_Entry; |
| 4068 | |
| 4069 | /* Output a decoded representation of the .debug_line section. */ |
| 4070 | |
| 4071 | static int |
| 4072 | display_debug_lines_decoded (struct dwarf_section * section, |
| 4073 | unsigned char * data, |
| 4074 | unsigned char * end, |
| 4075 | void * fileptr) |
| 4076 | { |
| 4077 | static DWARF2_Internal_LineInfo saved_linfo; |
| 4078 | |
| 4079 | introduce (section, FALSE); |
| 4080 | |
| 4081 | while (data < end) |
| 4082 | { |
| 4083 | /* This loop amounts to one iteration per compilation unit. */ |
| 4084 | DWARF2_Internal_LineInfo linfo; |
| 4085 | unsigned char *standard_opcodes; |
| 4086 | unsigned char *end_of_sequence; |
| 4087 | int i; |
| 4088 | File_Entry *file_table = NULL; |
| 4089 | unsigned int n_files = 0; |
| 4090 | unsigned char **directory_table = NULL; |
| 4091 | dwarf_vma n_directories = 0; |
| 4092 | |
| 4093 | if (const_strneq (section->name, ".debug_line.") |
| 4094 | /* Note: the following does not apply to .debug_line.dwo sections. |
| 4095 | These are full debug_line sections. */ |
| 4096 | && strcmp (section->name, ".debug_line.dwo") != 0) |
| 4097 | { |
| 4098 | /* See comment in display_debug_lines_raw(). */ |
| 4099 | end_of_sequence = end; |
| 4100 | standard_opcodes = NULL; |
| 4101 | linfo = saved_linfo; |
| 4102 | /* PR 17531: file: 0522b371. */ |
| 4103 | if (linfo.li_line_range == 0) |
| 4104 | { |
| 4105 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
| 4106 | return 0; |
| 4107 | } |
| 4108 | reset_state_machine (linfo.li_default_is_stmt); |
| 4109 | } |
| 4110 | else |
| 4111 | { |
| 4112 | unsigned char *hdrptr; |
| 4113 | |
| 4114 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
| 4115 | & end_of_sequence)) == NULL) |
| 4116 | return 0; |
| 4117 | |
| 4118 | /* PR 17531: file: 0522b371. */ |
| 4119 | if (linfo.li_line_range == 0) |
| 4120 | { |
| 4121 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
| 4122 | linfo.li_line_range = 1; |
| 4123 | } |
| 4124 | reset_state_machine (linfo.li_default_is_stmt); |
| 4125 | |
| 4126 | /* Save a pointer to the contents of the Opcodes table. */ |
| 4127 | standard_opcodes = hdrptr; |
| 4128 | |
| 4129 | /* Traverse the Directory table just to count entries. */ |
| 4130 | data = standard_opcodes + linfo.li_opcode_base - 1; |
| 4131 | /* PR 20440 */ |
| 4132 | if (data >= end) |
| 4133 | { |
| 4134 | warn (_("opcode base of %d extends beyond end of section\n"), |
| 4135 | linfo.li_opcode_base); |
| 4136 | return 0; |
| 4137 | } |
| 4138 | |
| 4139 | if (linfo.li_version >= 5) |
| 4140 | { |
| 4141 | unsigned char *format_start, format_count, *format; |
| 4142 | dwarf_vma formati, entryi; |
| 4143 | unsigned int bytes_read; |
| 4144 | |
| 4145 | load_debug_section_with_follow (line_str, fileptr); |
| 4146 | |
| 4147 | /* Skip directories format. */ |
| 4148 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
| 4149 | format_start = data; |
| 4150 | for (formati = 0; formati < format_count; formati++) |
| 4151 | { |
| 4152 | read_uleb128 (data, & bytes_read, end); |
| 4153 | data += bytes_read; |
| 4154 | read_uleb128 (data, & bytes_read, end); |
| 4155 | data += bytes_read; |
| 4156 | } |
| 4157 | |
| 4158 | n_directories = read_uleb128 (data, & bytes_read, end); |
| 4159 | data += bytes_read; |
| 4160 | if (data == end) |
| 4161 | { |
| 4162 | warn (_("Corrupt directories list\n")); |
| 4163 | break; |
| 4164 | } |
| 4165 | |
| 4166 | directory_table = (unsigned char **) |
| 4167 | xmalloc (n_directories * sizeof (unsigned char *)); |
| 4168 | |
| 4169 | for (entryi = 0; entryi < n_directories; entryi++) |
| 4170 | { |
| 4171 | unsigned char **pathp = &directory_table[entryi]; |
| 4172 | |
| 4173 | format = format_start; |
| 4174 | for (formati = 0; formati < format_count; formati++) |
| 4175 | { |
| 4176 | dwarf_vma content_type, form; |
| 4177 | dwarf_vma uvalue; |
| 4178 | |
| 4179 | content_type = read_uleb128 (format, & bytes_read, end); |
| 4180 | format += bytes_read; |
| 4181 | form = read_uleb128 (format, & bytes_read, end); |
| 4182 | format += bytes_read; |
| 4183 | if (data == end) |
| 4184 | { |
| 4185 | warn (_("Corrupt directories list\n")); |
| 4186 | break; |
| 4187 | } |
| 4188 | switch (content_type) |
| 4189 | { |
| 4190 | case DW_LNCT_path: |
| 4191 | switch (form) |
| 4192 | { |
| 4193 | case DW_FORM_string: |
| 4194 | *pathp = data; |
| 4195 | break; |
| 4196 | case DW_FORM_line_strp: |
| 4197 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
| 4198 | end); |
| 4199 | /* Remove const by the cast. */ |
| 4200 | *pathp = (unsigned char *) |
| 4201 | fetch_indirect_line_string (uvalue); |
| 4202 | break; |
| 4203 | } |
| 4204 | break; |
| 4205 | } |
| 4206 | data = read_and_display_attr_value (0, form, 0, data, end, |
| 4207 | 0, 0, |
| 4208 | linfo.li_offset_size, |
| 4209 | linfo.li_version, |
| 4210 | NULL, 1, section, |
| 4211 | NULL, '\t'); |
| 4212 | } |
| 4213 | if (data == end) |
| 4214 | { |
| 4215 | warn (_("Corrupt directories list\n")); |
| 4216 | break; |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | /* Skip files format. */ |
| 4221 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
| 4222 | format_start = data; |
| 4223 | for (formati = 0; formati < format_count; formati++) |
| 4224 | { |
| 4225 | read_uleb128 (data, & bytes_read, end); |
| 4226 | data += bytes_read; |
| 4227 | read_uleb128 (data, & bytes_read, end); |
| 4228 | data += bytes_read; |
| 4229 | } |
| 4230 | |
| 4231 | n_files = read_uleb128 (data, & bytes_read, end); |
| 4232 | data += bytes_read; |
| 4233 | if (data == end) |
| 4234 | { |
| 4235 | warn (_("Corrupt file name list\n")); |
| 4236 | break; |
| 4237 | } |
| 4238 | |
| 4239 | file_table = (File_Entry *) xcalloc (1, n_files |
| 4240 | * sizeof (File_Entry)); |
| 4241 | |
| 4242 | for (entryi = 0; entryi < n_files; entryi++) |
| 4243 | { |
| 4244 | File_Entry *file = &file_table[entryi]; |
| 4245 | |
| 4246 | format = format_start; |
| 4247 | for (formati = 0; formati < format_count; formati++) |
| 4248 | { |
| 4249 | dwarf_vma content_type, form; |
| 4250 | dwarf_vma uvalue; |
| 4251 | |
| 4252 | content_type = read_uleb128 (format, & bytes_read, end); |
| 4253 | format += bytes_read; |
| 4254 | form = read_uleb128 (format, & bytes_read, end); |
| 4255 | format += bytes_read; |
| 4256 | if (data == end) |
| 4257 | { |
| 4258 | warn (_("Corrupt file name list\n")); |
| 4259 | break; |
| 4260 | } |
| 4261 | switch (content_type) |
| 4262 | { |
| 4263 | case DW_LNCT_path: |
| 4264 | switch (form) |
| 4265 | { |
| 4266 | case DW_FORM_string: |
| 4267 | file->name = data; |
| 4268 | break; |
| 4269 | case DW_FORM_line_strp: |
| 4270 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
| 4271 | end); |
| 4272 | /* Remove const by the cast. */ |
| 4273 | file->name = (unsigned char *) |
| 4274 | fetch_indirect_line_string (uvalue); |
| 4275 | break; |
| 4276 | } |
| 4277 | break; |
| 4278 | case DW_LNCT_directory_index: |
| 4279 | switch (form) |
| 4280 | { |
| 4281 | case DW_FORM_data1: |
| 4282 | SAFE_BYTE_GET (file->directory_index, data, 1, |
| 4283 | end); |
| 4284 | break; |
| 4285 | case DW_FORM_data2: |
| 4286 | SAFE_BYTE_GET (file->directory_index, data, 2, |
| 4287 | end); |
| 4288 | break; |
| 4289 | case DW_FORM_udata: |
| 4290 | file->directory_index = read_uleb128 (data, NULL, |
| 4291 | end); |
| 4292 | break; |
| 4293 | } |
| 4294 | break; |
| 4295 | } |
| 4296 | data = read_and_display_attr_value (0, form, 0, data, end, |
| 4297 | 0, 0, |
| 4298 | linfo.li_offset_size, |
| 4299 | linfo.li_version, |
| 4300 | NULL, 1, section, |
| 4301 | NULL, '\t'); |
| 4302 | } |
| 4303 | if (data == end) |
| 4304 | { |
| 4305 | warn (_("Corrupt file name list\n")); |
| 4306 | break; |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | else |
| 4311 | { |
| 4312 | if (*data != 0) |
| 4313 | { |
| 4314 | unsigned char *ptr_directory_table = data; |
| 4315 | |
| 4316 | while (data < end && *data != 0) |
| 4317 | { |
| 4318 | data += strnlen ((char *) data, end - data) + 1; |
| 4319 | n_directories++; |
| 4320 | } |
| 4321 | |
| 4322 | /* PR 20440 */ |
| 4323 | if (data >= end) |
| 4324 | { |
| 4325 | warn (_("directory table ends unexpectedly\n")); |
| 4326 | n_directories = 0; |
| 4327 | break; |
| 4328 | } |
| 4329 | |
| 4330 | /* Go through the directory table again to save the directories. */ |
| 4331 | directory_table = (unsigned char **) |
| 4332 | xmalloc (n_directories * sizeof (unsigned char *)); |
| 4333 | |
| 4334 | i = 0; |
| 4335 | while (*ptr_directory_table != 0) |
| 4336 | { |
| 4337 | directory_table[i] = ptr_directory_table; |
| 4338 | ptr_directory_table += strnlen ((char *) ptr_directory_table, |
| 4339 | ptr_directory_table - end) + 1; |
| 4340 | i++; |
| 4341 | } |
| 4342 | } |
| 4343 | /* Skip the NUL at the end of the table. */ |
| 4344 | data++; |
| 4345 | |
| 4346 | /* Traverse the File Name table just to count the entries. */ |
| 4347 | if (data < end && *data != 0) |
| 4348 | { |
| 4349 | unsigned char *ptr_file_name_table = data; |
| 4350 | |
| 4351 | while (data < end && *data != 0) |
| 4352 | { |
| 4353 | unsigned int bytes_read; |
| 4354 | |
| 4355 | /* Skip Name, directory index, last modification time and length |
| 4356 | of file. */ |
| 4357 | data += strnlen ((char *) data, end - data) + 1; |
| 4358 | read_uleb128 (data, & bytes_read, end); |
| 4359 | data += bytes_read; |
| 4360 | read_uleb128 (data, & bytes_read, end); |
| 4361 | data += bytes_read; |
| 4362 | read_uleb128 (data, & bytes_read, end); |
| 4363 | data += bytes_read; |
| 4364 | |
| 4365 | n_files++; |
| 4366 | } |
| 4367 | |
| 4368 | if (data >= end) |
| 4369 | { |
| 4370 | warn (_("file table ends unexpectedly\n")); |
| 4371 | n_files = 0; |
| 4372 | break; |
| 4373 | } |
| 4374 | |
| 4375 | /* Go through the file table again to save the strings. */ |
| 4376 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); |
| 4377 | |
| 4378 | i = 0; |
| 4379 | while (*ptr_file_name_table != 0) |
| 4380 | { |
| 4381 | unsigned int bytes_read; |
| 4382 | |
| 4383 | file_table[i].name = ptr_file_name_table; |
| 4384 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, |
| 4385 | end - ptr_file_name_table) + 1; |
| 4386 | |
| 4387 | /* We are not interested in directory, time or size. */ |
| 4388 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, |
| 4389 | & bytes_read, end); |
| 4390 | ptr_file_name_table += bytes_read; |
| 4391 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, |
| 4392 | & bytes_read, end); |
| 4393 | ptr_file_name_table += bytes_read; |
| 4394 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); |
| 4395 | ptr_file_name_table += bytes_read; |
| 4396 | i++; |
| 4397 | } |
| 4398 | i = 0; |
| 4399 | } |
| 4400 | |
| 4401 | /* Skip the NUL at the end of the table. */ |
| 4402 | data++; |
| 4403 | } |
| 4404 | |
| 4405 | /* Print the Compilation Unit's name and a header. */ |
| 4406 | if (file_table == NULL) |
| 4407 | ; |
| 4408 | else if (directory_table == NULL) |
| 4409 | printf (_("CU: %s:\n"), file_table[0].name); |
| 4410 | else |
| 4411 | { |
| 4412 | unsigned int ix = file_table[0].directory_index; |
| 4413 | const char *directory; |
| 4414 | |
| 4415 | if (ix == 0) |
| 4416 | directory = "."; |
| 4417 | /* PR 20439 */ |
| 4418 | else if (n_directories == 0) |
| 4419 | directory = _("<unknown>"); |
| 4420 | else if (ix > n_directories) |
| 4421 | { |
| 4422 | warn (_("directory index %u > number of directories %s\n"), |
| 4423 | ix, dwarf_vmatoa ("u", n_directories)); |
| 4424 | directory = _("<corrupt>"); |
| 4425 | } |
| 4426 | else |
| 4427 | directory = (char *) directory_table[ix - 1]; |
| 4428 | |
| 4429 | if (do_wide || strlen (directory) < 76) |
| 4430 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); |
| 4431 | else |
| 4432 | printf ("%s:\n", file_table[0].name); |
| 4433 | } |
| 4434 | |
| 4435 | printf (_("File name Line number Starting address View Stmt\n")); |
| 4436 | saved_linfo = linfo; |
| 4437 | } |
| 4438 | |
| 4439 | /* This loop iterates through the Dwarf Line Number Program. */ |
| 4440 | while (data < end_of_sequence) |
| 4441 | { |
| 4442 | unsigned char op_code; |
| 4443 | int xop; |
| 4444 | int adv; |
| 4445 | unsigned long int uladv; |
| 4446 | unsigned int bytes_read; |
| 4447 | int is_special_opcode = 0; |
| 4448 | |
| 4449 | op_code = *data++; |
| 4450 | xop = op_code; |
| 4451 | |
| 4452 | if (op_code >= linfo.li_opcode_base) |
| 4453 | { |
| 4454 | op_code -= linfo.li_opcode_base; |
| 4455 | uladv = (op_code / linfo.li_line_range); |
| 4456 | if (linfo.li_max_ops_per_insn == 1) |
| 4457 | { |
| 4458 | uladv *= linfo.li_min_insn_length; |
| 4459 | state_machine_regs.address += uladv; |
| 4460 | if (uladv) |
| 4461 | state_machine_regs.view = 0; |
| 4462 | } |
| 4463 | else |
| 4464 | { |
| 4465 | unsigned addrdelta |
| 4466 | = ((state_machine_regs.op_index + uladv) |
| 4467 | / linfo.li_max_ops_per_insn) |
| 4468 | * linfo.li_min_insn_length; |
| 4469 | state_machine_regs.address |
| 4470 | += addrdelta; |
| 4471 | state_machine_regs.op_index |
| 4472 | = (state_machine_regs.op_index + uladv) |
| 4473 | % linfo.li_max_ops_per_insn; |
| 4474 | if (addrdelta) |
| 4475 | state_machine_regs.view = 0; |
| 4476 | } |
| 4477 | |
| 4478 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
| 4479 | state_machine_regs.line += adv; |
| 4480 | is_special_opcode = 1; |
| 4481 | /* Increment view after printing this row. */ |
| 4482 | } |
| 4483 | else switch (op_code) |
| 4484 | { |
| 4485 | case DW_LNS_extended_op: |
| 4486 | { |
| 4487 | unsigned int ext_op_code_len; |
| 4488 | unsigned char ext_op_code; |
| 4489 | unsigned char *op_code_data = data; |
| 4490 | |
| 4491 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, |
| 4492 | end_of_sequence); |
| 4493 | op_code_data += bytes_read; |
| 4494 | |
| 4495 | if (ext_op_code_len == 0) |
| 4496 | { |
| 4497 | warn (_("Badly formed extended line op encountered!\n")); |
| 4498 | break; |
| 4499 | } |
| 4500 | ext_op_code_len += bytes_read; |
| 4501 | ext_op_code = *op_code_data++; |
| 4502 | xop = ext_op_code; |
| 4503 | xop = -xop; |
| 4504 | |
| 4505 | switch (ext_op_code) |
| 4506 | { |
| 4507 | case DW_LNE_end_sequence: |
| 4508 | /* Reset stuff after printing this row. */ |
| 4509 | break; |
| 4510 | case DW_LNE_set_address: |
| 4511 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, |
| 4512 | op_code_data, |
| 4513 | ext_op_code_len - bytes_read - 1, |
| 4514 | end); |
| 4515 | state_machine_regs.op_index = 0; |
| 4516 | state_machine_regs.view = 0; |
| 4517 | break; |
| 4518 | case DW_LNE_define_file: |
| 4519 | { |
| 4520 | file_table = (File_Entry *) xrealloc |
| 4521 | (file_table, (n_files + 1) * sizeof (File_Entry)); |
| 4522 | |
| 4523 | ++state_machine_regs.last_file_entry; |
| 4524 | /* Source file name. */ |
| 4525 | file_table[n_files].name = op_code_data; |
| 4526 | op_code_data += strlen ((char *) op_code_data) + 1; |
| 4527 | /* Directory index. */ |
| 4528 | file_table[n_files].directory_index = |
| 4529 | read_uleb128 (op_code_data, & bytes_read, |
| 4530 | end_of_sequence); |
| 4531 | op_code_data += bytes_read; |
| 4532 | /* Last modification time. */ |
| 4533 | file_table[n_files].modification_date = |
| 4534 | read_uleb128 (op_code_data, & bytes_read, |
| 4535 | end_of_sequence); |
| 4536 | op_code_data += bytes_read; |
| 4537 | /* File length. */ |
| 4538 | file_table[n_files].length = |
| 4539 | read_uleb128 (op_code_data, & bytes_read, |
| 4540 | end_of_sequence); |
| 4541 | |
| 4542 | n_files++; |
| 4543 | break; |
| 4544 | } |
| 4545 | case DW_LNE_set_discriminator: |
| 4546 | case DW_LNE_HP_set_sequence: |
| 4547 | /* Simply ignored. */ |
| 4548 | break; |
| 4549 | |
| 4550 | default: |
| 4551 | printf (_("UNKNOWN (%u): length %d\n"), |
| 4552 | ext_op_code, ext_op_code_len - bytes_read); |
| 4553 | break; |
| 4554 | } |
| 4555 | data += ext_op_code_len; |
| 4556 | break; |
| 4557 | } |
| 4558 | case DW_LNS_copy: |
| 4559 | /* Increment view after printing this row. */ |
| 4560 | break; |
| 4561 | |
| 4562 | case DW_LNS_advance_pc: |
| 4563 | uladv = read_uleb128 (data, & bytes_read, end); |
| 4564 | data += bytes_read; |
| 4565 | if (linfo.li_max_ops_per_insn == 1) |
| 4566 | { |
| 4567 | uladv *= linfo.li_min_insn_length; |
| 4568 | state_machine_regs.address += uladv; |
| 4569 | if (uladv) |
| 4570 | state_machine_regs.view = 0; |
| 4571 | } |
| 4572 | else |
| 4573 | { |
| 4574 | unsigned addrdelta |
| 4575 | = ((state_machine_regs.op_index + uladv) |
| 4576 | / linfo.li_max_ops_per_insn) |
| 4577 | * linfo.li_min_insn_length; |
| 4578 | state_machine_regs.address |
| 4579 | += addrdelta; |
| 4580 | state_machine_regs.op_index |
| 4581 | = (state_machine_regs.op_index + uladv) |
| 4582 | % linfo.li_max_ops_per_insn; |
| 4583 | if (addrdelta) |
| 4584 | state_machine_regs.view = 0; |
| 4585 | } |
| 4586 | break; |
| 4587 | |
| 4588 | case DW_LNS_advance_line: |
| 4589 | adv = read_sleb128 (data, & bytes_read, end); |
| 4590 | data += bytes_read; |
| 4591 | state_machine_regs.line += adv; |
| 4592 | break; |
| 4593 | |
| 4594 | case DW_LNS_set_file: |
| 4595 | adv = read_uleb128 (data, & bytes_read, end); |
| 4596 | data += bytes_read; |
| 4597 | state_machine_regs.file = adv; |
| 4598 | |
| 4599 | { |
| 4600 | unsigned file = state_machine_regs.file - 1; |
| 4601 | unsigned dir; |
| 4602 | |
| 4603 | if (file_table == NULL || n_files == 0) |
| 4604 | printf (_("\n [Use file table entry %d]\n"), file); |
| 4605 | /* PR 20439 */ |
| 4606 | else if (file >= n_files) |
| 4607 | { |
| 4608 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); |
| 4609 | printf (_("\n <over large file table index %u>"), file); |
| 4610 | } |
| 4611 | else if ((dir = file_table[file].directory_index) == 0) |
| 4612 | /* If directory index is 0, that means current directory. */ |
| 4613 | printf ("\n./%s:[++]\n", file_table[file].name); |
| 4614 | else if (directory_table == NULL || n_directories == 0) |
| 4615 | printf (_("\n [Use file %s in directory table entry %d]\n"), |
| 4616 | file_table[file].name, dir); |
| 4617 | /* PR 20439 */ |
| 4618 | else if (dir > n_directories) |
| 4619 | { |
| 4620 | warn (_("directory index %u > number of directories %s\n"), |
| 4621 | dir, dwarf_vmatoa ("u", n_directories)); |
| 4622 | printf (_("\n <over large directory table entry %u>\n"), dir); |
| 4623 | } |
| 4624 | else |
| 4625 | printf ("\n%s/%s:\n", |
| 4626 | /* The directory index starts counting at 1. */ |
| 4627 | directory_table[dir - 1], file_table[file].name); |
| 4628 | } |
| 4629 | break; |
| 4630 | |
| 4631 | case DW_LNS_set_column: |
| 4632 | uladv = read_uleb128 (data, & bytes_read, end); |
| 4633 | data += bytes_read; |
| 4634 | state_machine_regs.column = uladv; |
| 4635 | break; |
| 4636 | |
| 4637 | case DW_LNS_negate_stmt: |
| 4638 | adv = state_machine_regs.is_stmt; |
| 4639 | adv = ! adv; |
| 4640 | state_machine_regs.is_stmt = adv; |
| 4641 | break; |
| 4642 | |
| 4643 | case DW_LNS_set_basic_block: |
| 4644 | state_machine_regs.basic_block = 1; |
| 4645 | break; |
| 4646 | |
| 4647 | case DW_LNS_const_add_pc: |
| 4648 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
| 4649 | if (linfo.li_max_ops_per_insn == 1) |
| 4650 | { |
| 4651 | uladv *= linfo.li_min_insn_length; |
| 4652 | state_machine_regs.address += uladv; |
| 4653 | if (uladv) |
| 4654 | state_machine_regs.view = 0; |
| 4655 | } |
| 4656 | else |
| 4657 | { |
| 4658 | unsigned addrdelta |
| 4659 | = ((state_machine_regs.op_index + uladv) |
| 4660 | / linfo.li_max_ops_per_insn) |
| 4661 | * linfo.li_min_insn_length; |
| 4662 | state_machine_regs.address |
| 4663 | += addrdelta; |
| 4664 | state_machine_regs.op_index |
| 4665 | = (state_machine_regs.op_index + uladv) |
| 4666 | % linfo.li_max_ops_per_insn; |
| 4667 | if (addrdelta) |
| 4668 | state_machine_regs.view = 0; |
| 4669 | } |
| 4670 | break; |
| 4671 | |
| 4672 | case DW_LNS_fixed_advance_pc: |
| 4673 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
| 4674 | state_machine_regs.address += uladv; |
| 4675 | state_machine_regs.op_index = 0; |
| 4676 | /* Do NOT reset view. */ |
| 4677 | break; |
| 4678 | |
| 4679 | case DW_LNS_set_prologue_end: |
| 4680 | break; |
| 4681 | |
| 4682 | case DW_LNS_set_epilogue_begin: |
| 4683 | break; |
| 4684 | |
| 4685 | case DW_LNS_set_isa: |
| 4686 | uladv = read_uleb128 (data, & bytes_read, end); |
| 4687 | data += bytes_read; |
| 4688 | printf (_(" Set ISA to %lu\n"), uladv); |
| 4689 | break; |
| 4690 | |
| 4691 | default: |
| 4692 | printf (_(" Unknown opcode %d with operands: "), op_code); |
| 4693 | |
| 4694 | if (standard_opcodes != NULL) |
| 4695 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
| 4696 | { |
| 4697 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, |
| 4698 | &bytes_read, end)), |
| 4699 | i == 1 ? "" : ", "); |
| 4700 | data += bytes_read; |
| 4701 | } |
| 4702 | putchar ('\n'); |
| 4703 | break; |
| 4704 | } |
| 4705 | |
| 4706 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
| 4707 | to the DWARF address/line matrix. */ |
| 4708 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
| 4709 | || (xop == DW_LNS_copy)) |
| 4710 | { |
| 4711 | const unsigned int MAX_FILENAME_LENGTH = 35; |
| 4712 | char *fileName; |
| 4713 | char *newFileName = NULL; |
| 4714 | size_t fileNameLength; |
| 4715 | |
| 4716 | if (file_table) |
| 4717 | { |
| 4718 | unsigned indx = state_machine_regs.file - 1; |
| 4719 | /* PR 20439 */ |
| 4720 | if (indx >= n_files) |
| 4721 | { |
| 4722 | warn (_("corrupt file index %u encountered\n"), indx); |
| 4723 | fileName = _("<corrupt>"); |
| 4724 | } |
| 4725 | else |
| 4726 | fileName = (char *) file_table[indx].name; |
| 4727 | } |
| 4728 | else |
| 4729 | fileName = _("<unknown>"); |
| 4730 | |
| 4731 | fileNameLength = strlen (fileName); |
| 4732 | |
| 4733 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
| 4734 | { |
| 4735 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
| 4736 | /* Truncate file name */ |
| 4737 | strncpy (newFileName, |
| 4738 | fileName + fileNameLength - MAX_FILENAME_LENGTH, |
| 4739 | MAX_FILENAME_LENGTH + 1); |
| 4740 | } |
| 4741 | else |
| 4742 | { |
| 4743 | newFileName = (char *) xmalloc (fileNameLength + 1); |
| 4744 | strncpy (newFileName, fileName, fileNameLength + 1); |
| 4745 | } |
| 4746 | |
| 4747 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
| 4748 | { |
| 4749 | if (linfo.li_max_ops_per_insn == 1) |
| 4750 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
| 4751 | newFileName, state_machine_regs.line, |
| 4752 | state_machine_regs.address); |
| 4753 | else |
| 4754 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
| 4755 | newFileName, state_machine_regs.line, |
| 4756 | state_machine_regs.address, |
| 4757 | state_machine_regs.op_index); |
| 4758 | } |
| 4759 | else |
| 4760 | { |
| 4761 | if (linfo.li_max_ops_per_insn == 1) |
| 4762 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
| 4763 | newFileName, state_machine_regs.line, |
| 4764 | state_machine_regs.address); |
| 4765 | else |
| 4766 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
| 4767 | newFileName, state_machine_regs.line, |
| 4768 | state_machine_regs.address, |
| 4769 | state_machine_regs.op_index); |
| 4770 | } |
| 4771 | |
| 4772 | if (state_machine_regs.view) |
| 4773 | printf (" %6u", state_machine_regs.view); |
| 4774 | else |
| 4775 | printf (" "); |
| 4776 | |
| 4777 | if (state_machine_regs.is_stmt) |
| 4778 | printf (" x"); |
| 4779 | |
| 4780 | putchar ('\n'); |
| 4781 | state_machine_regs.view++; |
| 4782 | |
| 4783 | if (xop == -DW_LNE_end_sequence) |
| 4784 | { |
| 4785 | reset_state_machine (linfo.li_default_is_stmt); |
| 4786 | putchar ('\n'); |
| 4787 | } |
| 4788 | |
| 4789 | free (newFileName); |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | if (file_table) |
| 4794 | { |
| 4795 | free (file_table); |
| 4796 | file_table = NULL; |
| 4797 | n_files = 0; |
| 4798 | } |
| 4799 | |
| 4800 | if (directory_table) |
| 4801 | { |
| 4802 | free (directory_table); |
| 4803 | directory_table = NULL; |
| 4804 | n_directories = 0; |
| 4805 | } |
| 4806 | |
| 4807 | putchar ('\n'); |
| 4808 | } |
| 4809 | |
| 4810 | return 1; |
| 4811 | } |
| 4812 | |
| 4813 | static int |
| 4814 | display_debug_lines (struct dwarf_section *section, void *file) |
| 4815 | { |
| 4816 | unsigned char *data = section->start; |
| 4817 | unsigned char *end = data + section->size; |
| 4818 | int retValRaw = 1; |
| 4819 | int retValDecoded = 1; |
| 4820 | |
| 4821 | if (do_debug_lines == 0) |
| 4822 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; |
| 4823 | |
| 4824 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
| 4825 | retValRaw = display_debug_lines_raw (section, data, end, file); |
| 4826 | |
| 4827 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
| 4828 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
| 4829 | |
| 4830 | if (!retValRaw || !retValDecoded) |
| 4831 | return 0; |
| 4832 | |
| 4833 | return 1; |
| 4834 | } |
| 4835 | |
| 4836 | static debug_info * |
| 4837 | find_debug_info_for_offset (unsigned long offset) |
| 4838 | { |
| 4839 | unsigned int i; |
| 4840 | |
| 4841 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
| 4842 | return NULL; |
| 4843 | |
| 4844 | for (i = 0; i < num_debug_info_entries; i++) |
| 4845 | if (debug_information[i].cu_offset == offset) |
| 4846 | return debug_information + i; |
| 4847 | |
| 4848 | return NULL; |
| 4849 | } |
| 4850 | |
| 4851 | static const char * |
| 4852 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) |
| 4853 | { |
| 4854 | /* See gdb/gdb-index.h. */ |
| 4855 | static const char * const kinds[] = |
| 4856 | { |
| 4857 | N_ ("no info"), |
| 4858 | N_ ("type"), |
| 4859 | N_ ("variable"), |
| 4860 | N_ ("function"), |
| 4861 | N_ ("other"), |
| 4862 | N_ ("unused5"), |
| 4863 | N_ ("unused6"), |
| 4864 | N_ ("unused7") |
| 4865 | }; |
| 4866 | |
| 4867 | return _ (kinds[kind]); |
| 4868 | } |
| 4869 | |
| 4870 | static int |
| 4871 | display_debug_pubnames_worker (struct dwarf_section *section, |
| 4872 | void *file ATTRIBUTE_UNUSED, |
| 4873 | int is_gnu) |
| 4874 | { |
| 4875 | DWARF2_Internal_PubNames names; |
| 4876 | unsigned char *start = section->start; |
| 4877 | unsigned char *end = start + section->size; |
| 4878 | |
| 4879 | /* It does not matter if this load fails, |
| 4880 | we test for that later on. */ |
| 4881 | load_debug_info (file); |
| 4882 | |
| 4883 | introduce (section, FALSE); |
| 4884 | |
| 4885 | while (start < end) |
| 4886 | { |
| 4887 | unsigned char *data; |
| 4888 | unsigned long sec_off; |
| 4889 | unsigned int offset_size, initial_length_size; |
| 4890 | |
| 4891 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
| 4892 | if (names.pn_length == 0xffffffff) |
| 4893 | { |
| 4894 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
| 4895 | offset_size = 8; |
| 4896 | initial_length_size = 12; |
| 4897 | } |
| 4898 | else |
| 4899 | { |
| 4900 | offset_size = 4; |
| 4901 | initial_length_size = 4; |
| 4902 | } |
| 4903 | |
| 4904 | sec_off = start - section->start; |
| 4905 | if (sec_off + names.pn_length < sec_off |
| 4906 | || sec_off + names.pn_length > section->size) |
| 4907 | { |
| 4908 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
| 4909 | section->name, |
| 4910 | sec_off - initial_length_size, |
| 4911 | dwarf_vmatoa ("x", names.pn_length)); |
| 4912 | break; |
| 4913 | } |
| 4914 | |
| 4915 | data = start; |
| 4916 | start += names.pn_length; |
| 4917 | |
| 4918 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
| 4919 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); |
| 4920 | |
| 4921 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
| 4922 | && num_debug_info_entries > 0 |
| 4923 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
| 4924 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
| 4925 | (unsigned long) names.pn_offset, section->name); |
| 4926 | |
| 4927 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
| 4928 | |
| 4929 | printf (_(" Length: %ld\n"), |
| 4930 | (long) names.pn_length); |
| 4931 | printf (_(" Version: %d\n"), |
| 4932 | names.pn_version); |
| 4933 | printf (_(" Offset into .debug_info section: 0x%lx\n"), |
| 4934 | (unsigned long) names.pn_offset); |
| 4935 | printf (_(" Size of area in .debug_info section: %ld\n"), |
| 4936 | (long) names.pn_size); |
| 4937 | |
| 4938 | if (names.pn_version != 2 && names.pn_version != 3) |
| 4939 | { |
| 4940 | static int warned = 0; |
| 4941 | |
| 4942 | if (! warned) |
| 4943 | { |
| 4944 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); |
| 4945 | warned = 1; |
| 4946 | } |
| 4947 | |
| 4948 | continue; |
| 4949 | } |
| 4950 | |
| 4951 | if (is_gnu) |
| 4952 | printf (_("\n Offset Kind Name\n")); |
| 4953 | else |
| 4954 | printf (_("\n Offset\tName\n")); |
| 4955 | |
| 4956 | while (1) |
| 4957 | { |
| 4958 | bfd_size_type maxprint; |
| 4959 | dwarf_vma offset; |
| 4960 | |
| 4961 | SAFE_BYTE_GET (offset, data, offset_size, end); |
| 4962 | |
| 4963 | if (offset == 0) |
| 4964 | break; |
| 4965 | |
| 4966 | data += offset_size; |
| 4967 | if (data >= end) |
| 4968 | break; |
| 4969 | maxprint = (end - data) - 1; |
| 4970 | |
| 4971 | if (is_gnu) |
| 4972 | { |
| 4973 | unsigned int kind_data; |
| 4974 | gdb_index_symbol_kind kind; |
| 4975 | const char *kind_name; |
| 4976 | int is_static; |
| 4977 | |
| 4978 | SAFE_BYTE_GET (kind_data, data, 1, end); |
| 4979 | data++; |
| 4980 | maxprint --; |
| 4981 | /* GCC computes the kind as the upper byte in the CU index |
| 4982 | word, and then right shifts it by the CU index size. |
| 4983 | Left shift KIND to where the gdb-index.h accessor macros |
| 4984 | can use it. */ |
| 4985 | kind_data <<= GDB_INDEX_CU_BITSIZE; |
| 4986 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); |
| 4987 | kind_name = get_gdb_index_symbol_kind_name (kind); |
| 4988 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); |
| 4989 | printf (" %-6lx %s,%-10s %.*s\n", |
| 4990 | (unsigned long) offset, is_static ? _("s") : _("g"), |
| 4991 | kind_name, (int) maxprint, data); |
| 4992 | } |
| 4993 | else |
| 4994 | printf (" %-6lx\t%.*s\n", |
| 4995 | (unsigned long) offset, (int) maxprint, data); |
| 4996 | |
| 4997 | data += strnlen ((char *) data, maxprint) + 1; |
| 4998 | if (data >= end) |
| 4999 | break; |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | printf ("\n"); |
| 5004 | return 1; |
| 5005 | } |
| 5006 | |
| 5007 | static int |
| 5008 | display_debug_pubnames (struct dwarf_section *section, void *file) |
| 5009 | { |
| 5010 | return display_debug_pubnames_worker (section, file, 0); |
| 5011 | } |
| 5012 | |
| 5013 | static int |
| 5014 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) |
| 5015 | { |
| 5016 | return display_debug_pubnames_worker (section, file, 1); |
| 5017 | } |
| 5018 | |
| 5019 | static int |
| 5020 | display_debug_macinfo (struct dwarf_section *section, |
| 5021 | void *file ATTRIBUTE_UNUSED) |
| 5022 | { |
| 5023 | unsigned char *start = section->start; |
| 5024 | unsigned char *end = start + section->size; |
| 5025 | unsigned char *curr = start; |
| 5026 | unsigned int bytes_read; |
| 5027 | enum dwarf_macinfo_record_type op; |
| 5028 | |
| 5029 | introduce (section, FALSE); |
| 5030 | |
| 5031 | while (curr < end) |
| 5032 | { |
| 5033 | unsigned int lineno; |
| 5034 | const unsigned char *string; |
| 5035 | |
| 5036 | op = (enum dwarf_macinfo_record_type) *curr; |
| 5037 | curr++; |
| 5038 | |
| 5039 | switch (op) |
| 5040 | { |
| 5041 | case DW_MACINFO_start_file: |
| 5042 | { |
| 5043 | unsigned int filenum; |
| 5044 | |
| 5045 | lineno = read_uleb128 (curr, & bytes_read, end); |
| 5046 | curr += bytes_read; |
| 5047 | filenum = read_uleb128 (curr, & bytes_read, end); |
| 5048 | curr += bytes_read; |
| 5049 | |
| 5050 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
| 5051 | lineno, filenum); |
| 5052 | } |
| 5053 | break; |
| 5054 | |
| 5055 | case DW_MACINFO_end_file: |
| 5056 | printf (_(" DW_MACINFO_end_file\n")); |
| 5057 | break; |
| 5058 | |
| 5059 | case DW_MACINFO_define: |
| 5060 | lineno = read_uleb128 (curr, & bytes_read, end); |
| 5061 | curr += bytes_read; |
| 5062 | string = curr; |
| 5063 | curr += strnlen ((char *) string, end - string) + 1; |
| 5064 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
| 5065 | lineno, string); |
| 5066 | break; |
| 5067 | |
| 5068 | case DW_MACINFO_undef: |
| 5069 | lineno = read_uleb128 (curr, & bytes_read, end); |
| 5070 | curr += bytes_read; |
| 5071 | string = curr; |
| 5072 | curr += strnlen ((char *) string, end - string) + 1; |
| 5073 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
| 5074 | lineno, string); |
| 5075 | break; |
| 5076 | |
| 5077 | case DW_MACINFO_vendor_ext: |
| 5078 | { |
| 5079 | unsigned int constant; |
| 5080 | |
| 5081 | constant = read_uleb128 (curr, & bytes_read, end); |
| 5082 | curr += bytes_read; |
| 5083 | string = curr; |
| 5084 | curr += strnlen ((char *) string, end - string) + 1; |
| 5085 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
| 5086 | constant, string); |
| 5087 | } |
| 5088 | break; |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | return 1; |
| 5093 | } |
| 5094 | |
| 5095 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
| 5096 | filename and dirname corresponding to file name table entry with index |
| 5097 | FILEIDX. Return NULL on failure. */ |
| 5098 | |
| 5099 | static unsigned char * |
| 5100 | get_line_filename_and_dirname (dwarf_vma line_offset, |
| 5101 | dwarf_vma fileidx, |
| 5102 | unsigned char **dir_name) |
| 5103 | { |
| 5104 | struct dwarf_section *section = &debug_displays [line].section; |
| 5105 | unsigned char *hdrptr, *dirtable, *file_name; |
| 5106 | unsigned int offset_size, initial_length_size; |
| 5107 | unsigned int version, opcode_base, bytes_read; |
| 5108 | dwarf_vma length, diridx; |
| 5109 | const unsigned char * end; |
| 5110 | |
| 5111 | *dir_name = NULL; |
| 5112 | if (section->start == NULL |
| 5113 | || line_offset >= section->size |
| 5114 | || fileidx == 0) |
| 5115 | return NULL; |
| 5116 | |
| 5117 | hdrptr = section->start + line_offset; |
| 5118 | end = section->start + section->size; |
| 5119 | |
| 5120 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); |
| 5121 | if (length == 0xffffffff) |
| 5122 | { |
| 5123 | /* This section is 64-bit DWARF 3. */ |
| 5124 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
| 5125 | offset_size = 8; |
| 5126 | initial_length_size = 12; |
| 5127 | } |
| 5128 | else |
| 5129 | { |
| 5130 | offset_size = 4; |
| 5131 | initial_length_size = 4; |
| 5132 | } |
| 5133 | if (length + initial_length_size < length |
| 5134 | || length + initial_length_size > section->size) |
| 5135 | return NULL; |
| 5136 | |
| 5137 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); |
| 5138 | if (version != 2 && version != 3 && version != 4) |
| 5139 | return NULL; |
| 5140 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ |
| 5141 | if (version >= 4) |
| 5142 | hdrptr++; /* Skip max_ops_per_insn. */ |
| 5143 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ |
| 5144 | |
| 5145 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); |
| 5146 | if (opcode_base == 0) |
| 5147 | return NULL; |
| 5148 | |
| 5149 | hdrptr += opcode_base - 1; |
| 5150 | if (hdrptr >= end) |
| 5151 | return NULL; |
| 5152 | |
| 5153 | dirtable = hdrptr; |
| 5154 | /* Skip over dirname table. */ |
| 5155 | while (*hdrptr != '\0') |
| 5156 | { |
| 5157 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
| 5158 | if (hdrptr >= end) |
| 5159 | return NULL; |
| 5160 | } |
| 5161 | hdrptr++; /* Skip the NUL at the end of the table. */ |
| 5162 | |
| 5163 | /* Now skip over preceding filename table entries. */ |
| 5164 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
| 5165 | { |
| 5166 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
| 5167 | read_uleb128 (hdrptr, &bytes_read, end); |
| 5168 | hdrptr += bytes_read; |
| 5169 | read_uleb128 (hdrptr, &bytes_read, end); |
| 5170 | hdrptr += bytes_read; |
| 5171 | read_uleb128 (hdrptr, &bytes_read, end); |
| 5172 | hdrptr += bytes_read; |
| 5173 | } |
| 5174 | if (hdrptr >= end || *hdrptr == '\0') |
| 5175 | return NULL; |
| 5176 | |
| 5177 | file_name = hdrptr; |
| 5178 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
| 5179 | if (hdrptr >= end) |
| 5180 | return NULL; |
| 5181 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
| 5182 | if (diridx == 0) |
| 5183 | return file_name; |
| 5184 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
| 5185 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
| 5186 | if (dirtable >= end || *dirtable == '\0') |
| 5187 | return NULL; |
| 5188 | *dir_name = dirtable; |
| 5189 | return file_name; |
| 5190 | } |
| 5191 | |
| 5192 | static int |
| 5193 | display_debug_macro (struct dwarf_section *section, |
| 5194 | void *file) |
| 5195 | { |
| 5196 | unsigned char *start = section->start; |
| 5197 | unsigned char *end = start + section->size; |
| 5198 | unsigned char *curr = start; |
| 5199 | unsigned char *extended_op_buf[256]; |
| 5200 | unsigned int bytes_read; |
| 5201 | |
| 5202 | load_debug_section_with_follow (str, file); |
| 5203 | load_debug_section_with_follow (line, file); |
| 5204 | |
| 5205 | introduce (section, FALSE); |
| 5206 | |
| 5207 | while (curr < end) |
| 5208 | { |
| 5209 | unsigned int lineno, version, flags; |
| 5210 | unsigned int offset_size = 4; |
| 5211 | const unsigned char *string; |
| 5212 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
| 5213 | unsigned char **extended_ops = NULL; |
| 5214 | |
| 5215 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
| 5216 | if (version != 4 && version != 5) |
| 5217 | { |
| 5218 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
| 5219 | section->name); |
| 5220 | return 0; |
| 5221 | } |
| 5222 | |
| 5223 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
| 5224 | if (flags & 1) |
| 5225 | offset_size = 8; |
| 5226 | printf (_(" Offset: 0x%lx\n"), |
| 5227 | (unsigned long) sec_offset); |
| 5228 | printf (_(" Version: %d\n"), version); |
| 5229 | printf (_(" Offset size: %d\n"), offset_size); |
| 5230 | if (flags & 2) |
| 5231 | { |
| 5232 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
| 5233 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
| 5234 | (unsigned long) line_offset); |
| 5235 | } |
| 5236 | if (flags & 4) |
| 5237 | { |
| 5238 | unsigned int i, count, op; |
| 5239 | dwarf_vma nargs, n; |
| 5240 | |
| 5241 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); |
| 5242 | |
| 5243 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
| 5244 | extended_ops = extended_op_buf; |
| 5245 | if (count) |
| 5246 | { |
| 5247 | printf (_(" Extension opcode arguments:\n")); |
| 5248 | for (i = 0; i < count; i++) |
| 5249 | { |
| 5250 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
| 5251 | extended_ops[op] = curr; |
| 5252 | nargs = read_uleb128 (curr, &bytes_read, end); |
| 5253 | curr += bytes_read; |
| 5254 | if (nargs == 0) |
| 5255 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
| 5256 | else |
| 5257 | { |
| 5258 | printf (_(" DW_MACRO_%02x arguments: "), op); |
| 5259 | for (n = 0; n < nargs; n++) |
| 5260 | { |
| 5261 | unsigned int form; |
| 5262 | |
| 5263 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); |
| 5264 | printf ("%s%s", get_FORM_name (form), |
| 5265 | n == nargs - 1 ? "\n" : ", "); |
| 5266 | switch (form) |
| 5267 | { |
| 5268 | case DW_FORM_data1: |
| 5269 | case DW_FORM_data2: |
| 5270 | case DW_FORM_data4: |
| 5271 | case DW_FORM_data8: |
| 5272 | case DW_FORM_sdata: |
| 5273 | case DW_FORM_udata: |
| 5274 | case DW_FORM_block: |
| 5275 | case DW_FORM_block1: |
| 5276 | case DW_FORM_block2: |
| 5277 | case DW_FORM_block4: |
| 5278 | case DW_FORM_flag: |
| 5279 | case DW_FORM_string: |
| 5280 | case DW_FORM_strp: |
| 5281 | case DW_FORM_sec_offset: |
| 5282 | break; |
| 5283 | default: |
| 5284 | error (_("Invalid extension opcode form %s\n"), |
| 5285 | get_FORM_name (form)); |
| 5286 | return 0; |
| 5287 | } |
| 5288 | } |
| 5289 | } |
| 5290 | } |
| 5291 | } |
| 5292 | } |
| 5293 | printf ("\n"); |
| 5294 | |
| 5295 | while (1) |
| 5296 | { |
| 5297 | unsigned int op; |
| 5298 | |
| 5299 | if (curr >= end) |
| 5300 | { |
| 5301 | error (_(".debug_macro section not zero terminated\n")); |
| 5302 | return 0; |
| 5303 | } |
| 5304 | |
| 5305 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
| 5306 | if (op == 0) |
| 5307 | break; |
| 5308 | |
| 5309 | switch (op) |
| 5310 | { |
| 5311 | case DW_MACRO_start_file: |
| 5312 | { |
| 5313 | unsigned int filenum; |
| 5314 | unsigned char *file_name = NULL, *dir_name = NULL; |
| 5315 | |
| 5316 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5317 | curr += bytes_read; |
| 5318 | filenum = read_uleb128 (curr, &bytes_read, end); |
| 5319 | curr += bytes_read; |
| 5320 | |
| 5321 | if ((flags & 2) == 0) |
| 5322 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
| 5323 | else |
| 5324 | file_name |
| 5325 | = get_line_filename_and_dirname (line_offset, filenum, |
| 5326 | &dir_name); |
| 5327 | if (file_name == NULL) |
| 5328 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
| 5329 | lineno, filenum); |
| 5330 | else |
| 5331 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
| 5332 | lineno, filenum, |
| 5333 | dir_name != NULL ? (const char *) dir_name : "", |
| 5334 | dir_name != NULL ? "/" : "", file_name); |
| 5335 | } |
| 5336 | break; |
| 5337 | |
| 5338 | case DW_MACRO_end_file: |
| 5339 | printf (_(" DW_MACRO_end_file\n")); |
| 5340 | break; |
| 5341 | |
| 5342 | case DW_MACRO_define: |
| 5343 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5344 | curr += bytes_read; |
| 5345 | string = curr; |
| 5346 | curr += strnlen ((char *) string, end - string) + 1; |
| 5347 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
| 5348 | lineno, string); |
| 5349 | break; |
| 5350 | |
| 5351 | case DW_MACRO_undef: |
| 5352 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5353 | curr += bytes_read; |
| 5354 | string = curr; |
| 5355 | curr += strnlen ((char *) string, end - string) + 1; |
| 5356 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
| 5357 | lineno, string); |
| 5358 | break; |
| 5359 | |
| 5360 | case DW_MACRO_define_strp: |
| 5361 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5362 | curr += bytes_read; |
| 5363 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5364 | string = fetch_indirect_string (offset); |
| 5365 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
| 5366 | lineno, string); |
| 5367 | break; |
| 5368 | |
| 5369 | case DW_MACRO_undef_strp: |
| 5370 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5371 | curr += bytes_read; |
| 5372 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5373 | string = fetch_indirect_string (offset); |
| 5374 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
| 5375 | lineno, string); |
| 5376 | break; |
| 5377 | |
| 5378 | case DW_MACRO_import: |
| 5379 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5380 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
| 5381 | (unsigned long) offset); |
| 5382 | break; |
| 5383 | |
| 5384 | case DW_MACRO_define_sup: |
| 5385 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5386 | curr += bytes_read; |
| 5387 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5388 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
| 5389 | lineno, (unsigned long) offset); |
| 5390 | break; |
| 5391 | |
| 5392 | case DW_MACRO_undef_sup: |
| 5393 | lineno = read_uleb128 (curr, &bytes_read, end); |
| 5394 | curr += bytes_read; |
| 5395 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5396 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
| 5397 | lineno, (unsigned long) offset); |
| 5398 | break; |
| 5399 | |
| 5400 | case DW_MACRO_import_sup: |
| 5401 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
| 5402 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
| 5403 | (unsigned long) offset); |
| 5404 | break; |
| 5405 | |
| 5406 | default: |
| 5407 | if (extended_ops == NULL || extended_ops[op] == NULL) |
| 5408 | { |
| 5409 | error (_(" Unknown macro opcode %02x seen\n"), op); |
| 5410 | return 0; |
| 5411 | } |
| 5412 | else |
| 5413 | { |
| 5414 | /* Skip over unhandled opcodes. */ |
| 5415 | dwarf_vma nargs, n; |
| 5416 | unsigned char *desc = extended_ops[op]; |
| 5417 | nargs = read_uleb128 (desc, &bytes_read, end); |
| 5418 | desc += bytes_read; |
| 5419 | if (nargs == 0) |
| 5420 | { |
| 5421 | printf (_(" DW_MACRO_%02x\n"), op); |
| 5422 | break; |
| 5423 | } |
| 5424 | printf (_(" DW_MACRO_%02x -"), op); |
| 5425 | for (n = 0; n < nargs; n++) |
| 5426 | { |
| 5427 | int val; |
| 5428 | |
| 5429 | /* DW_FORM_implicit_const is not expected here. */ |
| 5430 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
| 5431 | curr |
| 5432 | = read_and_display_attr_value (0, val, 0, |
| 5433 | curr, end, 0, 0, offset_size, |
| 5434 | version, NULL, 0, NULL, |
| 5435 | NULL, ' '); |
| 5436 | if (n != nargs - 1) |
| 5437 | printf (","); |
| 5438 | } |
| 5439 | printf ("\n"); |
| 5440 | } |
| 5441 | break; |
| 5442 | } |
| 5443 | } |
| 5444 | |
| 5445 | printf ("\n"); |
| 5446 | } |
| 5447 | |
| 5448 | return 1; |
| 5449 | } |
| 5450 | |
| 5451 | static int |
| 5452 | display_debug_abbrev (struct dwarf_section *section, |
| 5453 | void *file ATTRIBUTE_UNUSED) |
| 5454 | { |
| 5455 | abbrev_entry *entry; |
| 5456 | unsigned char *start = section->start; |
| 5457 | unsigned char *end = start + section->size; |
| 5458 | |
| 5459 | introduce (section, FALSE); |
| 5460 | |
| 5461 | do |
| 5462 | { |
| 5463 | unsigned char *last; |
| 5464 | |
| 5465 | free_abbrevs (); |
| 5466 | |
| 5467 | last = start; |
| 5468 | start = process_abbrev_section (start, end); |
| 5469 | |
| 5470 | if (first_abbrev == NULL) |
| 5471 | continue; |
| 5472 | |
| 5473 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
| 5474 | |
| 5475 | for (entry = first_abbrev; entry; entry = entry->next) |
| 5476 | { |
| 5477 | abbrev_attr *attr; |
| 5478 | |
| 5479 | printf (" %ld %s [%s]\n", |
| 5480 | entry->entry, |
| 5481 | get_TAG_name (entry->tag), |
| 5482 | entry->children ? _("has children") : _("no children")); |
| 5483 | |
| 5484 | for (attr = entry->first_attr; attr; attr = attr->next) |
| 5485 | { |
| 5486 | printf (" %-18s %s", |
| 5487 | get_AT_name (attr->attribute), |
| 5488 | get_FORM_name (attr->form)); |
| 5489 | if (attr->form == DW_FORM_implicit_const) |
| 5490 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); |
| 5491 | putchar ('\n'); |
| 5492 | } |
| 5493 | } |
| 5494 | } |
| 5495 | while (start); |
| 5496 | |
| 5497 | printf ("\n"); |
| 5498 | |
| 5499 | return 1; |
| 5500 | } |
| 5501 | |
| 5502 | /* Return true when ADDR is the maximum address, when addresses are |
| 5503 | POINTER_SIZE bytes long. */ |
| 5504 | |
| 5505 | static bfd_boolean |
| 5506 | is_max_address (dwarf_vma addr, unsigned int pointer_size) |
| 5507 | { |
| 5508 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); |
| 5509 | return ((addr & mask) == mask); |
| 5510 | } |
| 5511 | |
| 5512 | /* Display a view pair list starting at *VSTART_PTR and ending at |
| 5513 | VLISTEND within SECTION. */ |
| 5514 | |
| 5515 | static void |
| 5516 | display_view_pair_list (struct dwarf_section *section, |
| 5517 | unsigned char **vstart_ptr, |
| 5518 | unsigned int debug_info_entry, |
| 5519 | unsigned char *vlistend) |
| 5520 | { |
| 5521 | unsigned char *vstart = *vstart_ptr; |
| 5522 | unsigned char *section_end = section->start + section->size; |
| 5523 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; |
| 5524 | |
| 5525 | if (vlistend < section_end) |
| 5526 | section_end = vlistend; |
| 5527 | |
| 5528 | putchar ('\n'); |
| 5529 | |
| 5530 | while (vstart < section_end) |
| 5531 | { |
| 5532 | dwarf_vma off = vstart - section->start; |
| 5533 | dwarf_vma vbegin, vend; |
| 5534 | |
| 5535 | unsigned int bytes_read; |
| 5536 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); |
| 5537 | vstart += bytes_read; |
| 5538 | if (vstart == section_end) |
| 5539 | { |
| 5540 | vstart -= bytes_read; |
| 5541 | break; |
| 5542 | } |
| 5543 | |
| 5544 | vend = read_uleb128 (vstart, &bytes_read, section_end); |
| 5545 | vstart += bytes_read; |
| 5546 | |
| 5547 | printf (" %8.8lx ", (unsigned long) off); |
| 5548 | |
| 5549 | print_dwarf_view (vbegin, pointer_size, 1); |
| 5550 | print_dwarf_view (vend, pointer_size, 1); |
| 5551 | printf (_("location view pair\n")); |
| 5552 | } |
| 5553 | |
| 5554 | putchar ('\n'); |
| 5555 | *vstart_ptr = vstart; |
| 5556 | } |
| 5557 | |
| 5558 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
| 5559 | |
| 5560 | static void |
| 5561 | display_loc_list (struct dwarf_section *section, |
| 5562 | unsigned char **start_ptr, |
| 5563 | unsigned int debug_info_entry, |
| 5564 | dwarf_vma offset, |
| 5565 | dwarf_vma base_address, |
| 5566 | unsigned char **vstart_ptr, |
| 5567 | int has_frame_base) |
| 5568 | { |
| 5569 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
| 5570 | unsigned char *section_end = section->start + section->size; |
| 5571 | unsigned long cu_offset; |
| 5572 | unsigned int pointer_size; |
| 5573 | unsigned int offset_size; |
| 5574 | int dwarf_version; |
| 5575 | |
| 5576 | dwarf_vma begin; |
| 5577 | dwarf_vma end; |
| 5578 | unsigned short length; |
| 5579 | int need_frame_base; |
| 5580 | |
| 5581 | if (debug_info_entry >= num_debug_info_entries) |
| 5582 | { |
| 5583 | warn (_("No debug information available for loc lists of entry: %u\n"), |
| 5584 | debug_info_entry); |
| 5585 | return; |
| 5586 | } |
| 5587 | |
| 5588 | cu_offset = debug_information [debug_info_entry].cu_offset; |
| 5589 | pointer_size = debug_information [debug_info_entry].pointer_size; |
| 5590 | offset_size = debug_information [debug_info_entry].offset_size; |
| 5591 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
| 5592 | |
| 5593 | if (pointer_size < 2 || pointer_size > 8) |
| 5594 | { |
| 5595 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
| 5596 | pointer_size, debug_info_entry); |
| 5597 | return; |
| 5598 | } |
| 5599 | |
| 5600 | while (1) |
| 5601 | { |
| 5602 | dwarf_vma off = offset + (start - *start_ptr); |
| 5603 | dwarf_vma vbegin = vm1, vend = vm1; |
| 5604 | |
| 5605 | if (start + 2 * pointer_size > section_end) |
| 5606 | { |
| 5607 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5608 | (unsigned long) offset); |
| 5609 | break; |
| 5610 | } |
| 5611 | |
| 5612 | printf (" %8.8lx ", (unsigned long) off); |
| 5613 | |
| 5614 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
| 5615 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); |
| 5616 | |
| 5617 | if (begin == 0 && end == 0) |
| 5618 | { |
| 5619 | /* PR 18374: In a object file we can have a location list that |
| 5620 | starts with a begin and end of 0 because there are relocations |
| 5621 | that need to be applied to the addresses. Actually applying |
| 5622 | the relocations now does not help as they will probably resolve |
| 5623 | to 0, since the object file has not been fully linked. Real |
| 5624 | end of list markers will not have any relocations against them. */ |
| 5625 | if (! reloc_at (section, off) |
| 5626 | && ! reloc_at (section, off + pointer_size)) |
| 5627 | { |
| 5628 | printf (_("<End of list>\n")); |
| 5629 | break; |
| 5630 | } |
| 5631 | } |
| 5632 | |
| 5633 | /* Check base address specifiers. */ |
| 5634 | if (is_max_address (begin, pointer_size) |
| 5635 | && !is_max_address (end, pointer_size)) |
| 5636 | { |
| 5637 | base_address = end; |
| 5638 | print_dwarf_vma (begin, pointer_size); |
| 5639 | print_dwarf_vma (end, pointer_size); |
| 5640 | printf (_("(base address)\n")); |
| 5641 | continue; |
| 5642 | } |
| 5643 | |
| 5644 | if (vstart) |
| 5645 | { |
| 5646 | unsigned int bytes_read; |
| 5647 | |
| 5648 | off = offset + (vstart - *start_ptr); |
| 5649 | |
| 5650 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); |
| 5651 | vstart += bytes_read; |
| 5652 | print_dwarf_view (vbegin, pointer_size, 1); |
| 5653 | |
| 5654 | vend = read_uleb128 (vstart, &bytes_read, section_end); |
| 5655 | vstart += bytes_read; |
| 5656 | print_dwarf_view (vend, pointer_size, 1); |
| 5657 | |
| 5658 | printf (_("views at %8.8lx for:\n %*s "), |
| 5659 | (unsigned long) off, 8, ""); |
| 5660 | } |
| 5661 | |
| 5662 | if (start + 2 > section_end) |
| 5663 | { |
| 5664 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5665 | (unsigned long) offset); |
| 5666 | break; |
| 5667 | } |
| 5668 | |
| 5669 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
| 5670 | |
| 5671 | if (start + length > section_end) |
| 5672 | { |
| 5673 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5674 | (unsigned long) offset); |
| 5675 | break; |
| 5676 | } |
| 5677 | |
| 5678 | print_dwarf_vma (begin + base_address, pointer_size); |
| 5679 | print_dwarf_vma (end + base_address, pointer_size); |
| 5680 | |
| 5681 | putchar ('('); |
| 5682 | need_frame_base = decode_location_expression (start, |
| 5683 | pointer_size, |
| 5684 | offset_size, |
| 5685 | dwarf_version, |
| 5686 | length, |
| 5687 | cu_offset, section); |
| 5688 | putchar (')'); |
| 5689 | |
| 5690 | if (need_frame_base && !has_frame_base) |
| 5691 | printf (_(" [without DW_AT_frame_base]")); |
| 5692 | |
| 5693 | if (begin == end && vbegin == vend) |
| 5694 | fputs (_(" (start == end)"), stdout); |
| 5695 | else if (begin > end || (begin == end && vbegin > vend)) |
| 5696 | fputs (_(" (start > end)"), stdout); |
| 5697 | |
| 5698 | putchar ('\n'); |
| 5699 | |
| 5700 | start += length; |
| 5701 | } |
| 5702 | |
| 5703 | *start_ptr = start; |
| 5704 | *vstart_ptr = vstart; |
| 5705 | } |
| 5706 | |
| 5707 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
| 5708 | |
| 5709 | static void |
| 5710 | display_loclists_list (struct dwarf_section *section, |
| 5711 | unsigned char **start_ptr, |
| 5712 | unsigned int debug_info_entry, |
| 5713 | dwarf_vma offset, |
| 5714 | dwarf_vma base_address, |
| 5715 | unsigned char **vstart_ptr, |
| 5716 | int has_frame_base) |
| 5717 | { |
| 5718 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
| 5719 | unsigned char *section_end = section->start + section->size; |
| 5720 | unsigned long cu_offset; |
| 5721 | unsigned int pointer_size; |
| 5722 | unsigned int offset_size; |
| 5723 | int dwarf_version; |
| 5724 | unsigned int bytes_read; |
| 5725 | |
| 5726 | /* Initialize it due to a false compiler warning. */ |
| 5727 | dwarf_vma begin = -1, vbegin = -1; |
| 5728 | dwarf_vma end = -1, vend = -1; |
| 5729 | dwarf_vma length; |
| 5730 | int need_frame_base; |
| 5731 | |
| 5732 | if (debug_info_entry >= num_debug_info_entries) |
| 5733 | { |
| 5734 | warn (_("No debug information available for " |
| 5735 | "loclists lists of entry: %u\n"), |
| 5736 | debug_info_entry); |
| 5737 | return; |
| 5738 | } |
| 5739 | |
| 5740 | cu_offset = debug_information [debug_info_entry].cu_offset; |
| 5741 | pointer_size = debug_information [debug_info_entry].pointer_size; |
| 5742 | offset_size = debug_information [debug_info_entry].offset_size; |
| 5743 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
| 5744 | |
| 5745 | if (pointer_size < 2 || pointer_size > 8) |
| 5746 | { |
| 5747 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
| 5748 | pointer_size, debug_info_entry); |
| 5749 | return; |
| 5750 | } |
| 5751 | |
| 5752 | while (1) |
| 5753 | { |
| 5754 | dwarf_vma off = offset + (start - *start_ptr); |
| 5755 | enum dwarf_location_list_entry_type llet; |
| 5756 | |
| 5757 | if (start + 1 > section_end) |
| 5758 | { |
| 5759 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5760 | (unsigned long) offset); |
| 5761 | break; |
| 5762 | } |
| 5763 | |
| 5764 | printf (" %8.8lx ", (unsigned long) off); |
| 5765 | |
| 5766 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); |
| 5767 | |
| 5768 | if (vstart && llet == DW_LLE_offset_pair) |
| 5769 | { |
| 5770 | off = offset + (vstart - *start_ptr); |
| 5771 | |
| 5772 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); |
| 5773 | vstart += bytes_read; |
| 5774 | print_dwarf_view (vbegin, pointer_size, 1); |
| 5775 | |
| 5776 | vend = read_uleb128 (vstart, &bytes_read, section_end); |
| 5777 | vstart += bytes_read; |
| 5778 | print_dwarf_view (vend, pointer_size, 1); |
| 5779 | |
| 5780 | printf (_("views at %8.8lx for:\n %*s "), |
| 5781 | (unsigned long) off, 8, ""); |
| 5782 | } |
| 5783 | |
| 5784 | switch (llet) |
| 5785 | { |
| 5786 | case DW_LLE_end_of_list: |
| 5787 | printf (_("<End of list>\n")); |
| 5788 | break; |
| 5789 | case DW_LLE_offset_pair: |
| 5790 | begin = read_uleb128 (start, &bytes_read, section_end); |
| 5791 | start += bytes_read; |
| 5792 | end = read_uleb128 (start, &bytes_read, section_end); |
| 5793 | start += bytes_read; |
| 5794 | break; |
| 5795 | case DW_LLE_base_address: |
| 5796 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, |
| 5797 | section_end); |
| 5798 | print_dwarf_vma (base_address, pointer_size); |
| 5799 | printf (_("(base address)\n")); |
| 5800 | break; |
| 5801 | #ifdef DW_LLE_view_pair |
| 5802 | case DW_LLE_view_pair: |
| 5803 | if (vstart) |
| 5804 | printf (_("View pair entry in loclist with locviews attribute\n")); |
| 5805 | vbegin = read_uleb128 (start, &bytes_read, section_end); |
| 5806 | start += bytes_read; |
| 5807 | print_dwarf_view (vbegin, pointer_size, 1); |
| 5808 | |
| 5809 | vend = read_uleb128 (start, &bytes_read, section_end); |
| 5810 | start += bytes_read; |
| 5811 | print_dwarf_view (vend, pointer_size, 1); |
| 5812 | |
| 5813 | printf (_("views for:\n")); |
| 5814 | continue; |
| 5815 | #endif |
| 5816 | default: |
| 5817 | error (_("Invalid location list entry type %d\n"), llet); |
| 5818 | return; |
| 5819 | } |
| 5820 | if (llet == DW_LLE_end_of_list) |
| 5821 | break; |
| 5822 | if (llet != DW_LLE_offset_pair) |
| 5823 | continue; |
| 5824 | |
| 5825 | if (start + 2 > section_end) |
| 5826 | { |
| 5827 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5828 | (unsigned long) offset); |
| 5829 | break; |
| 5830 | } |
| 5831 | |
| 5832 | length = read_uleb128 (start, &bytes_read, section_end); |
| 5833 | start += bytes_read; |
| 5834 | |
| 5835 | print_dwarf_vma (begin + base_address, pointer_size); |
| 5836 | print_dwarf_vma (end + base_address, pointer_size); |
| 5837 | |
| 5838 | putchar ('('); |
| 5839 | need_frame_base = decode_location_expression (start, |
| 5840 | pointer_size, |
| 5841 | offset_size, |
| 5842 | dwarf_version, |
| 5843 | length, |
| 5844 | cu_offset, section); |
| 5845 | putchar (')'); |
| 5846 | |
| 5847 | if (need_frame_base && !has_frame_base) |
| 5848 | printf (_(" [without DW_AT_frame_base]")); |
| 5849 | |
| 5850 | if (begin == end && vbegin == vend) |
| 5851 | fputs (_(" (start == end)"), stdout); |
| 5852 | else if (begin > end || (begin == end && vbegin > vend)) |
| 5853 | fputs (_(" (start > end)"), stdout); |
| 5854 | |
| 5855 | putchar ('\n'); |
| 5856 | |
| 5857 | start += length; |
| 5858 | vbegin = vend = -1; |
| 5859 | } |
| 5860 | |
| 5861 | if (vbegin != vm1 || vend != vm1) |
| 5862 | printf (_("Trailing view pair not used in a range")); |
| 5863 | |
| 5864 | *start_ptr = start; |
| 5865 | *vstart_ptr = vstart; |
| 5866 | } |
| 5867 | |
| 5868 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
| 5869 | right-adjusted in a field of length LEN, and followed by a space. */ |
| 5870 | |
| 5871 | static void |
| 5872 | print_addr_index (unsigned int idx, unsigned int len) |
| 5873 | { |
| 5874 | static char buf[15]; |
| 5875 | snprintf (buf, sizeof (buf), "[%d]", idx); |
| 5876 | printf ("%*s ", len, buf); |
| 5877 | } |
| 5878 | |
| 5879 | /* Display a location list from a .dwo section. It uses address indexes rather |
| 5880 | than embedded addresses. This code closely follows display_loc_list, but the |
| 5881 | two are sufficiently different that combining things is very ugly. */ |
| 5882 | |
| 5883 | static void |
| 5884 | display_loc_list_dwo (struct dwarf_section *section, |
| 5885 | unsigned char **start_ptr, |
| 5886 | unsigned int debug_info_entry, |
| 5887 | dwarf_vma offset, |
| 5888 | unsigned char **vstart_ptr, |
| 5889 | int has_frame_base) |
| 5890 | { |
| 5891 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
| 5892 | unsigned char *section_end = section->start + section->size; |
| 5893 | unsigned long cu_offset; |
| 5894 | unsigned int pointer_size; |
| 5895 | unsigned int offset_size; |
| 5896 | int dwarf_version; |
| 5897 | int entry_type; |
| 5898 | unsigned short length; |
| 5899 | int need_frame_base; |
| 5900 | unsigned int idx; |
| 5901 | unsigned int bytes_read; |
| 5902 | |
| 5903 | if (debug_info_entry >= num_debug_info_entries) |
| 5904 | { |
| 5905 | warn (_("No debug information for loc lists of entry: %u\n"), |
| 5906 | debug_info_entry); |
| 5907 | return; |
| 5908 | } |
| 5909 | |
| 5910 | cu_offset = debug_information [debug_info_entry].cu_offset; |
| 5911 | pointer_size = debug_information [debug_info_entry].pointer_size; |
| 5912 | offset_size = debug_information [debug_info_entry].offset_size; |
| 5913 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
| 5914 | |
| 5915 | if (pointer_size < 2 || pointer_size > 8) |
| 5916 | { |
| 5917 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
| 5918 | pointer_size, debug_info_entry); |
| 5919 | return; |
| 5920 | } |
| 5921 | |
| 5922 | while (1) |
| 5923 | { |
| 5924 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
| 5925 | |
| 5926 | if (start >= section_end) |
| 5927 | { |
| 5928 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 5929 | (unsigned long) offset); |
| 5930 | break; |
| 5931 | } |
| 5932 | |
| 5933 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
| 5934 | |
| 5935 | if (vstart) |
| 5936 | switch (entry_type) |
| 5937 | { |
| 5938 | default: |
| 5939 | break; |
| 5940 | |
| 5941 | case 2: |
| 5942 | case 3: |
| 5943 | case 4: |
| 5944 | { |
| 5945 | dwarf_vma view; |
| 5946 | dwarf_vma off = offset + (vstart - *start_ptr); |
| 5947 | |
| 5948 | view = read_uleb128 (vstart, &bytes_read, section_end); |
| 5949 | vstart += bytes_read; |
| 5950 | print_dwarf_view (view, 8, 1); |
| 5951 | |
| 5952 | view = read_uleb128 (vstart, &bytes_read, section_end); |
| 5953 | vstart += bytes_read; |
| 5954 | print_dwarf_view (view, 8, 1); |
| 5955 | |
| 5956 | printf (_("views at %8.8lx for:\n %*s "), |
| 5957 | (unsigned long) off, 8, ""); |
| 5958 | |
| 5959 | } |
| 5960 | break; |
| 5961 | } |
| 5962 | |
| 5963 | switch (entry_type) |
| 5964 | { |
| 5965 | case 0: /* A terminating entry. */ |
| 5966 | *start_ptr = start; |
| 5967 | *vstart_ptr = vstart; |
| 5968 | printf (_("<End of list>\n")); |
| 5969 | return; |
| 5970 | case 1: /* A base-address entry. */ |
| 5971 | idx = read_uleb128 (start, &bytes_read, section_end); |
| 5972 | start += bytes_read; |
| 5973 | print_addr_index (idx, 8); |
| 5974 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
| 5975 | printf (_("(base address selection entry)\n")); |
| 5976 | continue; |
| 5977 | case 2: /* A start/end entry. */ |
| 5978 | idx = read_uleb128 (start, &bytes_read, section_end); |
| 5979 | start += bytes_read; |
| 5980 | print_addr_index (idx, 8); |
| 5981 | idx = read_uleb128 (start, &bytes_read, section_end); |
| 5982 | start += bytes_read; |
| 5983 | print_addr_index (idx, 8); |
| 5984 | break; |
| 5985 | case 3: /* A start/length entry. */ |
| 5986 | idx = read_uleb128 (start, &bytes_read, section_end); |
| 5987 | start += bytes_read; |
| 5988 | print_addr_index (idx, 8); |
| 5989 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
| 5990 | printf ("%08x ", idx); |
| 5991 | break; |
| 5992 | case 4: /* An offset pair entry. */ |
| 5993 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
| 5994 | printf ("%08x ", idx); |
| 5995 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
| 5996 | printf ("%08x ", idx); |
| 5997 | break; |
| 5998 | default: |
| 5999 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); |
| 6000 | *start_ptr = start; |
| 6001 | *vstart_ptr = vstart; |
| 6002 | return; |
| 6003 | } |
| 6004 | |
| 6005 | if (start + 2 > section_end) |
| 6006 | { |
| 6007 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 6008 | (unsigned long) offset); |
| 6009 | break; |
| 6010 | } |
| 6011 | |
| 6012 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
| 6013 | if (start + length > section_end) |
| 6014 | { |
| 6015 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
| 6016 | (unsigned long) offset); |
| 6017 | break; |
| 6018 | } |
| 6019 | |
| 6020 | putchar ('('); |
| 6021 | need_frame_base = decode_location_expression (start, |
| 6022 | pointer_size, |
| 6023 | offset_size, |
| 6024 | dwarf_version, |
| 6025 | length, |
| 6026 | cu_offset, section); |
| 6027 | putchar (')'); |
| 6028 | |
| 6029 | if (need_frame_base && !has_frame_base) |
| 6030 | printf (_(" [without DW_AT_frame_base]")); |
| 6031 | |
| 6032 | putchar ('\n'); |
| 6033 | |
| 6034 | start += length; |
| 6035 | } |
| 6036 | |
| 6037 | *start_ptr = start; |
| 6038 | *vstart_ptr = vstart; |
| 6039 | } |
| 6040 | |
| 6041 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
| 6042 | loc_views. */ |
| 6043 | |
| 6044 | static dwarf_vma *loc_offsets, *loc_views; |
| 6045 | |
| 6046 | static int |
| 6047 | loc_offsets_compar (const void *ap, const void *bp) |
| 6048 | { |
| 6049 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; |
| 6050 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; |
| 6051 | |
| 6052 | int ret = (a > b) - (b > a); |
| 6053 | if (ret) |
| 6054 | return ret; |
| 6055 | |
| 6056 | a = loc_views[*(const unsigned int *) ap]; |
| 6057 | b = loc_views[*(const unsigned int *) bp]; |
| 6058 | |
| 6059 | ret = (a > b) - (b > a); |
| 6060 | |
| 6061 | return ret; |
| 6062 | } |
| 6063 | |
| 6064 | static int |
| 6065 | display_debug_loc (struct dwarf_section *section, void *file) |
| 6066 | { |
| 6067 | unsigned char *start = section->start, *vstart = NULL; |
| 6068 | unsigned long bytes; |
| 6069 | unsigned char *section_begin = start; |
| 6070 | unsigned int num_loc_list = 0; |
| 6071 | unsigned long last_offset = 0; |
| 6072 | unsigned long last_view = 0; |
| 6073 | unsigned int first = 0; |
| 6074 | unsigned int i; |
| 6075 | unsigned int j; |
| 6076 | int seen_first_offset = 0; |
| 6077 | int locs_sorted = 1; |
| 6078 | unsigned char *next = start, *vnext = vstart; |
| 6079 | unsigned int *array = NULL; |
| 6080 | const char *suffix = strrchr (section->name, '.'); |
| 6081 | bfd_boolean is_dwo = FALSE; |
| 6082 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
| 6083 | dwarf_vma expected_start = 0; |
| 6084 | |
| 6085 | if (suffix && strcmp (suffix, ".dwo") == 0) |
| 6086 | is_dwo = TRUE; |
| 6087 | |
| 6088 | bytes = section->size; |
| 6089 | |
| 6090 | if (bytes == 0) |
| 6091 | { |
| 6092 | printf (_("\nThe %s section is empty.\n"), section->name); |
| 6093 | return 0; |
| 6094 | } |
| 6095 | |
| 6096 | if (is_loclists) |
| 6097 | { |
| 6098 | unsigned char *hdrptr = section_begin; |
| 6099 | dwarf_vma ll_length; |
| 6100 | unsigned short ll_version; |
| 6101 | unsigned char *end = section_begin + section->size; |
| 6102 | unsigned char address_size, segment_selector_size; |
| 6103 | uint32_t offset_entry_count; |
| 6104 | |
| 6105 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); |
| 6106 | if (ll_length == 0xffffffff) |
| 6107 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); |
| 6108 | |
| 6109 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); |
| 6110 | if (ll_version != 5) |
| 6111 | { |
| 6112 | warn (_("The %s section contains corrupt or " |
| 6113 | "unsupported version number: %d.\n"), |
| 6114 | section->name, ll_version); |
| 6115 | return 0; |
| 6116 | } |
| 6117 | |
| 6118 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); |
| 6119 | |
| 6120 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); |
| 6121 | if (segment_selector_size != 0) |
| 6122 | { |
| 6123 | warn (_("The %s section contains " |
| 6124 | "unsupported segment selector size: %d.\n"), |
| 6125 | section->name, segment_selector_size); |
| 6126 | return 0; |
| 6127 | } |
| 6128 | |
| 6129 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); |
| 6130 | if (offset_entry_count != 0) |
| 6131 | { |
| 6132 | warn (_("The %s section contains " |
| 6133 | "unsupported offset entry count: %d.\n"), |
| 6134 | section->name, offset_entry_count); |
| 6135 | return 0; |
| 6136 | } |
| 6137 | |
| 6138 | expected_start = hdrptr - section_begin; |
| 6139 | } |
| 6140 | |
| 6141 | if (load_debug_info (file) == 0) |
| 6142 | { |
| 6143 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
| 6144 | section->name); |
| 6145 | return 0; |
| 6146 | } |
| 6147 | |
| 6148 | /* Check the order of location list in .debug_info section. If |
| 6149 | offsets of location lists are in the ascending order, we can |
| 6150 | use `debug_information' directly. */ |
| 6151 | for (i = 0; i < num_debug_info_entries; i++) |
| 6152 | { |
| 6153 | unsigned int num; |
| 6154 | |
| 6155 | num = debug_information [i].num_loc_offsets; |
| 6156 | if (num > num_loc_list) |
| 6157 | num_loc_list = num; |
| 6158 | |
| 6159 | /* Check if we can use `debug_information' directly. */ |
| 6160 | if (locs_sorted && num != 0) |
| 6161 | { |
| 6162 | if (!seen_first_offset) |
| 6163 | { |
| 6164 | /* This is the first location list. */ |
| 6165 | last_offset = debug_information [i].loc_offsets [0]; |
| 6166 | last_view = debug_information [i].loc_views [0]; |
| 6167 | first = i; |
| 6168 | seen_first_offset = 1; |
| 6169 | j = 1; |
| 6170 | } |
| 6171 | else |
| 6172 | j = 0; |
| 6173 | |
| 6174 | for (; j < num; j++) |
| 6175 | { |
| 6176 | if (last_offset > |
| 6177 | debug_information [i].loc_offsets [j] |
| 6178 | || (last_offset == debug_information [i].loc_offsets [j] |
| 6179 | && last_view > debug_information [i].loc_views [j])) |
| 6180 | { |
| 6181 | locs_sorted = 0; |
| 6182 | break; |
| 6183 | } |
| 6184 | last_offset = debug_information [i].loc_offsets [j]; |
| 6185 | last_view = debug_information [i].loc_views [j]; |
| 6186 | } |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | if (!seen_first_offset) |
| 6191 | error (_("No location lists in .debug_info section!\n")); |
| 6192 | |
| 6193 | if (debug_information [first].num_loc_offsets > 0 |
| 6194 | && debug_information [first].loc_offsets [0] != expected_start |
| 6195 | && debug_information [first].loc_views [0] != expected_start) |
| 6196 | warn (_("Location lists in %s section start at 0x%s\n"), |
| 6197 | section->name, |
| 6198 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); |
| 6199 | |
| 6200 | if (!locs_sorted) |
| 6201 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); |
| 6202 | |
| 6203 | introduce (section, FALSE); |
| 6204 | |
| 6205 | if (reloc_at (section, 0)) |
| 6206 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); |
| 6207 | |
| 6208 | printf (_(" Offset Begin End Expression\n")); |
| 6209 | |
| 6210 | seen_first_offset = 0; |
| 6211 | for (i = first; i < num_debug_info_entries; i++) |
| 6212 | { |
| 6213 | dwarf_vma offset, voffset; |
| 6214 | dwarf_vma base_address; |
| 6215 | unsigned int k; |
| 6216 | int has_frame_base; |
| 6217 | |
| 6218 | if (!locs_sorted) |
| 6219 | { |
| 6220 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
| 6221 | array[k] = k; |
| 6222 | loc_offsets = debug_information [i].loc_offsets; |
| 6223 | loc_views = debug_information [i].loc_views; |
| 6224 | qsort (array, debug_information [i].num_loc_offsets, |
| 6225 | sizeof (*array), loc_offsets_compar); |
| 6226 | } |
| 6227 | |
| 6228 | int adjacent_view_loclists = 1; |
| 6229 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
| 6230 | { |
| 6231 | j = locs_sorted ? k : array[k]; |
| 6232 | if (k |
| 6233 | && (debug_information [i].loc_offsets [locs_sorted |
| 6234 | ? k - 1 : array [k - 1]] |
| 6235 | == debug_information [i].loc_offsets [j]) |
| 6236 | && (debug_information [i].loc_views [locs_sorted |
| 6237 | ? k - 1 : array [k - 1]] |
| 6238 | == debug_information [i].loc_views [j])) |
| 6239 | continue; |
| 6240 | has_frame_base = debug_information [i].have_frame_base [j]; |
| 6241 | offset = debug_information [i].loc_offsets [j]; |
| 6242 | next = section_begin + offset; |
| 6243 | voffset = debug_information [i].loc_views [j]; |
| 6244 | if (voffset != vm1) |
| 6245 | vnext = section_begin + voffset; |
| 6246 | else |
| 6247 | vnext = NULL; |
| 6248 | base_address = debug_information [i].base_address; |
| 6249 | |
| 6250 | if (vnext && vnext < next) |
| 6251 | { |
| 6252 | vstart = vnext; |
| 6253 | display_view_pair_list (section, &vstart, i, next); |
| 6254 | if (start == vnext) |
| 6255 | start = vstart; |
| 6256 | } |
| 6257 | |
| 6258 | if (!seen_first_offset || !adjacent_view_loclists) |
| 6259 | seen_first_offset = 1; |
| 6260 | else |
| 6261 | { |
| 6262 | if (start < next) |
| 6263 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), |
| 6264 | (unsigned long) (start - section_begin), |
| 6265 | (unsigned long) offset); |
| 6266 | else if (start > next) |
| 6267 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), |
| 6268 | (unsigned long) (start - section_begin), |
| 6269 | (unsigned long) offset); |
| 6270 | } |
| 6271 | start = next; |
| 6272 | vstart = vnext; |
| 6273 | |
| 6274 | if (offset >= bytes) |
| 6275 | { |
| 6276 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), |
| 6277 | (unsigned long) offset); |
| 6278 | continue; |
| 6279 | } |
| 6280 | |
| 6281 | if (vnext && voffset >= bytes) |
| 6282 | { |
| 6283 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), |
| 6284 | (unsigned long) voffset); |
| 6285 | continue; |
| 6286 | } |
| 6287 | |
| 6288 | if (!is_loclists) |
| 6289 | { |
| 6290 | if (is_dwo) |
| 6291 | display_loc_list_dwo (section, &start, i, offset, |
| 6292 | &vstart, has_frame_base); |
| 6293 | else |
| 6294 | display_loc_list (section, &start, i, offset, base_address, |
| 6295 | &vstart, has_frame_base); |
| 6296 | } |
| 6297 | else |
| 6298 | { |
| 6299 | if (is_dwo) |
| 6300 | warn (_("DWO is not yet supported.\n")); |
| 6301 | else |
| 6302 | display_loclists_list (section, &start, i, offset, base_address, |
| 6303 | &vstart, has_frame_base); |
| 6304 | } |
| 6305 | |
| 6306 | /* FIXME: this arrangement is quite simplistic. Nothing |
| 6307 | requires locview lists to be adjacent to corresponding |
| 6308 | loclists, and a single loclist could be augmented by |
| 6309 | different locview lists, and vice-versa, unlikely as it |
| 6310 | is that it would make sense to do so. Hopefully we'll |
| 6311 | have view pair support built into loclists before we ever |
| 6312 | need to address all these possibilities. */ |
| 6313 | if (adjacent_view_loclists && vnext |
| 6314 | && vnext != start && vstart != next) |
| 6315 | { |
| 6316 | adjacent_view_loclists = 0; |
| 6317 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); |
| 6318 | } |
| 6319 | |
| 6320 | if (vnext && vnext == start) |
| 6321 | display_view_pair_list (section, &start, i, vstart); |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | if (start < section->start + section->size) |
| 6326 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
| 6327 | "There are %ld unused bytes at the end of section %s\n", |
| 6328 | (long) (section->start + section->size - start)), |
| 6329 | (long) (section->start + section->size - start), section->name); |
| 6330 | putchar ('\n'); |
| 6331 | free (array); |
| 6332 | return 1; |
| 6333 | } |
| 6334 | |
| 6335 | static int |
| 6336 | display_debug_str (struct dwarf_section *section, |
| 6337 | void *file ATTRIBUTE_UNUSED) |
| 6338 | { |
| 6339 | unsigned char *start = section->start; |
| 6340 | unsigned long bytes = section->size; |
| 6341 | dwarf_vma addr = section->address; |
| 6342 | |
| 6343 | if (bytes == 0) |
| 6344 | { |
| 6345 | printf (_("\nThe %s section is empty.\n"), section->name); |
| 6346 | return 0; |
| 6347 | } |
| 6348 | |
| 6349 | introduce (section, FALSE); |
| 6350 | |
| 6351 | while (bytes) |
| 6352 | { |
| 6353 | int j; |
| 6354 | int k; |
| 6355 | int lbytes; |
| 6356 | |
| 6357 | lbytes = (bytes > 16 ? 16 : bytes); |
| 6358 | |
| 6359 | printf (" 0x%8.8lx ", (unsigned long) addr); |
| 6360 | |
| 6361 | for (j = 0; j < 16; j++) |
| 6362 | { |
| 6363 | if (j < lbytes) |
| 6364 | printf ("%2.2x", start[j]); |
| 6365 | else |
| 6366 | printf (" "); |
| 6367 | |
| 6368 | if ((j & 3) == 3) |
| 6369 | printf (" "); |
| 6370 | } |
| 6371 | |
| 6372 | for (j = 0; j < lbytes; j++) |
| 6373 | { |
| 6374 | k = start[j]; |
| 6375 | if (k >= ' ' && k < 0x80) |
| 6376 | printf ("%c", k); |
| 6377 | else |
| 6378 | printf ("."); |
| 6379 | } |
| 6380 | |
| 6381 | putchar ('\n'); |
| 6382 | |
| 6383 | start += lbytes; |
| 6384 | addr += lbytes; |
| 6385 | bytes -= lbytes; |
| 6386 | } |
| 6387 | |
| 6388 | putchar ('\n'); |
| 6389 | |
| 6390 | return 1; |
| 6391 | } |
| 6392 | |
| 6393 | static int |
| 6394 | display_debug_info (struct dwarf_section *section, void *file) |
| 6395 | { |
| 6396 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
| 6397 | } |
| 6398 | |
| 6399 | static int |
| 6400 | display_debug_types (struct dwarf_section *section, void *file) |
| 6401 | { |
| 6402 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
| 6403 | } |
| 6404 | |
| 6405 | static int |
| 6406 | display_trace_info (struct dwarf_section *section, void *file) |
| 6407 | { |
| 6408 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
| 6409 | } |
| 6410 | |
| 6411 | static int |
| 6412 | display_debug_aranges (struct dwarf_section *section, |
| 6413 | void *file ATTRIBUTE_UNUSED) |
| 6414 | { |
| 6415 | unsigned char *start = section->start; |
| 6416 | unsigned char *end = start + section->size; |
| 6417 | |
| 6418 | introduce (section, FALSE); |
| 6419 | |
| 6420 | /* It does not matter if this load fails, |
| 6421 | we test for that later on. */ |
| 6422 | load_debug_info (file); |
| 6423 | |
| 6424 | while (start < end) |
| 6425 | { |
| 6426 | unsigned char *hdrptr; |
| 6427 | DWARF2_Internal_ARange arange; |
| 6428 | unsigned char *addr_ranges; |
| 6429 | dwarf_vma length; |
| 6430 | dwarf_vma address; |
| 6431 | unsigned long sec_off; |
| 6432 | unsigned char address_size; |
| 6433 | int excess; |
| 6434 | unsigned int offset_size; |
| 6435 | unsigned int initial_length_size; |
| 6436 | |
| 6437 | hdrptr = start; |
| 6438 | |
| 6439 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
| 6440 | if (arange.ar_length == 0xffffffff) |
| 6441 | { |
| 6442 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
| 6443 | offset_size = 8; |
| 6444 | initial_length_size = 12; |
| 6445 | } |
| 6446 | else |
| 6447 | { |
| 6448 | offset_size = 4; |
| 6449 | initial_length_size = 4; |
| 6450 | } |
| 6451 | |
| 6452 | sec_off = hdrptr - section->start; |
| 6453 | if (sec_off + arange.ar_length < sec_off |
| 6454 | || sec_off + arange.ar_length > section->size) |
| 6455 | { |
| 6456 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
| 6457 | section->name, |
| 6458 | sec_off - initial_length_size, |
| 6459 | dwarf_vmatoa ("x", arange.ar_length)); |
| 6460 | break; |
| 6461 | } |
| 6462 | |
| 6463 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
| 6464 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); |
| 6465 | |
| 6466 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
| 6467 | && num_debug_info_entries > 0 |
| 6468 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) |
| 6469 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
| 6470 | (unsigned long) arange.ar_info_offset, section->name); |
| 6471 | |
| 6472 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
| 6473 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); |
| 6474 | |
| 6475 | if (arange.ar_version != 2 && arange.ar_version != 3) |
| 6476 | { |
| 6477 | /* PR 19872: A version number of 0 probably means that there is |
| 6478 | padding at the end of the .debug_aranges section. Gold puts |
| 6479 | it there when performing an incremental link, for example. |
| 6480 | So do not generate a warning in this case. */ |
| 6481 | if (arange.ar_version) |
| 6482 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); |
| 6483 | break; |
| 6484 | } |
| 6485 | |
| 6486 | printf (_(" Length: %ld\n"), |
| 6487 | (long) arange.ar_length); |
| 6488 | printf (_(" Version: %d\n"), arange.ar_version); |
| 6489 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
| 6490 | (unsigned long) arange.ar_info_offset); |
| 6491 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
| 6492 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); |
| 6493 | |
| 6494 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
| 6495 | |
| 6496 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
| 6497 | if (address_size == 0 || address_size > 8) |
| 6498 | { |
| 6499 | error (_("Invalid address size in %s section!\n"), |
| 6500 | section->name); |
| 6501 | break; |
| 6502 | } |
| 6503 | |
| 6504 | /* The DWARF spec does not require that the address size be a power |
| 6505 | of two, but we do. This will have to change if we ever encounter |
| 6506 | an uneven architecture. */ |
| 6507 | if ((address_size & (address_size - 1)) != 0) |
| 6508 | { |
| 6509 | warn (_("Pointer size + Segment size is not a power of two.\n")); |
| 6510 | break; |
| 6511 | } |
| 6512 | |
| 6513 | if (address_size > 4) |
| 6514 | printf (_("\n Address Length\n")); |
| 6515 | else |
| 6516 | printf (_("\n Address Length\n")); |
| 6517 | |
| 6518 | addr_ranges = hdrptr; |
| 6519 | |
| 6520 | /* Must pad to an alignment boundary that is twice the address size. */ |
| 6521 | excess = (hdrptr - start) % (2 * address_size); |
| 6522 | if (excess) |
| 6523 | addr_ranges += (2 * address_size) - excess; |
| 6524 | |
| 6525 | start += arange.ar_length + initial_length_size; |
| 6526 | |
| 6527 | while (addr_ranges + 2 * address_size <= start) |
| 6528 | { |
| 6529 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
| 6530 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); |
| 6531 | |
| 6532 | printf (" "); |
| 6533 | print_dwarf_vma (address, address_size); |
| 6534 | print_dwarf_vma (length, address_size); |
| 6535 | putchar ('\n'); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | printf ("\n"); |
| 6540 | |
| 6541 | return 1; |
| 6542 | } |
| 6543 | |
| 6544 | /* Comparison function for qsort. */ |
| 6545 | static int |
| 6546 | comp_addr_base (const void * v0, const void * v1) |
| 6547 | { |
| 6548 | debug_info *info0 = *(debug_info **) v0; |
| 6549 | debug_info *info1 = *(debug_info **) v1; |
| 6550 | return info0->addr_base - info1->addr_base; |
| 6551 | } |
| 6552 | |
| 6553 | /* Display the debug_addr section. */ |
| 6554 | static int |
| 6555 | display_debug_addr (struct dwarf_section *section, |
| 6556 | void *file) |
| 6557 | { |
| 6558 | debug_info **debug_addr_info; |
| 6559 | unsigned char *entry; |
| 6560 | unsigned char *end; |
| 6561 | unsigned int i; |
| 6562 | unsigned int count; |
| 6563 | |
| 6564 | if (section->size == 0) |
| 6565 | { |
| 6566 | printf (_("\nThe %s section is empty.\n"), section->name); |
| 6567 | return 0; |
| 6568 | } |
| 6569 | |
| 6570 | if (load_debug_info (file) == 0) |
| 6571 | { |
| 6572 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
| 6573 | section->name); |
| 6574 | return 0; |
| 6575 | } |
| 6576 | |
| 6577 | introduce (section, FALSE); |
| 6578 | |
| 6579 | /* PR 17531: file: cf38d01b. |
| 6580 | We use xcalloc because a corrupt file may not have initialised all of the |
| 6581 | fields in the debug_info structure, which means that the sort below might |
| 6582 | try to move uninitialised data. */ |
| 6583 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), |
| 6584 | sizeof (debug_info *)); |
| 6585 | |
| 6586 | count = 0; |
| 6587 | for (i = 0; i < num_debug_info_entries; i++) |
| 6588 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
| 6589 | { |
| 6590 | /* PR 17531: file: cf38d01b. */ |
| 6591 | if (debug_information[i].addr_base >= section->size) |
| 6592 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), |
| 6593 | (unsigned long) debug_information[i].addr_base, i); |
| 6594 | else |
| 6595 | debug_addr_info [count++] = debug_information + i; |
| 6596 | } |
| 6597 | |
| 6598 | /* Add a sentinel to make iteration convenient. */ |
| 6599 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); |
| 6600 | debug_addr_info [count]->addr_base = section->size; |
| 6601 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
| 6602 | |
| 6603 | for (i = 0; i < count; i++) |
| 6604 | { |
| 6605 | unsigned int idx; |
| 6606 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
| 6607 | |
| 6608 | printf (_(" For compilation unit at offset 0x%s:\n"), |
| 6609 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
| 6610 | |
| 6611 | printf (_("\tIndex\tAddress\n")); |
| 6612 | entry = section->start + debug_addr_info [i]->addr_base; |
| 6613 | end = section->start + debug_addr_info [i + 1]->addr_base; |
| 6614 | idx = 0; |
| 6615 | while (entry < end) |
| 6616 | { |
| 6617 | dwarf_vma base = byte_get (entry, address_size); |
| 6618 | printf (_("\t%d:\t"), idx); |
| 6619 | print_dwarf_vma (base, address_size); |
| 6620 | printf ("\n"); |
| 6621 | entry += address_size; |
| 6622 | idx++; |
| 6623 | } |
| 6624 | } |
| 6625 | printf ("\n"); |
| 6626 | |
| 6627 | free (debug_addr_info); |
| 6628 | return 1; |
| 6629 | } |
| 6630 | |
| 6631 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ |
| 6632 | |
| 6633 | static int |
| 6634 | display_debug_str_offsets (struct dwarf_section *section, |
| 6635 | void *file ATTRIBUTE_UNUSED) |
| 6636 | { |
| 6637 | if (section->size == 0) |
| 6638 | { |
| 6639 | printf (_("\nThe %s section is empty.\n"), section->name); |
| 6640 | return 0; |
| 6641 | } |
| 6642 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing |
| 6643 | what the offset size is for this section. */ |
| 6644 | return 1; |
| 6645 | } |
| 6646 | |
| 6647 | /* Each debug_information[x].range_lists[y] gets this representation for |
| 6648 | sorting purposes. */ |
| 6649 | |
| 6650 | struct range_entry |
| 6651 | { |
| 6652 | /* The debug_information[x].range_lists[y] value. */ |
| 6653 | dwarf_vma ranges_offset; |
| 6654 | |
| 6655 | /* Original debug_information to find parameters of the data. */ |
| 6656 | debug_info *debug_info_p; |
| 6657 | }; |
| 6658 | |
| 6659 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ |
| 6660 | |
| 6661 | static int |
| 6662 | range_entry_compar (const void *ap, const void *bp) |
| 6663 | { |
| 6664 | const struct range_entry *a_re = (const struct range_entry *) ap; |
| 6665 | const struct range_entry *b_re = (const struct range_entry *) bp; |
| 6666 | const dwarf_vma a = a_re->ranges_offset; |
| 6667 | const dwarf_vma b = b_re->ranges_offset; |
| 6668 | |
| 6669 | return (a > b) - (b > a); |
| 6670 | } |
| 6671 | |
| 6672 | static void |
| 6673 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, |
| 6674 | unsigned int pointer_size, unsigned long offset, |
| 6675 | unsigned long base_address) |
| 6676 | { |
| 6677 | while (start < finish) |
| 6678 | { |
| 6679 | dwarf_vma begin; |
| 6680 | dwarf_vma end; |
| 6681 | |
| 6682 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
| 6683 | if (start >= finish) |
| 6684 | break; |
| 6685 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
| 6686 | |
| 6687 | |
| 6688 | printf (" %8.8lx ", offset); |
| 6689 | |
| 6690 | if (begin == 0 && end == 0) |
| 6691 | { |
| 6692 | printf (_("<End of list>\n")); |
| 6693 | break; |
| 6694 | } |
| 6695 | |
| 6696 | /* Check base address specifiers. */ |
| 6697 | if (is_max_address (begin, pointer_size) |
| 6698 | && !is_max_address (end, pointer_size)) |
| 6699 | { |
| 6700 | base_address = end; |
| 6701 | print_dwarf_vma (begin, pointer_size); |
| 6702 | print_dwarf_vma (end, pointer_size); |
| 6703 | printf ("(base address)\n"); |
| 6704 | continue; |
| 6705 | } |
| 6706 | |
| 6707 | print_dwarf_vma (begin + base_address, pointer_size); |
| 6708 | print_dwarf_vma (end + base_address, pointer_size); |
| 6709 | |
| 6710 | if (begin == end) |
| 6711 | fputs (_("(start == end)"), stdout); |
| 6712 | else if (begin > end) |
| 6713 | fputs (_("(start > end)"), stdout); |
| 6714 | |
| 6715 | putchar ('\n'); |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | static void |
| 6720 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, |
| 6721 | unsigned int pointer_size, unsigned long offset, |
| 6722 | unsigned long base_address) |
| 6723 | { |
| 6724 | unsigned char *next = start; |
| 6725 | |
| 6726 | while (1) |
| 6727 | { |
| 6728 | unsigned long off = offset + (start - next); |
| 6729 | enum dwarf_range_list_entry rlet; |
| 6730 | /* Initialize it due to a false compiler warning. */ |
| 6731 | dwarf_vma begin = -1, length, end = -1; |
| 6732 | unsigned int bytes_read; |
| 6733 | |
| 6734 | if (start + 1 > finish) |
| 6735 | { |
| 6736 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), |
| 6737 | offset); |
| 6738 | break; |
| 6739 | } |
| 6740 | |
| 6741 | printf (" %8.8lx ", off); |
| 6742 | |
| 6743 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); |
| 6744 | |
| 6745 | switch (rlet) |
| 6746 | { |
| 6747 | case DW_RLE_end_of_list: |
| 6748 | printf (_("<End of list>\n")); |
| 6749 | break; |
| 6750 | case DW_RLE_base_address: |
| 6751 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); |
| 6752 | print_dwarf_vma (base_address, pointer_size); |
| 6753 | printf (_("(base address)\n")); |
| 6754 | break; |
| 6755 | case DW_RLE_start_length: |
| 6756 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
| 6757 | length = read_uleb128 (start, &bytes_read, finish); |
| 6758 | start += bytes_read; |
| 6759 | end = begin + length; |
| 6760 | break; |
| 6761 | case DW_RLE_offset_pair: |
| 6762 | begin = read_uleb128 (start, &bytes_read, finish); |
| 6763 | start += bytes_read; |
| 6764 | end = read_uleb128 (start, &bytes_read, finish); |
| 6765 | start += bytes_read; |
| 6766 | break; |
| 6767 | case DW_RLE_start_end: |
| 6768 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
| 6769 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
| 6770 | break; |
| 6771 | default: |
| 6772 | error (_("Invalid range list entry type %d\n"), rlet); |
| 6773 | rlet = DW_RLE_end_of_list; |
| 6774 | break; |
| 6775 | } |
| 6776 | if (rlet == DW_RLE_end_of_list) |
| 6777 | break; |
| 6778 | if (rlet == DW_RLE_base_address) |
| 6779 | continue; |
| 6780 | |
| 6781 | print_dwarf_vma (begin + base_address, pointer_size); |
| 6782 | print_dwarf_vma (end + base_address, pointer_size); |
| 6783 | |
| 6784 | if (begin == end) |
| 6785 | fputs (_("(start == end)"), stdout); |
| 6786 | else if (begin > end) |
| 6787 | fputs (_("(start > end)"), stdout); |
| 6788 | |
| 6789 | putchar ('\n'); |
| 6790 | } |
| 6791 | } |
| 6792 | |
| 6793 | static int |
| 6794 | display_debug_ranges (struct dwarf_section *section, |
| 6795 | void *file ATTRIBUTE_UNUSED) |
| 6796 | { |
| 6797 | unsigned char *start = section->start; |
| 6798 | unsigned char *last_start = start; |
| 6799 | unsigned long bytes = section->size; |
| 6800 | unsigned char *section_begin = start; |
| 6801 | unsigned char *finish = start + bytes; |
| 6802 | unsigned int num_range_list, i; |
| 6803 | struct range_entry *range_entries, *range_entry_fill; |
| 6804 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
| 6805 | /* Initialize it due to a false compiler warning. */ |
| 6806 | unsigned char address_size = 0; |
| 6807 | |
| 6808 | if (bytes == 0) |
| 6809 | { |
| 6810 | printf (_("\nThe %s section is empty.\n"), section->name); |
| 6811 | return 0; |
| 6812 | } |
| 6813 | |
| 6814 | if (is_rnglists) |
| 6815 | { |
| 6816 | dwarf_vma initial_length; |
| 6817 | unsigned int initial_length_size; |
| 6818 | unsigned char segment_selector_size; |
| 6819 | unsigned int offset_size, offset_entry_count; |
| 6820 | unsigned short version; |
| 6821 | |
| 6822 | /* Get and check the length of the block. */ |
| 6823 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); |
| 6824 | |
| 6825 | if (initial_length == 0xffffffff) |
| 6826 | { |
| 6827 | /* This section is 64-bit DWARF 3. */ |
| 6828 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); |
| 6829 | offset_size = 8; |
| 6830 | initial_length_size = 12; |
| 6831 | } |
| 6832 | else |
| 6833 | { |
| 6834 | offset_size = 4; |
| 6835 | initial_length_size = 4; |
| 6836 | } |
| 6837 | |
| 6838 | if (initial_length + initial_length_size > section->size) |
| 6839 | { |
| 6840 | /* If the length field has a relocation against it, then we should |
| 6841 | not complain if it is inaccurate (and probably negative). |
| 6842 | It is copied from .debug_line handling code. */ |
| 6843 | if (reloc_at (section, (start - section->start) - offset_size)) |
| 6844 | { |
| 6845 | initial_length = (finish - start) - initial_length_size; |
| 6846 | } |
| 6847 | else |
| 6848 | { |
| 6849 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), |
| 6850 | (long) initial_length); |
| 6851 | return 0; |
| 6852 | } |
| 6853 | } |
| 6854 | |
| 6855 | /* Get and check the version number. */ |
| 6856 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); |
| 6857 | |
| 6858 | if (version != 5) |
| 6859 | { |
| 6860 | warn (_("Only DWARF version 5 debug_rnglists info " |
| 6861 | "is currently supported.\n")); |
| 6862 | return 0; |
| 6863 | } |
| 6864 | |
| 6865 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); |
| 6866 | |
| 6867 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); |
| 6868 | if (segment_selector_size != 0) |
| 6869 | { |
| 6870 | warn (_("The %s section contains " |
| 6871 | "unsupported segment selector size: %d.\n"), |
| 6872 | section->name, segment_selector_size); |
| 6873 | return 0; |
| 6874 | } |
| 6875 | |
| 6876 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); |
| 6877 | if (offset_entry_count != 0) |
| 6878 | { |
| 6879 | warn (_("The %s section contains " |
| 6880 | "unsupported offset entry count: %u.\n"), |
| 6881 | section->name, offset_entry_count); |
| 6882 | return 0; |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | if (load_debug_info (file) == 0) |
| 6887 | { |
| 6888 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
| 6889 | section->name); |
| 6890 | return 0; |
| 6891 | } |
| 6892 | |
| 6893 | num_range_list = 0; |
| 6894 | for (i = 0; i < num_debug_info_entries; i++) |
| 6895 | num_range_list += debug_information [i].num_range_lists; |
| 6896 | |
| 6897 | if (num_range_list == 0) |
| 6898 | { |
| 6899 | /* This can happen when the file was compiled with -gsplit-debug |
| 6900 | which removes references to range lists from the primary .o file. */ |
| 6901 | printf (_("No range lists in .debug_info section.\n")); |
| 6902 | return 1; |
| 6903 | } |
| 6904 | |
| 6905 | range_entries = (struct range_entry *) |
| 6906 | xmalloc (sizeof (*range_entries) * num_range_list); |
| 6907 | range_entry_fill = range_entries; |
| 6908 | |
| 6909 | for (i = 0; i < num_debug_info_entries; i++) |
| 6910 | { |
| 6911 | debug_info *debug_info_p = &debug_information[i]; |
| 6912 | unsigned int j; |
| 6913 | |
| 6914 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
| 6915 | { |
| 6916 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; |
| 6917 | range_entry_fill->debug_info_p = debug_info_p; |
| 6918 | range_entry_fill++; |
| 6919 | } |
| 6920 | } |
| 6921 | |
| 6922 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
| 6923 | range_entry_compar); |
| 6924 | |
| 6925 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
| 6926 | warn (_("Range lists in %s section start at 0x%lx\n"), |
| 6927 | section->name, (unsigned long) range_entries[0].ranges_offset); |
| 6928 | |
| 6929 | introduce (section, FALSE); |
| 6930 | |
| 6931 | printf (_(" Offset Begin End\n")); |
| 6932 | |
| 6933 | for (i = 0; i < num_range_list; i++) |
| 6934 | { |
| 6935 | struct range_entry *range_entry = &range_entries[i]; |
| 6936 | debug_info *debug_info_p = range_entry->debug_info_p; |
| 6937 | unsigned int pointer_size; |
| 6938 | dwarf_vma offset; |
| 6939 | unsigned char *next; |
| 6940 | dwarf_vma base_address; |
| 6941 | |
| 6942 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
| 6943 | offset = range_entry->ranges_offset; |
| 6944 | next = section_begin + offset; |
| 6945 | base_address = debug_info_p->base_address; |
| 6946 | |
| 6947 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
| 6948 | if (pointer_size < 2 || pointer_size > 8) |
| 6949 | { |
| 6950 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), |
| 6951 | pointer_size, (unsigned long) offset); |
| 6952 | continue; |
| 6953 | } |
| 6954 | |
| 6955 | if (next < section_begin || next >= finish) |
| 6956 | { |
| 6957 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), |
| 6958 | (unsigned long) offset, i); |
| 6959 | continue; |
| 6960 | } |
| 6961 | |
| 6962 | if (dwarf_check != 0 && i > 0) |
| 6963 | { |
| 6964 | if (start < next) |
| 6965 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), |
| 6966 | (unsigned long) (start - section_begin), |
| 6967 | (unsigned long) (next - section_begin), section->name); |
| 6968 | else if (start > next) |
| 6969 | { |
| 6970 | if (next == last_start) |
| 6971 | continue; |
| 6972 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), |
| 6973 | (unsigned long) (start - section_begin), |
| 6974 | (unsigned long) (next - section_begin), section->name); |
| 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | start = next; |
| 6979 | last_start = next; |
| 6980 | |
| 6981 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
| 6982 | (start, finish, pointer_size, offset, base_address); |
| 6983 | } |
| 6984 | putchar ('\n'); |
| 6985 | |
| 6986 | free (range_entries); |
| 6987 | |
| 6988 | return 1; |
| 6989 | } |
| 6990 | |
| 6991 | typedef struct Frame_Chunk |
| 6992 | { |
| 6993 | struct Frame_Chunk *next; |
| 6994 | unsigned char *chunk_start; |
| 6995 | unsigned int ncols; |
| 6996 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
| 6997 | short int *col_type; |
| 6998 | int *col_offset; |
| 6999 | char *augmentation; |
| 7000 | unsigned int code_factor; |
| 7001 | int data_factor; |
| 7002 | dwarf_vma pc_begin; |
| 7003 | dwarf_vma pc_range; |
| 7004 | unsigned int cfa_reg; |
| 7005 | dwarf_vma cfa_offset; |
| 7006 | unsigned int ra; |
| 7007 | unsigned char fde_encoding; |
| 7008 | unsigned char cfa_exp; |
| 7009 | unsigned char ptr_size; |
| 7010 | unsigned char segment_size; |
| 7011 | } |
| 7012 | Frame_Chunk; |
| 7013 | |
| 7014 | static const char *const *dwarf_regnames; |
| 7015 | static unsigned int dwarf_regnames_count; |
| 7016 | |
| 7017 | /* A marker for a col_type that means this column was never referenced |
| 7018 | in the frame info. */ |
| 7019 | #define DW_CFA_unreferenced (-1) |
| 7020 | |
| 7021 | /* Return 0 if no more space is needed, 1 if more space is needed, |
| 7022 | -1 for invalid reg. */ |
| 7023 | |
| 7024 | static int |
| 7025 | frame_need_space (Frame_Chunk *fc, unsigned int reg) |
| 7026 | { |
| 7027 | unsigned int prev = fc->ncols; |
| 7028 | |
| 7029 | if (reg < (unsigned int) fc->ncols) |
| 7030 | return 0; |
| 7031 | |
| 7032 | if (dwarf_regnames_count |
| 7033 | && reg > dwarf_regnames_count) |
| 7034 | return -1; |
| 7035 | |
| 7036 | fc->ncols = reg + 1; |
| 7037 | /* PR 17512: file: 10450-2643-0.004. |
| 7038 | If reg == -1 then this can happen... */ |
| 7039 | if (fc->ncols == 0) |
| 7040 | return -1; |
| 7041 | |
| 7042 | /* PR 17512: file: 2844a11d. */ |
| 7043 | if (fc->ncols > 1024) |
| 7044 | { |
| 7045 | error (_("Unfeasibly large register number: %u\n"), reg); |
| 7046 | fc->ncols = 0; |
| 7047 | /* FIXME: 1024 is an arbitrary limit. Increase it if |
| 7048 | we ever encounter a valid binary that exceeds it. */ |
| 7049 | return -1; |
| 7050 | } |
| 7051 | |
| 7052 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
| 7053 | sizeof (short int)); |
| 7054 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
| 7055 | /* PR 17512: file:002-10025-0.005. */ |
| 7056 | if (fc->col_type == NULL || fc->col_offset == NULL) |
| 7057 | { |
| 7058 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), |
| 7059 | fc->ncols); |
| 7060 | fc->ncols = 0; |
| 7061 | return -1; |
| 7062 | } |
| 7063 | |
| 7064 | while (prev < fc->ncols) |
| 7065 | { |
| 7066 | fc->col_type[prev] = DW_CFA_unreferenced; |
| 7067 | fc->col_offset[prev] = 0; |
| 7068 | prev++; |
| 7069 | } |
| 7070 | return 1; |
| 7071 | } |
| 7072 | |
| 7073 | static const char *const dwarf_regnames_i386[] = |
| 7074 | { |
| 7075 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
| 7076 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
| 7077 | "eip", "eflags", NULL, /* 8 - 10 */ |
| 7078 | "st0", "st1", "st2", "st3", /* 11 - 14 */ |
| 7079 | "st4", "st5", "st6", "st7", /* 15 - 18 */ |
| 7080 | NULL, NULL, /* 19 - 20 */ |
| 7081 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ |
| 7082 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ |
| 7083 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ |
| 7084 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ |
| 7085 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ |
| 7086 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
| 7087 | "tr", "ldtr", /* 48 - 49 */ |
| 7088 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
| 7089 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
| 7090 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
| 7091 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
| 7092 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
| 7093 | NULL, NULL, NULL, /* 90 - 92 */ |
| 7094 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ |
| 7095 | }; |
| 7096 | |
| 7097 | static const char *const dwarf_regnames_iamcu[] = |
| 7098 | { |
| 7099 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
| 7100 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
| 7101 | "eip", "eflags", NULL, /* 8 - 10 */ |
| 7102 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ |
| 7103 | NULL, NULL, /* 19 - 20 */ |
| 7104 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ |
| 7105 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ |
| 7106 | NULL, NULL, NULL, /* 37 - 39 */ |
| 7107 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
| 7108 | "tr", "ldtr", /* 48 - 49 */ |
| 7109 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
| 7110 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
| 7111 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
| 7112 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
| 7113 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
| 7114 | NULL, NULL, NULL, /* 90 - 92 */ |
| 7115 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ |
| 7116 | }; |
| 7117 | |
| 7118 | void |
| 7119 | init_dwarf_regnames_i386 (void) |
| 7120 | { |
| 7121 | dwarf_regnames = dwarf_regnames_i386; |
| 7122 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); |
| 7123 | } |
| 7124 | |
| 7125 | void |
| 7126 | init_dwarf_regnames_iamcu (void) |
| 7127 | { |
| 7128 | dwarf_regnames = dwarf_regnames_iamcu; |
| 7129 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); |
| 7130 | } |
| 7131 | |
| 7132 | static const char *const dwarf_regnames_x86_64[] = |
| 7133 | { |
| 7134 | "rax", "rdx", "rcx", "rbx", |
| 7135 | "rsi", "rdi", "rbp", "rsp", |
| 7136 | "r8", "r9", "r10", "r11", |
| 7137 | "r12", "r13", "r14", "r15", |
| 7138 | "rip", |
| 7139 | "xmm0", "xmm1", "xmm2", "xmm3", |
| 7140 | "xmm4", "xmm5", "xmm6", "xmm7", |
| 7141 | "xmm8", "xmm9", "xmm10", "xmm11", |
| 7142 | "xmm12", "xmm13", "xmm14", "xmm15", |
| 7143 | "st0", "st1", "st2", "st3", |
| 7144 | "st4", "st5", "st6", "st7", |
| 7145 | "mm0", "mm1", "mm2", "mm3", |
| 7146 | "mm4", "mm5", "mm6", "mm7", |
| 7147 | "rflags", |
| 7148 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, |
| 7149 | "fs.base", "gs.base", NULL, NULL, |
| 7150 | "tr", "ldtr", |
| 7151 | "mxcsr", "fcw", "fsw", |
| 7152 | "xmm16", "xmm17", "xmm18", "xmm19", |
| 7153 | "xmm20", "xmm21", "xmm22", "xmm23", |
| 7154 | "xmm24", "xmm25", "xmm26", "xmm27", |
| 7155 | "xmm28", "xmm29", "xmm30", "xmm31", |
| 7156 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ |
| 7157 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ |
| 7158 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ |
| 7159 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ |
| 7160 | NULL, NULL, NULL, /* 115 - 117 */ |
| 7161 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" |
| 7162 | }; |
| 7163 | |
| 7164 | void |
| 7165 | init_dwarf_regnames_x86_64 (void) |
| 7166 | { |
| 7167 | dwarf_regnames = dwarf_regnames_x86_64; |
| 7168 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); |
| 7169 | } |
| 7170 | |
| 7171 | static const char *const dwarf_regnames_aarch64[] = |
| 7172 | { |
| 7173 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
| 7174 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", |
| 7175 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
| 7176 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", |
| 7177 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, |
| 7178 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
| 7179 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", |
| 7180 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", |
| 7181 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
| 7182 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", |
| 7183 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
| 7184 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", |
| 7185 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
| 7186 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
| 7187 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", |
| 7188 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", |
| 7189 | }; |
| 7190 | |
| 7191 | void |
| 7192 | init_dwarf_regnames_aarch64 (void) |
| 7193 | { |
| 7194 | dwarf_regnames = dwarf_regnames_aarch64; |
| 7195 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); |
| 7196 | } |
| 7197 | |
| 7198 | static const char *const dwarf_regnames_s390[] = |
| 7199 | { |
| 7200 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ |
| 7201 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 7202 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 7203 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", |
| 7204 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", |
| 7205 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", |
| 7206 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", |
| 7207 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", |
| 7208 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", |
| 7209 | "pswm", "pswa", |
| 7210 | NULL, NULL, |
| 7211 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", |
| 7212 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", |
| 7213 | }; |
| 7214 | |
| 7215 | void |
| 7216 | init_dwarf_regnames_s390 (void) |
| 7217 | { |
| 7218 | dwarf_regnames = dwarf_regnames_s390; |
| 7219 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); |
| 7220 | } |
| 7221 | |
| 7222 | static const char *const dwarf_regnames_riscv[] = |
| 7223 | { |
| 7224 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ |
| 7225 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ |
| 7226 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ |
| 7227 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ |
| 7228 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ |
| 7229 | "fs0", "fs1", /* 40 - 41 */ |
| 7230 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ |
| 7231 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ |
| 7232 | "fs10", "fs11", /* 58 - 59 */ |
| 7233 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ |
| 7234 | }; |
| 7235 | |
| 7236 | void |
| 7237 | init_dwarf_regnames_riscv (void) |
| 7238 | { |
| 7239 | dwarf_regnames = dwarf_regnames_riscv; |
| 7240 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); |
| 7241 | } |
| 7242 | |
| 7243 | void |
| 7244 | init_dwarf_regnames (unsigned int e_machine) |
| 7245 | { |
| 7246 | switch (e_machine) |
| 7247 | { |
| 7248 | case EM_386: |
| 7249 | init_dwarf_regnames_i386 (); |
| 7250 | break; |
| 7251 | |
| 7252 | case EM_IAMCU: |
| 7253 | init_dwarf_regnames_iamcu (); |
| 7254 | break; |
| 7255 | |
| 7256 | case EM_X86_64: |
| 7257 | case EM_L1OM: |
| 7258 | case EM_K1OM: |
| 7259 | init_dwarf_regnames_x86_64 (); |
| 7260 | break; |
| 7261 | |
| 7262 | case EM_AARCH64: |
| 7263 | init_dwarf_regnames_aarch64 (); |
| 7264 | break; |
| 7265 | |
| 7266 | case EM_S390: |
| 7267 | init_dwarf_regnames_s390 (); |
| 7268 | break; |
| 7269 | |
| 7270 | case EM_RISCV: |
| 7271 | init_dwarf_regnames_riscv (); |
| 7272 | break; |
| 7273 | |
| 7274 | default: |
| 7275 | break; |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | static const char * |
| 7280 | regname (unsigned int regno, int row) |
| 7281 | { |
| 7282 | static char reg[64]; |
| 7283 | |
| 7284 | if (dwarf_regnames |
| 7285 | && regno < dwarf_regnames_count |
| 7286 | && dwarf_regnames [regno] != NULL) |
| 7287 | { |
| 7288 | if (row) |
| 7289 | return dwarf_regnames [regno]; |
| 7290 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, |
| 7291 | dwarf_regnames [regno]); |
| 7292 | } |
| 7293 | else |
| 7294 | snprintf (reg, sizeof (reg), "r%d", regno); |
| 7295 | return reg; |
| 7296 | } |
| 7297 | |
| 7298 | static void |
| 7299 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
| 7300 | { |
| 7301 | unsigned int r; |
| 7302 | char tmp[100]; |
| 7303 | |
| 7304 | if (*max_regs != fc->ncols) |
| 7305 | *max_regs = fc->ncols; |
| 7306 | |
| 7307 | if (*need_col_headers) |
| 7308 | { |
| 7309 | static const char *sloc = " LOC"; |
| 7310 | |
| 7311 | *need_col_headers = 0; |
| 7312 | |
| 7313 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
| 7314 | |
| 7315 | for (r = 0; r < *max_regs; r++) |
| 7316 | if (fc->col_type[r] != DW_CFA_unreferenced) |
| 7317 | { |
| 7318 | if (r == fc->ra) |
| 7319 | printf ("ra "); |
| 7320 | else |
| 7321 | printf ("%-5s ", regname (r, 1)); |
| 7322 | } |
| 7323 | |
| 7324 | printf ("\n"); |
| 7325 | } |
| 7326 | |
| 7327 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
| 7328 | if (fc->cfa_exp) |
| 7329 | strcpy (tmp, "exp"); |
| 7330 | else |
| 7331 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
| 7332 | printf ("%-8s ", tmp); |
| 7333 | |
| 7334 | for (r = 0; r < fc->ncols; r++) |
| 7335 | { |
| 7336 | if (fc->col_type[r] != DW_CFA_unreferenced) |
| 7337 | { |
| 7338 | switch (fc->col_type[r]) |
| 7339 | { |
| 7340 | case DW_CFA_undefined: |
| 7341 | strcpy (tmp, "u"); |
| 7342 | break; |
| 7343 | case DW_CFA_same_value: |
| 7344 | strcpy (tmp, "s"); |
| 7345 | break; |
| 7346 | case DW_CFA_offset: |
| 7347 | sprintf (tmp, "c%+d", fc->col_offset[r]); |
| 7348 | break; |
| 7349 | case DW_CFA_val_offset: |
| 7350 | sprintf (tmp, "v%+d", fc->col_offset[r]); |
| 7351 | break; |
| 7352 | case DW_CFA_register: |
| 7353 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
| 7354 | break; |
| 7355 | case DW_CFA_expression: |
| 7356 | strcpy (tmp, "exp"); |
| 7357 | break; |
| 7358 | case DW_CFA_val_expression: |
| 7359 | strcpy (tmp, "vexp"); |
| 7360 | break; |
| 7361 | default: |
| 7362 | strcpy (tmp, "n/a"); |
| 7363 | break; |
| 7364 | } |
| 7365 | printf ("%-5s ", tmp); |
| 7366 | } |
| 7367 | } |
| 7368 | printf ("\n"); |
| 7369 | } |
| 7370 | |
| 7371 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
| 7372 | |
| 7373 | static unsigned char * |
| 7374 | read_cie (unsigned char *start, unsigned char *end, |
| 7375 | Frame_Chunk **p_cie, int *p_version, |
| 7376 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
| 7377 | { |
| 7378 | int version; |
| 7379 | Frame_Chunk *fc; |
| 7380 | unsigned int length_return; |
| 7381 | unsigned char *augmentation_data = NULL; |
| 7382 | bfd_size_type augmentation_data_len = 0; |
| 7383 | |
| 7384 | * p_cie = NULL; |
| 7385 | /* PR 17512: file: 001-228113-0.004. */ |
| 7386 | if (start >= end) |
| 7387 | return end; |
| 7388 | |
| 7389 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
| 7390 | memset (fc, 0, sizeof (Frame_Chunk)); |
| 7391 | |
| 7392 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
| 7393 | fc->col_offset = (int *) xmalloc (sizeof (int)); |
| 7394 | |
| 7395 | version = *start++; |
| 7396 | |
| 7397 | fc->augmentation = (char *) start; |
| 7398 | /* PR 17512: file: 001-228113-0.004. |
| 7399 | Skip past augmentation name, but avoid running off the end of the data. */ |
| 7400 | while (start < end) |
| 7401 | if (* start ++ == '\0') |
| 7402 | break; |
| 7403 | if (start == end) |
| 7404 | { |
| 7405 | warn (_("No terminator for augmentation name\n")); |
| 7406 | goto fail; |
| 7407 | } |
| 7408 | |
| 7409 | if (strcmp (fc->augmentation, "eh") == 0) |
| 7410 | start += eh_addr_size; |
| 7411 | |
| 7412 | if (version >= 4) |
| 7413 | { |
| 7414 | GET (fc->ptr_size, 1); |
| 7415 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
| 7416 | { |
| 7417 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); |
| 7418 | goto fail; |
| 7419 | } |
| 7420 | |
| 7421 | GET (fc->segment_size, 1); |
| 7422 | /* PR 17512: file: e99d2804. */ |
| 7423 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) |
| 7424 | { |
| 7425 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); |
| 7426 | goto fail; |
| 7427 | } |
| 7428 | |
| 7429 | eh_addr_size = fc->ptr_size; |
| 7430 | } |
| 7431 | else |
| 7432 | { |
| 7433 | fc->ptr_size = eh_addr_size; |
| 7434 | fc->segment_size = 0; |
| 7435 | } |
| 7436 | |
| 7437 | READ_ULEB (fc->code_factor); |
| 7438 | READ_SLEB (fc->data_factor); |
| 7439 | |
| 7440 | if (version == 1) |
| 7441 | { |
| 7442 | GET (fc->ra, 1); |
| 7443 | } |
| 7444 | else |
| 7445 | { |
| 7446 | READ_ULEB (fc->ra); |
| 7447 | } |
| 7448 | |
| 7449 | if (fc->augmentation[0] == 'z') |
| 7450 | { |
| 7451 | READ_ULEB (augmentation_data_len); |
| 7452 | augmentation_data = start; |
| 7453 | /* PR 17512: file: 11042-2589-0.004. */ |
| 7454 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
| 7455 | { |
| 7456 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
| 7457 | dwarf_vmatoa ("x", augmentation_data_len), |
| 7458 | (unsigned long) (end - start)); |
| 7459 | goto fail; |
| 7460 | } |
| 7461 | start += augmentation_data_len; |
| 7462 | } |
| 7463 | |
| 7464 | if (augmentation_data_len) |
| 7465 | { |
| 7466 | unsigned char *p; |
| 7467 | unsigned char *q; |
| 7468 | unsigned char *qend; |
| 7469 | |
| 7470 | p = (unsigned char *) fc->augmentation + 1; |
| 7471 | q = augmentation_data; |
| 7472 | qend = q + augmentation_data_len; |
| 7473 | |
| 7474 | while (p < end && q < qend) |
| 7475 | { |
| 7476 | if (*p == 'L') |
| 7477 | q++; |
| 7478 | else if (*p == 'P') |
| 7479 | q += 1 + size_of_encoded_value (*q); |
| 7480 | else if (*p == 'R') |
| 7481 | fc->fde_encoding = *q++; |
| 7482 | else if (*p == 'S') |
| 7483 | ; |
| 7484 | else if (*p == 'B') |
| 7485 | ; |
| 7486 | else |
| 7487 | break; |
| 7488 | p++; |
| 7489 | } |
| 7490 | /* Note - it is OK if this loop terminates with q < qend. |
| 7491 | Padding may have been inserted to align the end of the CIE. */ |
| 7492 | } |
| 7493 | |
| 7494 | *p_cie = fc; |
| 7495 | if (p_version) |
| 7496 | *p_version = version; |
| 7497 | if (p_aug_len) |
| 7498 | { |
| 7499 | *p_aug_len = augmentation_data_len; |
| 7500 | *p_aug = augmentation_data; |
| 7501 | } |
| 7502 | return start; |
| 7503 | |
| 7504 | fail: |
| 7505 | free (fc->col_offset); |
| 7506 | free (fc->col_type); |
| 7507 | free (fc); |
| 7508 | return end; |
| 7509 | } |
| 7510 | |
| 7511 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
| 7512 | If do_wide is not enabled, then formats the output to fit into 80 columns. |
| 7513 | PRINTED contains the number of characters already written to the current |
| 7514 | output line. */ |
| 7515 | |
| 7516 | static void |
| 7517 | display_data (bfd_size_type printed, |
| 7518 | const unsigned char * data, |
| 7519 | const bfd_size_type len) |
| 7520 | { |
| 7521 | if (do_wide || len < ((80 - printed) / 3)) |
| 7522 | for (printed = 0; printed < len; ++printed) |
| 7523 | printf (" %02x", data[printed]); |
| 7524 | else |
| 7525 | { |
| 7526 | for (printed = 0; printed < len; ++printed) |
| 7527 | { |
| 7528 | if (printed % (80 / 3) == 0) |
| 7529 | putchar ('\n'); |
| 7530 | printf (" %02x", data[printed]); |
| 7531 | } |
| 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | /* Prints out the contents on the augmentation data array. |
| 7536 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ |
| 7537 | |
| 7538 | static void |
| 7539 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) |
| 7540 | { |
| 7541 | bfd_size_type i; |
| 7542 | |
| 7543 | i = printf (_(" Augmentation data: ")); |
| 7544 | display_data (i, data, len); |
| 7545 | } |
| 7546 | |
| 7547 | static int |
| 7548 | display_debug_frames (struct dwarf_section *section, |
| 7549 | void *file ATTRIBUTE_UNUSED) |
| 7550 | { |
| 7551 | unsigned char *start = section->start; |
| 7552 | unsigned char *end = start + section->size; |
| 7553 | unsigned char *section_start = start; |
| 7554 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
| 7555 | Frame_Chunk *remembered_state = NULL; |
| 7556 | Frame_Chunk *rs; |
| 7557 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
| 7558 | unsigned int length_return; |
| 7559 | unsigned int max_regs = 0; |
| 7560 | const char *bad_reg = _("bad register: "); |
| 7561 | unsigned int saved_eh_addr_size = eh_addr_size; |
| 7562 | |
| 7563 | introduce (section, FALSE); |
| 7564 | |
| 7565 | while (start < end) |
| 7566 | { |
| 7567 | unsigned char *saved_start; |
| 7568 | unsigned char *block_end; |
| 7569 | dwarf_vma length; |
| 7570 | dwarf_vma cie_id; |
| 7571 | Frame_Chunk *fc; |
| 7572 | Frame_Chunk *cie; |
| 7573 | int need_col_headers = 1; |
| 7574 | unsigned char *augmentation_data = NULL; |
| 7575 | bfd_size_type augmentation_data_len = 0; |
| 7576 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
| 7577 | unsigned int offset_size; |
| 7578 | unsigned int initial_length_size; |
| 7579 | bfd_boolean all_nops; |
| 7580 | |
| 7581 | saved_start = start; |
| 7582 | |
| 7583 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
| 7584 | |
| 7585 | if (length == 0) |
| 7586 | { |
| 7587 | printf ("\n%08lx ZERO terminator\n\n", |
| 7588 | (unsigned long)(saved_start - section_start)); |
| 7589 | /* Skip any zero terminators that directly follow. |
| 7590 | A corrupt section size could have loaded a whole |
| 7591 | slew of zero filled memory bytes. eg |
| 7592 | PR 17512: file: 070-19381-0.004. */ |
| 7593 | while (start < end && * start == 0) |
| 7594 | ++ start; |
| 7595 | continue; |
| 7596 | } |
| 7597 | |
| 7598 | if (length == 0xffffffff) |
| 7599 | { |
| 7600 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
| 7601 | offset_size = 8; |
| 7602 | initial_length_size = 12; |
| 7603 | } |
| 7604 | else |
| 7605 | { |
| 7606 | offset_size = 4; |
| 7607 | initial_length_size = 4; |
| 7608 | } |
| 7609 | |
| 7610 | block_end = saved_start + length + initial_length_size; |
| 7611 | if (block_end > end || block_end < start) |
| 7612 | { |
| 7613 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
| 7614 | dwarf_vmatoa_1 (NULL, length, offset_size), |
| 7615 | (unsigned long) (saved_start - section_start)); |
| 7616 | block_end = end; |
| 7617 | } |
| 7618 | |
| 7619 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); |
| 7620 | |
| 7621 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
| 7622 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) |
| 7623 | { |
| 7624 | int version; |
| 7625 | unsigned int mreg; |
| 7626 | |
| 7627 | start = read_cie (start, end, &cie, &version, |
| 7628 | &augmentation_data_len, &augmentation_data); |
| 7629 | /* PR 17512: file: 027-135133-0.005. */ |
| 7630 | if (cie == NULL) |
| 7631 | break; |
| 7632 | |
| 7633 | fc = cie; |
| 7634 | fc->next = chunks; |
| 7635 | chunks = fc; |
| 7636 | fc->chunk_start = saved_start; |
| 7637 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
| 7638 | if (mreg < fc->ra) |
| 7639 | mreg = fc->ra; |
| 7640 | if (frame_need_space (fc, mreg) < 0) |
| 7641 | break; |
| 7642 | if (fc->fde_encoding) |
| 7643 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
| 7644 | |
| 7645 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
| 7646 | print_dwarf_vma (length, fc->ptr_size); |
| 7647 | print_dwarf_vma (cie_id, offset_size); |
| 7648 | |
| 7649 | if (do_debug_frames_interp) |
| 7650 | { |
| 7651 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, |
| 7652 | fc->code_factor, fc->data_factor, fc->ra); |
| 7653 | } |
| 7654 | else |
| 7655 | { |
| 7656 | printf ("CIE\n"); |
| 7657 | printf (" Version: %d\n", version); |
| 7658 | printf (" Augmentation: \"%s\"\n", fc->augmentation); |
| 7659 | if (version >= 4) |
| 7660 | { |
| 7661 | printf (" Pointer Size: %u\n", fc->ptr_size); |
| 7662 | printf (" Segment Size: %u\n", fc->segment_size); |
| 7663 | } |
| 7664 | printf (" Code alignment factor: %u\n", fc->code_factor); |
| 7665 | printf (" Data alignment factor: %d\n", fc->data_factor); |
| 7666 | printf (" Return address column: %d\n", fc->ra); |
| 7667 | |
| 7668 | if (augmentation_data_len) |
| 7669 | display_augmentation_data (augmentation_data, augmentation_data_len); |
| 7670 | |
| 7671 | putchar ('\n'); |
| 7672 | } |
| 7673 | } |
| 7674 | else |
| 7675 | { |
| 7676 | unsigned char *look_for; |
| 7677 | static Frame_Chunk fde_fc; |
| 7678 | unsigned long segment_selector; |
| 7679 | |
| 7680 | if (is_eh) |
| 7681 | { |
| 7682 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); |
| 7683 | look_for = start - 4 - ((cie_id ^ sign) - sign); |
| 7684 | } |
| 7685 | else |
| 7686 | look_for = section_start + cie_id; |
| 7687 | |
| 7688 | if (look_for <= saved_start) |
| 7689 | { |
| 7690 | for (cie = chunks; cie ; cie = cie->next) |
| 7691 | if (cie->chunk_start == look_for) |
| 7692 | break; |
| 7693 | } |
| 7694 | else |
| 7695 | { |
| 7696 | for (cie = forward_refs; cie ; cie = cie->next) |
| 7697 | if (cie->chunk_start == look_for) |
| 7698 | break; |
| 7699 | if (!cie) |
| 7700 | { |
| 7701 | unsigned int off_size; |
| 7702 | unsigned char *cie_scan; |
| 7703 | |
| 7704 | cie_scan = look_for; |
| 7705 | off_size = 4; |
| 7706 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); |
| 7707 | if (length == 0xffffffff) |
| 7708 | { |
| 7709 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); |
| 7710 | off_size = 8; |
| 7711 | } |
| 7712 | if (length != 0) |
| 7713 | { |
| 7714 | dwarf_vma c_id; |
| 7715 | |
| 7716 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); |
| 7717 | if (is_eh |
| 7718 | ? c_id == 0 |
| 7719 | : ((off_size == 4 && c_id == DW_CIE_ID) |
| 7720 | || (off_size == 8 && c_id == DW64_CIE_ID))) |
| 7721 | { |
| 7722 | int version; |
| 7723 | unsigned int mreg; |
| 7724 | |
| 7725 | read_cie (cie_scan, end, &cie, &version, |
| 7726 | &augmentation_data_len, &augmentation_data); |
| 7727 | /* PR 17512: file: 3450-2098-0.004. */ |
| 7728 | if (cie == NULL) |
| 7729 | { |
| 7730 | warn (_("Failed to read CIE information\n")); |
| 7731 | break; |
| 7732 | } |
| 7733 | cie->next = forward_refs; |
| 7734 | forward_refs = cie; |
| 7735 | cie->chunk_start = look_for; |
| 7736 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
| 7737 | if (mreg < cie->ra) |
| 7738 | mreg = cie->ra; |
| 7739 | if (frame_need_space (cie, mreg) < 0) |
| 7740 | { |
| 7741 | warn (_("Invalid max register\n")); |
| 7742 | break; |
| 7743 | } |
| 7744 | if (cie->fde_encoding) |
| 7745 | encoded_ptr_size |
| 7746 | = size_of_encoded_value (cie->fde_encoding); |
| 7747 | } |
| 7748 | } |
| 7749 | } |
| 7750 | } |
| 7751 | |
| 7752 | fc = &fde_fc; |
| 7753 | memset (fc, 0, sizeof (Frame_Chunk)); |
| 7754 | |
| 7755 | if (!cie) |
| 7756 | { |
| 7757 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
| 7758 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
| 7759 | (unsigned long) (saved_start - section_start)); |
| 7760 | fc->ncols = 0; |
| 7761 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
| 7762 | fc->col_offset = (int *) xmalloc (sizeof (int)); |
| 7763 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
| 7764 | { |
| 7765 | warn (_("Invalid max register\n")); |
| 7766 | break; |
| 7767 | } |
| 7768 | cie = fc; |
| 7769 | fc->augmentation = ""; |
| 7770 | fc->fde_encoding = 0; |
| 7771 | fc->ptr_size = eh_addr_size; |
| 7772 | fc->segment_size = 0; |
| 7773 | } |
| 7774 | else |
| 7775 | { |
| 7776 | fc->ncols = cie->ncols; |
| 7777 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
| 7778 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); |
| 7779 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
| 7780 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); |
| 7781 | fc->augmentation = cie->augmentation; |
| 7782 | fc->ptr_size = cie->ptr_size; |
| 7783 | eh_addr_size = cie->ptr_size; |
| 7784 | fc->segment_size = cie->segment_size; |
| 7785 | fc->code_factor = cie->code_factor; |
| 7786 | fc->data_factor = cie->data_factor; |
| 7787 | fc->cfa_reg = cie->cfa_reg; |
| 7788 | fc->cfa_offset = cie->cfa_offset; |
| 7789 | fc->ra = cie->ra; |
| 7790 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
| 7791 | { |
| 7792 | warn (_("Invalid max register\n")); |
| 7793 | break; |
| 7794 | } |
| 7795 | fc->fde_encoding = cie->fde_encoding; |
| 7796 | } |
| 7797 | |
| 7798 | if (fc->fde_encoding) |
| 7799 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
| 7800 | |
| 7801 | segment_selector = 0; |
| 7802 | if (fc->segment_size) |
| 7803 | { |
| 7804 | if (fc->segment_size > sizeof (segment_selector)) |
| 7805 | { |
| 7806 | /* PR 17512: file: 9e196b3e. */ |
| 7807 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); |
| 7808 | fc->segment_size = 4; |
| 7809 | } |
| 7810 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); |
| 7811 | } |
| 7812 | |
| 7813 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); |
| 7814 | |
| 7815 | /* FIXME: It appears that sometimes the final pc_range value is |
| 7816 | encoded in less than encoded_ptr_size bytes. See the x86_64 |
| 7817 | run of the "objcopy on compressed debug sections" test for an |
| 7818 | example of this. */ |
| 7819 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); |
| 7820 | |
| 7821 | if (cie->augmentation[0] == 'z') |
| 7822 | { |
| 7823 | READ_ULEB (augmentation_data_len); |
| 7824 | augmentation_data = start; |
| 7825 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
| 7826 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
| 7827 | { |
| 7828 | warn (_("Augmentation data too long: 0x%s, " |
| 7829 | "expected at most %#lx\n"), |
| 7830 | dwarf_vmatoa ("x", augmentation_data_len), |
| 7831 | (unsigned long) (end - start)); |
| 7832 | start = end; |
| 7833 | augmentation_data = NULL; |
| 7834 | augmentation_data_len = 0; |
| 7835 | } |
| 7836 | start += augmentation_data_len; |
| 7837 | } |
| 7838 | |
| 7839 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
| 7840 | (unsigned long)(saved_start - section_start), |
| 7841 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), |
| 7842 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
| 7843 | (unsigned long)(cie->chunk_start - section_start)); |
| 7844 | |
| 7845 | if (fc->segment_size) |
| 7846 | printf ("%04lx:", segment_selector); |
| 7847 | |
| 7848 | printf ("%s..%s\n", |
| 7849 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), |
| 7850 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); |
| 7851 | |
| 7852 | if (! do_debug_frames_interp && augmentation_data_len) |
| 7853 | { |
| 7854 | display_augmentation_data (augmentation_data, augmentation_data_len); |
| 7855 | putchar ('\n'); |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | /* At this point, fc is the current chunk, cie (if any) is set, and |
| 7860 | we're about to interpret instructions for the chunk. */ |
| 7861 | /* ??? At present we need to do this always, since this sizes the |
| 7862 | fc->col_type and fc->col_offset arrays, which we write into always. |
| 7863 | We should probably split the interpreted and non-interpreted bits |
| 7864 | into two different routines, since there's so much that doesn't |
| 7865 | really overlap between them. */ |
| 7866 | if (1 || do_debug_frames_interp) |
| 7867 | { |
| 7868 | /* Start by making a pass over the chunk, allocating storage |
| 7869 | and taking note of what registers are used. */ |
| 7870 | unsigned char *tmp = start; |
| 7871 | |
| 7872 | while (start < block_end) |
| 7873 | { |
| 7874 | unsigned int reg, op, opa; |
| 7875 | unsigned long temp; |
| 7876 | unsigned char * new_start; |
| 7877 | |
| 7878 | op = *start++; |
| 7879 | opa = op & 0x3f; |
| 7880 | if (op & 0xc0) |
| 7881 | op &= 0xc0; |
| 7882 | |
| 7883 | /* Warning: if you add any more cases to this switch, be |
| 7884 | sure to add them to the corresponding switch below. */ |
| 7885 | switch (op) |
| 7886 | { |
| 7887 | case DW_CFA_advance_loc: |
| 7888 | break; |
| 7889 | case DW_CFA_offset: |
| 7890 | SKIP_ULEB (); |
| 7891 | if (frame_need_space (fc, opa) >= 0) |
| 7892 | fc->col_type[opa] = DW_CFA_undefined; |
| 7893 | break; |
| 7894 | case DW_CFA_restore: |
| 7895 | if (frame_need_space (fc, opa) >= 0) |
| 7896 | fc->col_type[opa] = DW_CFA_undefined; |
| 7897 | break; |
| 7898 | case DW_CFA_set_loc: |
| 7899 | start += encoded_ptr_size; |
| 7900 | break; |
| 7901 | case DW_CFA_advance_loc1: |
| 7902 | start += 1; |
| 7903 | break; |
| 7904 | case DW_CFA_advance_loc2: |
| 7905 | start += 2; |
| 7906 | break; |
| 7907 | case DW_CFA_advance_loc4: |
| 7908 | start += 4; |
| 7909 | break; |
| 7910 | case DW_CFA_offset_extended: |
| 7911 | case DW_CFA_val_offset: |
| 7912 | READ_ULEB (reg); |
| 7913 | SKIP_ULEB (); |
| 7914 | if (frame_need_space (fc, reg) >= 0) |
| 7915 | fc->col_type[reg] = DW_CFA_undefined; |
| 7916 | break; |
| 7917 | case DW_CFA_restore_extended: |
| 7918 | READ_ULEB (reg); |
| 7919 | if (frame_need_space (fc, reg) >= 0) |
| 7920 | fc->col_type[reg] = DW_CFA_undefined; |
| 7921 | break; |
| 7922 | case DW_CFA_undefined: |
| 7923 | READ_ULEB (reg); |
| 7924 | if (frame_need_space (fc, reg) >= 0) |
| 7925 | fc->col_type[reg] = DW_CFA_undefined; |
| 7926 | break; |
| 7927 | case DW_CFA_same_value: |
| 7928 | READ_ULEB (reg); |
| 7929 | if (frame_need_space (fc, reg) >= 0) |
| 7930 | fc->col_type[reg] = DW_CFA_undefined; |
| 7931 | break; |
| 7932 | case DW_CFA_register: |
| 7933 | READ_ULEB (reg); |
| 7934 | SKIP_ULEB (); |
| 7935 | if (frame_need_space (fc, reg) >= 0) |
| 7936 | fc->col_type[reg] = DW_CFA_undefined; |
| 7937 | break; |
| 7938 | case DW_CFA_def_cfa: |
| 7939 | SKIP_ULEB (); |
| 7940 | SKIP_ULEB (); |
| 7941 | break; |
| 7942 | case DW_CFA_def_cfa_register: |
| 7943 | SKIP_ULEB (); |
| 7944 | break; |
| 7945 | case DW_CFA_def_cfa_offset: |
| 7946 | SKIP_ULEB (); |
| 7947 | break; |
| 7948 | case DW_CFA_def_cfa_expression: |
| 7949 | READ_ULEB (temp); |
| 7950 | new_start = start + temp; |
| 7951 | if (new_start < start) |
| 7952 | { |
| 7953 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); |
| 7954 | start = block_end; |
| 7955 | } |
| 7956 | else |
| 7957 | start = new_start; |
| 7958 | break; |
| 7959 | case DW_CFA_expression: |
| 7960 | case DW_CFA_val_expression: |
| 7961 | READ_ULEB (reg); |
| 7962 | READ_ULEB (temp); |
| 7963 | new_start = start + temp; |
| 7964 | if (new_start < start) |
| 7965 | { |
| 7966 | /* PR 17512: file:306-192417-0.005. */ |
| 7967 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
| 7968 | start = block_end; |
| 7969 | } |
| 7970 | else |
| 7971 | start = new_start; |
| 7972 | if (frame_need_space (fc, reg) >= 0) |
| 7973 | fc->col_type[reg] = DW_CFA_undefined; |
| 7974 | break; |
| 7975 | case DW_CFA_offset_extended_sf: |
| 7976 | case DW_CFA_val_offset_sf: |
| 7977 | READ_ULEB (reg); |
| 7978 | SKIP_SLEB (); |
| 7979 | if (frame_need_space (fc, reg) >= 0) |
| 7980 | fc->col_type[reg] = DW_CFA_undefined; |
| 7981 | break; |
| 7982 | case DW_CFA_def_cfa_sf: |
| 7983 | SKIP_ULEB (); |
| 7984 | SKIP_SLEB (); |
| 7985 | break; |
| 7986 | case DW_CFA_def_cfa_offset_sf: |
| 7987 | SKIP_SLEB (); |
| 7988 | break; |
| 7989 | case DW_CFA_MIPS_advance_loc8: |
| 7990 | start += 8; |
| 7991 | break; |
| 7992 | case DW_CFA_GNU_args_size: |
| 7993 | SKIP_ULEB (); |
| 7994 | break; |
| 7995 | case DW_CFA_GNU_negative_offset_extended: |
| 7996 | READ_ULEB (reg); |
| 7997 | SKIP_ULEB (); |
| 7998 | if (frame_need_space (fc, reg) >= 0) |
| 7999 | fc->col_type[reg] = DW_CFA_undefined; |
| 8000 | break; |
| 8001 | default: |
| 8002 | break; |
| 8003 | } |
| 8004 | } |
| 8005 | start = tmp; |
| 8006 | } |
| 8007 | |
| 8008 | all_nops = TRUE; |
| 8009 | |
| 8010 | /* Now we know what registers are used, make a second pass over |
| 8011 | the chunk, this time actually printing out the info. */ |
| 8012 | |
| 8013 | while (start < block_end) |
| 8014 | { |
| 8015 | unsigned char * tmp; |
| 8016 | unsigned op, opa; |
| 8017 | unsigned long ul, roffs; |
| 8018 | /* Note: It is tempting to use an unsigned long for 'reg' but there |
| 8019 | are various functions, notably frame_space_needed() that assume that |
| 8020 | reg is an unsigned int. */ |
| 8021 | unsigned int reg; |
| 8022 | dwarf_signed_vma l; |
| 8023 | dwarf_vma ofs; |
| 8024 | dwarf_vma vma; |
| 8025 | const char *reg_prefix = ""; |
| 8026 | |
| 8027 | op = *start++; |
| 8028 | opa = op & 0x3f; |
| 8029 | if (op & 0xc0) |
| 8030 | op &= 0xc0; |
| 8031 | |
| 8032 | /* Make a note if something other than DW_CFA_nop happens. */ |
| 8033 | if (op != DW_CFA_nop) |
| 8034 | all_nops = FALSE; |
| 8035 | |
| 8036 | /* Warning: if you add any more cases to this switch, be |
| 8037 | sure to add them to the corresponding switch above. */ |
| 8038 | switch (op) |
| 8039 | { |
| 8040 | case DW_CFA_advance_loc: |
| 8041 | if (do_debug_frames_interp) |
| 8042 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8043 | else |
| 8044 | printf (" DW_CFA_advance_loc: %d to %s\n", |
| 8045 | opa * fc->code_factor, |
| 8046 | dwarf_vmatoa_1 (NULL, |
| 8047 | fc->pc_begin + opa * fc->code_factor, |
| 8048 | fc->ptr_size)); |
| 8049 | fc->pc_begin += opa * fc->code_factor; |
| 8050 | break; |
| 8051 | |
| 8052 | case DW_CFA_offset: |
| 8053 | READ_ULEB (roffs); |
| 8054 | if (opa >= (unsigned int) fc->ncols) |
| 8055 | reg_prefix = bad_reg; |
| 8056 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8057 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", |
| 8058 | reg_prefix, regname (opa, 0), |
| 8059 | roffs * fc->data_factor); |
| 8060 | if (*reg_prefix == '\0') |
| 8061 | { |
| 8062 | fc->col_type[opa] = DW_CFA_offset; |
| 8063 | fc->col_offset[opa] = roffs * fc->data_factor; |
| 8064 | } |
| 8065 | break; |
| 8066 | |
| 8067 | case DW_CFA_restore: |
| 8068 | if (opa >= (unsigned int) fc->ncols) |
| 8069 | reg_prefix = bad_reg; |
| 8070 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8071 | printf (" DW_CFA_restore: %s%s\n", |
| 8072 | reg_prefix, regname (opa, 0)); |
| 8073 | if (*reg_prefix != '\0') |
| 8074 | break; |
| 8075 | |
| 8076 | if (opa >= (unsigned int) cie->ncols |
| 8077 | || (do_debug_frames_interp |
| 8078 | && cie->col_type[opa] == DW_CFA_unreferenced)) |
| 8079 | { |
| 8080 | fc->col_type[opa] = DW_CFA_undefined; |
| 8081 | fc->col_offset[opa] = 0; |
| 8082 | } |
| 8083 | else |
| 8084 | { |
| 8085 | fc->col_type[opa] = cie->col_type[opa]; |
| 8086 | fc->col_offset[opa] = cie->col_offset[opa]; |
| 8087 | } |
| 8088 | break; |
| 8089 | |
| 8090 | case DW_CFA_set_loc: |
| 8091 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
| 8092 | if (do_debug_frames_interp) |
| 8093 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8094 | else |
| 8095 | printf (" DW_CFA_set_loc: %s\n", |
| 8096 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); |
| 8097 | fc->pc_begin = vma; |
| 8098 | break; |
| 8099 | |
| 8100 | case DW_CFA_advance_loc1: |
| 8101 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
| 8102 | if (do_debug_frames_interp) |
| 8103 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8104 | else |
| 8105 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
| 8106 | (unsigned long) (ofs * fc->code_factor), |
| 8107 | dwarf_vmatoa_1 (NULL, |
| 8108 | fc->pc_begin + ofs * fc->code_factor, |
| 8109 | fc->ptr_size)); |
| 8110 | fc->pc_begin += ofs * fc->code_factor; |
| 8111 | break; |
| 8112 | |
| 8113 | case DW_CFA_advance_loc2: |
| 8114 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
| 8115 | if (do_debug_frames_interp) |
| 8116 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8117 | else |
| 8118 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
| 8119 | (unsigned long) (ofs * fc->code_factor), |
| 8120 | dwarf_vmatoa_1 (NULL, |
| 8121 | fc->pc_begin + ofs * fc->code_factor, |
| 8122 | fc->ptr_size)); |
| 8123 | fc->pc_begin += ofs * fc->code_factor; |
| 8124 | break; |
| 8125 | |
| 8126 | case DW_CFA_advance_loc4: |
| 8127 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
| 8128 | if (do_debug_frames_interp) |
| 8129 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8130 | else |
| 8131 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
| 8132 | (unsigned long) (ofs * fc->code_factor), |
| 8133 | dwarf_vmatoa_1 (NULL, |
| 8134 | fc->pc_begin + ofs * fc->code_factor, |
| 8135 | fc->ptr_size)); |
| 8136 | fc->pc_begin += ofs * fc->code_factor; |
| 8137 | break; |
| 8138 | |
| 8139 | case DW_CFA_offset_extended: |
| 8140 | READ_ULEB (reg); |
| 8141 | READ_ULEB (roffs); |
| 8142 | if (reg >= (unsigned int) fc->ncols) |
| 8143 | reg_prefix = bad_reg; |
| 8144 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8145 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", |
| 8146 | reg_prefix, regname (reg, 0), |
| 8147 | roffs * fc->data_factor); |
| 8148 | if (*reg_prefix == '\0') |
| 8149 | { |
| 8150 | fc->col_type[reg] = DW_CFA_offset; |
| 8151 | fc->col_offset[reg] = roffs * fc->data_factor; |
| 8152 | } |
| 8153 | break; |
| 8154 | |
| 8155 | case DW_CFA_val_offset: |
| 8156 | READ_ULEB (reg); |
| 8157 | READ_ULEB (roffs); |
| 8158 | if (reg >= (unsigned int) fc->ncols) |
| 8159 | reg_prefix = bad_reg; |
| 8160 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8161 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
| 8162 | reg_prefix, regname (reg, 0), |
| 8163 | roffs * fc->data_factor); |
| 8164 | if (*reg_prefix == '\0') |
| 8165 | { |
| 8166 | fc->col_type[reg] = DW_CFA_val_offset; |
| 8167 | fc->col_offset[reg] = roffs * fc->data_factor; |
| 8168 | } |
| 8169 | break; |
| 8170 | |
| 8171 | case DW_CFA_restore_extended: |
| 8172 | READ_ULEB (reg); |
| 8173 | if (reg >= (unsigned int) fc->ncols) |
| 8174 | reg_prefix = bad_reg; |
| 8175 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8176 | printf (" DW_CFA_restore_extended: %s%s\n", |
| 8177 | reg_prefix, regname (reg, 0)); |
| 8178 | if (*reg_prefix != '\0') |
| 8179 | break; |
| 8180 | |
| 8181 | if (reg >= (unsigned int) cie->ncols) |
| 8182 | { |
| 8183 | fc->col_type[reg] = DW_CFA_undefined; |
| 8184 | fc->col_offset[reg] = 0; |
| 8185 | } |
| 8186 | else |
| 8187 | { |
| 8188 | fc->col_type[reg] = cie->col_type[reg]; |
| 8189 | fc->col_offset[reg] = cie->col_offset[reg]; |
| 8190 | } |
| 8191 | break; |
| 8192 | |
| 8193 | case DW_CFA_undefined: |
| 8194 | READ_ULEB (reg); |
| 8195 | if (reg >= (unsigned int) fc->ncols) |
| 8196 | reg_prefix = bad_reg; |
| 8197 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8198 | printf (" DW_CFA_undefined: %s%s\n", |
| 8199 | reg_prefix, regname (reg, 0)); |
| 8200 | if (*reg_prefix == '\0') |
| 8201 | { |
| 8202 | fc->col_type[reg] = DW_CFA_undefined; |
| 8203 | fc->col_offset[reg] = 0; |
| 8204 | } |
| 8205 | break; |
| 8206 | |
| 8207 | case DW_CFA_same_value: |
| 8208 | READ_ULEB (reg); |
| 8209 | if (reg >= (unsigned int) fc->ncols) |
| 8210 | reg_prefix = bad_reg; |
| 8211 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8212 | printf (" DW_CFA_same_value: %s%s\n", |
| 8213 | reg_prefix, regname (reg, 0)); |
| 8214 | if (*reg_prefix == '\0') |
| 8215 | { |
| 8216 | fc->col_type[reg] = DW_CFA_same_value; |
| 8217 | fc->col_offset[reg] = 0; |
| 8218 | } |
| 8219 | break; |
| 8220 | |
| 8221 | case DW_CFA_register: |
| 8222 | READ_ULEB (reg); |
| 8223 | READ_ULEB (roffs); |
| 8224 | if (reg >= (unsigned int) fc->ncols) |
| 8225 | reg_prefix = bad_reg; |
| 8226 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8227 | { |
| 8228 | printf (" DW_CFA_register: %s%s in ", |
| 8229 | reg_prefix, regname (reg, 0)); |
| 8230 | puts (regname (roffs, 0)); |
| 8231 | } |
| 8232 | if (*reg_prefix == '\0') |
| 8233 | { |
| 8234 | fc->col_type[reg] = DW_CFA_register; |
| 8235 | fc->col_offset[reg] = roffs; |
| 8236 | } |
| 8237 | break; |
| 8238 | |
| 8239 | case DW_CFA_remember_state: |
| 8240 | if (! do_debug_frames_interp) |
| 8241 | printf (" DW_CFA_remember_state\n"); |
| 8242 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
| 8243 | rs->cfa_offset = fc->cfa_offset; |
| 8244 | rs->cfa_reg = fc->cfa_reg; |
| 8245 | rs->ra = fc->ra; |
| 8246 | rs->cfa_exp = fc->cfa_exp; |
| 8247 | rs->ncols = fc->ncols; |
| 8248 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
| 8249 | sizeof (* rs->col_type)); |
| 8250 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
| 8251 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); |
| 8252 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); |
| 8253 | rs->next = remembered_state; |
| 8254 | remembered_state = rs; |
| 8255 | break; |
| 8256 | |
| 8257 | case DW_CFA_restore_state: |
| 8258 | if (! do_debug_frames_interp) |
| 8259 | printf (" DW_CFA_restore_state\n"); |
| 8260 | rs = remembered_state; |
| 8261 | if (rs) |
| 8262 | { |
| 8263 | remembered_state = rs->next; |
| 8264 | fc->cfa_offset = rs->cfa_offset; |
| 8265 | fc->cfa_reg = rs->cfa_reg; |
| 8266 | fc->ra = rs->ra; |
| 8267 | fc->cfa_exp = rs->cfa_exp; |
| 8268 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
| 8269 | { |
| 8270 | warn (_("Invalid column number in saved frame state\n")); |
| 8271 | fc->ncols = 0; |
| 8272 | break; |
| 8273 | } |
| 8274 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
| 8275 | memcpy (fc->col_offset, rs->col_offset, |
| 8276 | rs->ncols * sizeof (* rs->col_offset)); |
| 8277 | free (rs->col_type); |
| 8278 | free (rs->col_offset); |
| 8279 | free (rs); |
| 8280 | } |
| 8281 | else if (do_debug_frames_interp) |
| 8282 | printf ("Mismatched DW_CFA_restore_state\n"); |
| 8283 | break; |
| 8284 | |
| 8285 | case DW_CFA_def_cfa: |
| 8286 | READ_ULEB (fc->cfa_reg); |
| 8287 | READ_ULEB (fc->cfa_offset); |
| 8288 | fc->cfa_exp = 0; |
| 8289 | if (! do_debug_frames_interp) |
| 8290 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
| 8291 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
| 8292 | break; |
| 8293 | |
| 8294 | case DW_CFA_def_cfa_register: |
| 8295 | READ_ULEB (fc->cfa_reg); |
| 8296 | fc->cfa_exp = 0; |
| 8297 | if (! do_debug_frames_interp) |
| 8298 | printf (" DW_CFA_def_cfa_register: %s\n", |
| 8299 | regname (fc->cfa_reg, 0)); |
| 8300 | break; |
| 8301 | |
| 8302 | case DW_CFA_def_cfa_offset: |
| 8303 | READ_ULEB (fc->cfa_offset); |
| 8304 | if (! do_debug_frames_interp) |
| 8305 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
| 8306 | break; |
| 8307 | |
| 8308 | case DW_CFA_nop: |
| 8309 | if (! do_debug_frames_interp) |
| 8310 | printf (" DW_CFA_nop\n"); |
| 8311 | break; |
| 8312 | |
| 8313 | case DW_CFA_def_cfa_expression: |
| 8314 | READ_ULEB (ul); |
| 8315 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
| 8316 | { |
| 8317 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
| 8318 | break; |
| 8319 | } |
| 8320 | if (! do_debug_frames_interp) |
| 8321 | { |
| 8322 | printf (" DW_CFA_def_cfa_expression ("); |
| 8323 | decode_location_expression (start, eh_addr_size, 0, -1, |
| 8324 | ul, 0, section); |
| 8325 | printf (")\n"); |
| 8326 | } |
| 8327 | fc->cfa_exp = 1; |
| 8328 | start += ul; |
| 8329 | break; |
| 8330 | |
| 8331 | case DW_CFA_expression: |
| 8332 | READ_ULEB (reg); |
| 8333 | READ_ULEB (ul); |
| 8334 | if (reg >= (unsigned int) fc->ncols) |
| 8335 | reg_prefix = bad_reg; |
| 8336 | /* PR 17512: file: 069-133014-0.006. */ |
| 8337 | /* PR 17512: file: 98c02eb4. */ |
| 8338 | tmp = start + ul; |
| 8339 | if (start >= block_end || tmp > block_end || tmp < start) |
| 8340 | { |
| 8341 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
| 8342 | break; |
| 8343 | } |
| 8344 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8345 | { |
| 8346 | printf (" DW_CFA_expression: %s%s (", |
| 8347 | reg_prefix, regname (reg, 0)); |
| 8348 | decode_location_expression (start, eh_addr_size, 0, -1, |
| 8349 | ul, 0, section); |
| 8350 | printf (")\n"); |
| 8351 | } |
| 8352 | if (*reg_prefix == '\0') |
| 8353 | fc->col_type[reg] = DW_CFA_expression; |
| 8354 | start = tmp; |
| 8355 | break; |
| 8356 | |
| 8357 | case DW_CFA_val_expression: |
| 8358 | READ_ULEB (reg); |
| 8359 | READ_ULEB (ul); |
| 8360 | if (reg >= (unsigned int) fc->ncols) |
| 8361 | reg_prefix = bad_reg; |
| 8362 | tmp = start + ul; |
| 8363 | if (start >= block_end || tmp > block_end || tmp < start) |
| 8364 | { |
| 8365 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
| 8366 | break; |
| 8367 | } |
| 8368 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8369 | { |
| 8370 | printf (" DW_CFA_val_expression: %s%s (", |
| 8371 | reg_prefix, regname (reg, 0)); |
| 8372 | decode_location_expression (start, eh_addr_size, 0, -1, |
| 8373 | ul, 0, section); |
| 8374 | printf (")\n"); |
| 8375 | } |
| 8376 | if (*reg_prefix == '\0') |
| 8377 | fc->col_type[reg] = DW_CFA_val_expression; |
| 8378 | start = tmp; |
| 8379 | break; |
| 8380 | |
| 8381 | case DW_CFA_offset_extended_sf: |
| 8382 | READ_ULEB (reg); |
| 8383 | READ_SLEB (l); |
| 8384 | if (frame_need_space (fc, reg) < 0) |
| 8385 | reg_prefix = bad_reg; |
| 8386 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8387 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", |
| 8388 | reg_prefix, regname (reg, 0), |
| 8389 | (long)(l * fc->data_factor)); |
| 8390 | if (*reg_prefix == '\0') |
| 8391 | { |
| 8392 | fc->col_type[reg] = DW_CFA_offset; |
| 8393 | fc->col_offset[reg] = l * fc->data_factor; |
| 8394 | } |
| 8395 | break; |
| 8396 | |
| 8397 | case DW_CFA_val_offset_sf: |
| 8398 | READ_ULEB (reg); |
| 8399 | READ_SLEB (l); |
| 8400 | if (frame_need_space (fc, reg) < 0) |
| 8401 | reg_prefix = bad_reg; |
| 8402 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8403 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
| 8404 | reg_prefix, regname (reg, 0), |
| 8405 | (long)(l * fc->data_factor)); |
| 8406 | if (*reg_prefix == '\0') |
| 8407 | { |
| 8408 | fc->col_type[reg] = DW_CFA_val_offset; |
| 8409 | fc->col_offset[reg] = l * fc->data_factor; |
| 8410 | } |
| 8411 | break; |
| 8412 | |
| 8413 | case DW_CFA_def_cfa_sf: |
| 8414 | READ_ULEB (fc->cfa_reg); |
| 8415 | READ_ULEB (fc->cfa_offset); |
| 8416 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
| 8417 | fc->cfa_exp = 0; |
| 8418 | if (! do_debug_frames_interp) |
| 8419 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
| 8420 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
| 8421 | break; |
| 8422 | |
| 8423 | case DW_CFA_def_cfa_offset_sf: |
| 8424 | READ_ULEB (fc->cfa_offset); |
| 8425 | fc->cfa_offset *= fc->data_factor; |
| 8426 | if (! do_debug_frames_interp) |
| 8427 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
| 8428 | break; |
| 8429 | |
| 8430 | case DW_CFA_MIPS_advance_loc8: |
| 8431 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
| 8432 | if (do_debug_frames_interp) |
| 8433 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8434 | else |
| 8435 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
| 8436 | (unsigned long) (ofs * fc->code_factor), |
| 8437 | dwarf_vmatoa_1 (NULL, |
| 8438 | fc->pc_begin + ofs * fc->code_factor, |
| 8439 | fc->ptr_size)); |
| 8440 | fc->pc_begin += ofs * fc->code_factor; |
| 8441 | break; |
| 8442 | |
| 8443 | case DW_CFA_GNU_window_save: |
| 8444 | if (! do_debug_frames_interp) |
| 8445 | printf (" DW_CFA_GNU_window_save\n"); |
| 8446 | break; |
| 8447 | |
| 8448 | case DW_CFA_GNU_args_size: |
| 8449 | READ_ULEB (ul); |
| 8450 | if (! do_debug_frames_interp) |
| 8451 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); |
| 8452 | break; |
| 8453 | |
| 8454 | case DW_CFA_GNU_negative_offset_extended: |
| 8455 | READ_ULEB (reg); |
| 8456 | READ_SLEB (l); |
| 8457 | l = - l; |
| 8458 | if (frame_need_space (fc, reg) < 0) |
| 8459 | reg_prefix = bad_reg; |
| 8460 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
| 8461 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", |
| 8462 | reg_prefix, regname (reg, 0), |
| 8463 | (long)(l * fc->data_factor)); |
| 8464 | if (*reg_prefix == '\0') |
| 8465 | { |
| 8466 | fc->col_type[reg] = DW_CFA_offset; |
| 8467 | fc->col_offset[reg] = l * fc->data_factor; |
| 8468 | } |
| 8469 | break; |
| 8470 | |
| 8471 | default: |
| 8472 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
| 8473 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); |
| 8474 | else |
| 8475 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
| 8476 | start = block_end; |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
| 8481 | if (do_debug_frames_interp && ! all_nops) |
| 8482 | frame_display_row (fc, &need_col_headers, &max_regs); |
| 8483 | |
| 8484 | start = block_end; |
| 8485 | eh_addr_size = saved_eh_addr_size; |
| 8486 | } |
| 8487 | |
| 8488 | printf ("\n"); |
| 8489 | |
| 8490 | while (remembered_state != NULL) |
| 8491 | { |
| 8492 | rs = remembered_state; |
| 8493 | remembered_state = rs->next; |
| 8494 | free (rs->col_type); |
| 8495 | free (rs->col_offset); |
| 8496 | rs->next = NULL; /* Paranoia. */ |
| 8497 | free (rs); |
| 8498 | } |
| 8499 | |
| 8500 | while (chunks != NULL) |
| 8501 | { |
| 8502 | rs = chunks; |
| 8503 | chunks = rs->next; |
| 8504 | free (rs->col_type); |
| 8505 | free (rs->col_offset); |
| 8506 | rs->next = NULL; /* Paranoia. */ |
| 8507 | free (rs); |
| 8508 | } |
| 8509 | |
| 8510 | while (forward_refs != NULL) |
| 8511 | { |
| 8512 | rs = forward_refs; |
| 8513 | forward_refs = rs->next; |
| 8514 | free (rs->col_type); |
| 8515 | free (rs->col_offset); |
| 8516 | rs->next = NULL; /* Paranoia. */ |
| 8517 | free (rs); |
| 8518 | } |
| 8519 | |
| 8520 | return 1; |
| 8521 | } |
| 8522 | |
| 8523 | #undef GET |
| 8524 | |
| 8525 | static int |
| 8526 | display_debug_names (struct dwarf_section *section, void *file) |
| 8527 | { |
| 8528 | unsigned char *hdrptr = section->start; |
| 8529 | dwarf_vma unit_length; |
| 8530 | unsigned char *unit_start; |
| 8531 | const unsigned char *const section_end = section->start + section->size; |
| 8532 | unsigned char *unit_end; |
| 8533 | |
| 8534 | introduce (section, FALSE); |
| 8535 | |
| 8536 | load_debug_section_with_follow (str, file); |
| 8537 | |
| 8538 | for (; hdrptr < section_end; hdrptr = unit_end) |
| 8539 | { |
| 8540 | unsigned int offset_size; |
| 8541 | uint16_t dwarf_version, padding; |
| 8542 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; |
| 8543 | uint32_t bucket_count, name_count, abbrev_table_size; |
| 8544 | uint32_t augmentation_string_size; |
| 8545 | unsigned int i; |
| 8546 | unsigned long sec_off; |
| 8547 | bfd_boolean augmentation_printable; |
| 8548 | const char *augmentation_string; |
| 8549 | |
| 8550 | unit_start = hdrptr; |
| 8551 | |
| 8552 | /* Get and check the length of the block. */ |
| 8553 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); |
| 8554 | |
| 8555 | if (unit_length == 0xffffffff) |
| 8556 | { |
| 8557 | /* This section is 64-bit DWARF. */ |
| 8558 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); |
| 8559 | offset_size = 8; |
| 8560 | } |
| 8561 | else |
| 8562 | offset_size = 4; |
| 8563 | unit_end = hdrptr + unit_length; |
| 8564 | |
| 8565 | sec_off = hdrptr - section->start; |
| 8566 | if (sec_off + unit_length < sec_off |
| 8567 | || sec_off + unit_length > section->size) |
| 8568 | { |
| 8569 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
| 8570 | section->name, |
| 8571 | (unsigned long) (unit_start - section->start), |
| 8572 | dwarf_vmatoa ("x", unit_length)); |
| 8573 | return 0; |
| 8574 | } |
| 8575 | |
| 8576 | /* Get and check the version number. */ |
| 8577 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); |
| 8578 | printf (_("Version %ld\n"), (long) dwarf_version); |
| 8579 | |
| 8580 | /* Prior versions did not exist, and future versions may not be |
| 8581 | backwards compatible. */ |
| 8582 | if (dwarf_version != 5) |
| 8583 | { |
| 8584 | warn (_("Only DWARF version 5 .debug_names " |
| 8585 | "is currently supported.\n")); |
| 8586 | return 0; |
| 8587 | } |
| 8588 | |
| 8589 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); |
| 8590 | if (padding != 0) |
| 8591 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), |
| 8592 | padding); |
| 8593 | |
| 8594 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); |
| 8595 | if (comp_unit_count == 0) |
| 8596 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); |
| 8597 | |
| 8598 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); |
| 8599 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); |
| 8600 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); |
| 8601 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); |
| 8602 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); |
| 8603 | |
| 8604 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); |
| 8605 | if (augmentation_string_size % 4 != 0) |
| 8606 | { |
| 8607 | warn (_("Augmentation string length %u must be rounded up " |
| 8608 | "to a multiple of 4 in .debug_names.\n"), |
| 8609 | augmentation_string_size); |
| 8610 | augmentation_string_size += (-augmentation_string_size) & 3; |
| 8611 | } |
| 8612 | |
| 8613 | printf (_("Augmentation string:")); |
| 8614 | |
| 8615 | augmentation_printable = TRUE; |
| 8616 | augmentation_string = (const char *) hdrptr; |
| 8617 | |
| 8618 | for (i = 0; i < augmentation_string_size; i++) |
| 8619 | { |
| 8620 | unsigned char uc; |
| 8621 | |
| 8622 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); |
| 8623 | printf (" %02x", uc); |
| 8624 | |
| 8625 | if (uc != 0 && !ISPRINT (uc)) |
| 8626 | augmentation_printable = FALSE; |
| 8627 | } |
| 8628 | |
| 8629 | if (augmentation_printable) |
| 8630 | { |
| 8631 | printf (" (\""); |
| 8632 | for (i = 0; |
| 8633 | i < augmentation_string_size && augmentation_string[i]; |
| 8634 | ++i) |
| 8635 | putchar (augmentation_string[i]); |
| 8636 | printf ("\")"); |
| 8637 | } |
| 8638 | putchar ('\n'); |
| 8639 | |
| 8640 | printf (_("CU table:\n")); |
| 8641 | for (i = 0; i < comp_unit_count; i++) |
| 8642 | { |
| 8643 | uint64_t cu_offset; |
| 8644 | |
| 8645 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); |
| 8646 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); |
| 8647 | } |
| 8648 | putchar ('\n'); |
| 8649 | |
| 8650 | printf (_("TU table:\n")); |
| 8651 | for (i = 0; i < local_type_unit_count; i++) |
| 8652 | { |
| 8653 | uint64_t tu_offset; |
| 8654 | |
| 8655 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); |
| 8656 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); |
| 8657 | } |
| 8658 | putchar ('\n'); |
| 8659 | |
| 8660 | printf (_("Foreign TU table:\n")); |
| 8661 | for (i = 0; i < foreign_type_unit_count; i++) |
| 8662 | { |
| 8663 | uint64_t signature; |
| 8664 | |
| 8665 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); |
| 8666 | printf (_("[%3u] "), i); |
| 8667 | print_dwarf_vma (signature, 8); |
| 8668 | putchar ('\n'); |
| 8669 | } |
| 8670 | putchar ('\n'); |
| 8671 | |
| 8672 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
| 8673 | hdrptr += bucket_count * sizeof (uint32_t); |
| 8674 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; |
| 8675 | hdrptr += name_count * sizeof (uint32_t); |
| 8676 | unsigned char *const name_table_string_offsets = hdrptr; |
| 8677 | hdrptr += name_count * offset_size; |
| 8678 | unsigned char *const name_table_entry_offsets = hdrptr; |
| 8679 | hdrptr += name_count * offset_size; |
| 8680 | unsigned char *const abbrev_table = hdrptr; |
| 8681 | hdrptr += abbrev_table_size; |
| 8682 | const unsigned char *const abbrev_table_end = hdrptr; |
| 8683 | unsigned char *const entry_pool = hdrptr; |
| 8684 | if (hdrptr > unit_end) |
| 8685 | { |
| 8686 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " |
| 8687 | "for unit 0x%lx in the debug_names\n"), |
| 8688 | (long) (hdrptr - section->start), |
| 8689 | (long) (unit_end - section->start), |
| 8690 | (long) (unit_start - section->start)); |
| 8691 | return 0; |
| 8692 | } |
| 8693 | |
| 8694 | size_t buckets_filled = 0; |
| 8695 | size_t bucketi; |
| 8696 | for (bucketi = 0; bucketi < bucket_count; bucketi++) |
| 8697 | { |
| 8698 | const uint32_t bucket = hash_table_buckets[bucketi]; |
| 8699 | |
| 8700 | if (bucket != 0) |
| 8701 | ++buckets_filled; |
| 8702 | } |
| 8703 | printf (ngettext ("Used %zu of %lu bucket.\n", |
| 8704 | "Used %zu of %lu buckets.\n", |
| 8705 | bucket_count), |
| 8706 | buckets_filled, (unsigned long) bucket_count); |
| 8707 | |
| 8708 | uint32_t hash_prev = 0; |
| 8709 | size_t hash_clash_count = 0; |
| 8710 | size_t longest_clash = 0; |
| 8711 | size_t this_length = 0; |
| 8712 | size_t hashi; |
| 8713 | for (hashi = 0; hashi < name_count; hashi++) |
| 8714 | { |
| 8715 | const uint32_t hash_this = hash_table_hashes[hashi]; |
| 8716 | |
| 8717 | if (hashi > 0) |
| 8718 | { |
| 8719 | if (hash_prev % bucket_count == hash_this % bucket_count) |
| 8720 | { |
| 8721 | ++hash_clash_count; |
| 8722 | ++this_length; |
| 8723 | longest_clash = MAX (longest_clash, this_length); |
| 8724 | } |
| 8725 | else |
| 8726 | this_length = 0; |
| 8727 | } |
| 8728 | hash_prev = hash_this; |
| 8729 | } |
| 8730 | printf (_("Out of %lu items there are %zu bucket clashes" |
| 8731 | " (longest of %zu entries).\n"), |
| 8732 | (unsigned long) name_count, hash_clash_count, longest_clash); |
| 8733 | assert (name_count == buckets_filled + hash_clash_count); |
| 8734 | |
| 8735 | struct abbrev_lookup_entry |
| 8736 | { |
| 8737 | dwarf_vma abbrev_tag; |
| 8738 | unsigned char *abbrev_lookup_ptr; |
| 8739 | }; |
| 8740 | struct abbrev_lookup_entry *abbrev_lookup = NULL; |
| 8741 | size_t abbrev_lookup_used = 0; |
| 8742 | size_t abbrev_lookup_allocated = 0; |
| 8743 | |
| 8744 | unsigned char *abbrevptr = abbrev_table; |
| 8745 | for (;;) |
| 8746 | { |
| 8747 | unsigned int bytes_read; |
| 8748 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, |
| 8749 | abbrev_table_end); |
| 8750 | abbrevptr += bytes_read; |
| 8751 | if (abbrev_tag == 0) |
| 8752 | break; |
| 8753 | if (abbrev_lookup_used == abbrev_lookup_allocated) |
| 8754 | { |
| 8755 | abbrev_lookup_allocated = MAX (0x100, |
| 8756 | abbrev_lookup_allocated * 2); |
| 8757 | abbrev_lookup = xrealloc (abbrev_lookup, |
| 8758 | (abbrev_lookup_allocated |
| 8759 | * sizeof (*abbrev_lookup))); |
| 8760 | } |
| 8761 | assert (abbrev_lookup_used < abbrev_lookup_allocated); |
| 8762 | struct abbrev_lookup_entry *entry; |
| 8763 | for (entry = abbrev_lookup; |
| 8764 | entry < abbrev_lookup + abbrev_lookup_used; |
| 8765 | entry++) |
| 8766 | if (entry->abbrev_tag == abbrev_tag) |
| 8767 | { |
| 8768 | warn (_("Duplicate abbreviation tag %lu " |
| 8769 | "in unit 0x%lx in the debug_names\n"), |
| 8770 | (long) abbrev_tag, (long) (unit_start - section->start)); |
| 8771 | break; |
| 8772 | } |
| 8773 | entry = &abbrev_lookup[abbrev_lookup_used++]; |
| 8774 | entry->abbrev_tag = abbrev_tag; |
| 8775 | entry->abbrev_lookup_ptr = abbrevptr; |
| 8776 | |
| 8777 | /* Skip DWARF tag. */ |
| 8778 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); |
| 8779 | abbrevptr += bytes_read; |
| 8780 | for (;;) |
| 8781 | { |
| 8782 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
| 8783 | &bytes_read, |
| 8784 | abbrev_table_end); |
| 8785 | abbrevptr += bytes_read; |
| 8786 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, |
| 8787 | abbrev_table_end); |
| 8788 | abbrevptr += bytes_read; |
| 8789 | if (xindex == 0 && form == 0) |
| 8790 | break; |
| 8791 | } |
| 8792 | } |
| 8793 | |
| 8794 | printf (_("\nSymbol table:\n")); |
| 8795 | uint32_t namei; |
| 8796 | for (namei = 0; namei < name_count; ++namei) |
| 8797 | { |
| 8798 | uint64_t string_offset, entry_offset; |
| 8799 | |
| 8800 | SAFE_BYTE_GET (string_offset, |
| 8801 | name_table_string_offsets + namei * offset_size, |
| 8802 | offset_size, unit_end); |
| 8803 | SAFE_BYTE_GET (entry_offset, |
| 8804 | name_table_entry_offsets + namei * offset_size, |
| 8805 | offset_size, unit_end); |
| 8806 | |
| 8807 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], |
| 8808 | fetch_indirect_string (string_offset)); |
| 8809 | |
| 8810 | unsigned char *entryptr = entry_pool + entry_offset; |
| 8811 | |
| 8812 | // We need to scan first whether there is a single or multiple |
| 8813 | // entries. TAGNO is -2 for the first entry, it is -1 for the |
| 8814 | // initial tag read of the second entry, then it becomes 0 for the |
| 8815 | // first entry for real printing etc. |
| 8816 | int tagno = -2; |
| 8817 | /* Initialize it due to a false compiler warning. */ |
| 8818 | dwarf_vma second_abbrev_tag = -1; |
| 8819 | for (;;) |
| 8820 | { |
| 8821 | unsigned int bytes_read; |
| 8822 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, |
| 8823 | unit_end); |
| 8824 | entryptr += bytes_read; |
| 8825 | if (tagno == -1) |
| 8826 | { |
| 8827 | second_abbrev_tag = abbrev_tag; |
| 8828 | tagno = 0; |
| 8829 | entryptr = entry_pool + entry_offset; |
| 8830 | continue; |
| 8831 | } |
| 8832 | if (abbrev_tag == 0) |
| 8833 | break; |
| 8834 | if (tagno >= 0) |
| 8835 | printf ("%s<%lu>", |
| 8836 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), |
| 8837 | (unsigned long) abbrev_tag); |
| 8838 | |
| 8839 | const struct abbrev_lookup_entry *entry; |
| 8840 | for (entry = abbrev_lookup; |
| 8841 | entry < abbrev_lookup + abbrev_lookup_used; |
| 8842 | entry++) |
| 8843 | if (entry->abbrev_tag == abbrev_tag) |
| 8844 | break; |
| 8845 | if (entry >= abbrev_lookup + abbrev_lookup_used) |
| 8846 | { |
| 8847 | warn (_("Undefined abbreviation tag %lu " |
| 8848 | "in unit 0x%lx in the debug_names\n"), |
| 8849 | (long) abbrev_tag, |
| 8850 | (long) (unit_start - section->start)); |
| 8851 | break; |
| 8852 | } |
| 8853 | abbrevptr = entry->abbrev_lookup_ptr; |
| 8854 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, |
| 8855 | abbrev_table_end); |
| 8856 | abbrevptr += bytes_read; |
| 8857 | if (tagno >= 0) |
| 8858 | printf (" %s", get_TAG_name (dwarf_tag)); |
| 8859 | for (;;) |
| 8860 | { |
| 8861 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
| 8862 | &bytes_read, |
| 8863 | abbrev_table_end); |
| 8864 | abbrevptr += bytes_read; |
| 8865 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, |
| 8866 | abbrev_table_end); |
| 8867 | abbrevptr += bytes_read; |
| 8868 | if (xindex == 0 && form == 0) |
| 8869 | break; |
| 8870 | |
| 8871 | if (tagno >= 0) |
| 8872 | printf (" %s", get_IDX_name (xindex)); |
| 8873 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, |
| 8874 | unit_end, 0, 0, |
| 8875 | offset_size, |
| 8876 | dwarf_version, NULL, |
| 8877 | (tagno < 0), NULL, |
| 8878 | NULL, '='); |
| 8879 | } |
| 8880 | ++tagno; |
| 8881 | } |
| 8882 | if (tagno <= 0) |
| 8883 | printf (_(" <no entries>")); |
| 8884 | putchar ('\n'); |
| 8885 | } |
| 8886 | |
| 8887 | free (abbrev_lookup); |
| 8888 | } |
| 8889 | |
| 8890 | return 1; |
| 8891 | } |
| 8892 | |
| 8893 | static int |
| 8894 | display_debug_links (struct dwarf_section * section, |
| 8895 | void * file ATTRIBUTE_UNUSED) |
| 8896 | { |
| 8897 | const unsigned char * filename; |
| 8898 | unsigned int filelen; |
| 8899 | |
| 8900 | introduce (section, FALSE); |
| 8901 | |
| 8902 | /* The .gnu_debuglink section is formatted as: |
| 8903 | (c-string) Filename. |
| 8904 | (padding) If needed to reach a 4 byte boundary. |
| 8905 | (uint32_t) CRC32 value. |
| 8906 | |
| 8907 | The .gun_debugaltlink section is formatted as: |
| 8908 | (c-string) Filename. |
| 8909 | (binary) Build-ID. */ |
| 8910 | |
| 8911 | filename = section->start; |
| 8912 | filelen = strnlen ((const char *) filename, section->size); |
| 8913 | if (filelen == section->size) |
| 8914 | { |
| 8915 | warn (_("The debuglink filename is corrupt/missing\n")); |
| 8916 | return 0; |
| 8917 | } |
| 8918 | |
| 8919 | printf (_(" Separate debug info file: %s\n"), filename); |
| 8920 | |
| 8921 | if (const_strneq (section->name, ".gnu_debuglink")) |
| 8922 | { |
| 8923 | unsigned int crc32; |
| 8924 | unsigned int crc_offset; |
| 8925 | |
| 8926 | crc_offset = filelen + 1; |
| 8927 | crc_offset = (crc_offset + 3) & ~3; |
| 8928 | if (crc_offset + 4 > section->size) |
| 8929 | { |
| 8930 | warn (_("CRC offset missing/truncated\n")); |
| 8931 | return 0; |
| 8932 | } |
| 8933 | |
| 8934 | crc32 = byte_get (filename + crc_offset, 4); |
| 8935 | |
| 8936 | printf (_(" CRC value: %#x\n"), crc32); |
| 8937 | |
| 8938 | if (crc_offset + 4 < section->size) |
| 8939 | { |
| 8940 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), |
| 8941 | (long)(section->size - (crc_offset + 4))); |
| 8942 | return 0; |
| 8943 | } |
| 8944 | } |
| 8945 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ |
| 8946 | { |
| 8947 | const unsigned char * build_id = section->start + filelen + 1; |
| 8948 | bfd_size_type build_id_len = section->size - (filelen + 1); |
| 8949 | bfd_size_type printed; |
| 8950 | |
| 8951 | /* FIXME: Should we support smaller build-id notes ? */ |
| 8952 | if (build_id_len < 0x14) |
| 8953 | { |
| 8954 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); |
| 8955 | return 0; |
| 8956 | } |
| 8957 | |
| 8958 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); |
| 8959 | display_data (printed, build_id, build_id_len); |
| 8960 | putchar ('\n'); |
| 8961 | } |
| 8962 | |
| 8963 | putchar ('\n'); |
| 8964 | return 1; |
| 8965 | } |
| 8966 | |
| 8967 | static int |
| 8968 | display_gdb_index (struct dwarf_section *section, |
| 8969 | void *file ATTRIBUTE_UNUSED) |
| 8970 | { |
| 8971 | unsigned char *start = section->start; |
| 8972 | uint32_t version; |
| 8973 | uint32_t cu_list_offset, tu_list_offset; |
| 8974 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; |
| 8975 | unsigned int cu_list_elements, tu_list_elements; |
| 8976 | unsigned int address_table_size, symbol_table_slots; |
| 8977 | unsigned char *cu_list, *tu_list; |
| 8978 | unsigned char *address_table, *symbol_table, *constant_pool; |
| 8979 | unsigned int i; |
| 8980 | |
| 8981 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ |
| 8982 | |
| 8983 | introduce (section, FALSE); |
| 8984 | |
| 8985 | if (section->size < 6 * sizeof (uint32_t)) |
| 8986 | { |
| 8987 | warn (_("Truncated header in the %s section.\n"), section->name); |
| 8988 | return 0; |
| 8989 | } |
| 8990 | |
| 8991 | version = byte_get_little_endian (start, 4); |
| 8992 | printf (_("Version %ld\n"), (long) version); |
| 8993 | |
| 8994 | /* Prior versions are obsolete, and future versions may not be |
| 8995 | backwards compatible. */ |
| 8996 | if (version < 3 || version > 8) |
| 8997 | { |
| 8998 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
| 8999 | return 0; |
| 9000 | } |
| 9001 | if (version < 4) |
| 9002 | warn (_("The address table data in version 3 may be wrong.\n")); |
| 9003 | if (version < 5) |
| 9004 | warn (_("Version 4 does not support case insensitive lookups.\n")); |
| 9005 | if (version < 6) |
| 9006 | warn (_("Version 5 does not include inlined functions.\n")); |
| 9007 | if (version < 7) |
| 9008 | warn (_("Version 6 does not include symbol attributes.\n")); |
| 9009 | /* Version 7 indices generated by Gold have bad type unit references, |
| 9010 | PR binutils/15021. But we don't know if the index was generated by |
| 9011 | Gold or not, so to avoid worrying users with gdb-generated indices |
| 9012 | we say nothing for version 7 here. */ |
| 9013 | |
| 9014 | cu_list_offset = byte_get_little_endian (start + 4, 4); |
| 9015 | tu_list_offset = byte_get_little_endian (start + 8, 4); |
| 9016 | address_table_offset = byte_get_little_endian (start + 12, 4); |
| 9017 | symbol_table_offset = byte_get_little_endian (start + 16, 4); |
| 9018 | constant_pool_offset = byte_get_little_endian (start + 20, 4); |
| 9019 | |
| 9020 | if (cu_list_offset > section->size |
| 9021 | || tu_list_offset > section->size |
| 9022 | || address_table_offset > section->size |
| 9023 | || symbol_table_offset > section->size |
| 9024 | || constant_pool_offset > section->size) |
| 9025 | { |
| 9026 | warn (_("Corrupt header in the %s section.\n"), section->name); |
| 9027 | return 0; |
| 9028 | } |
| 9029 | |
| 9030 | /* PR 17531: file: 418d0a8a. */ |
| 9031 | if (tu_list_offset < cu_list_offset) |
| 9032 | { |
| 9033 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), |
| 9034 | tu_list_offset, cu_list_offset); |
| 9035 | return 0; |
| 9036 | } |
| 9037 | |
| 9038 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
| 9039 | |
| 9040 | if (address_table_offset < tu_list_offset) |
| 9041 | { |
| 9042 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), |
| 9043 | address_table_offset, tu_list_offset); |
| 9044 | return 0; |
| 9045 | } |
| 9046 | |
| 9047 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
| 9048 | |
| 9049 | /* PR 17531: file: 18a47d3d. */ |
| 9050 | if (symbol_table_offset < address_table_offset) |
| 9051 | { |
| 9052 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
| 9053 | symbol_table_offset, address_table_offset); |
| 9054 | return 0; |
| 9055 | } |
| 9056 | |
| 9057 | address_table_size = symbol_table_offset - address_table_offset; |
| 9058 | |
| 9059 | if (constant_pool_offset < symbol_table_offset) |
| 9060 | { |
| 9061 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), |
| 9062 | constant_pool_offset, symbol_table_offset); |
| 9063 | return 0; |
| 9064 | } |
| 9065 | |
| 9066 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
| 9067 | |
| 9068 | cu_list = start + cu_list_offset; |
| 9069 | tu_list = start + tu_list_offset; |
| 9070 | address_table = start + address_table_offset; |
| 9071 | symbol_table = start + symbol_table_offset; |
| 9072 | constant_pool = start + constant_pool_offset; |
| 9073 | |
| 9074 | if (address_table + address_table_size > section->start + section->size) |
| 9075 | { |
| 9076 | warn (_("Address table extends beyond end of section.\n")); |
| 9077 | return 0; |
| 9078 | } |
| 9079 | |
| 9080 | printf (_("\nCU table:\n")); |
| 9081 | for (i = 0; i < cu_list_elements; i += 2) |
| 9082 | { |
| 9083 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); |
| 9084 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); |
| 9085 | |
| 9086 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, |
| 9087 | (unsigned long) cu_offset, |
| 9088 | (unsigned long) (cu_offset + cu_length - 1)); |
| 9089 | } |
| 9090 | |
| 9091 | printf (_("\nTU table:\n")); |
| 9092 | for (i = 0; i < tu_list_elements; i += 3) |
| 9093 | { |
| 9094 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); |
| 9095 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); |
| 9096 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); |
| 9097 | |
| 9098 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, |
| 9099 | (unsigned long) tu_offset, |
| 9100 | (unsigned long) type_offset); |
| 9101 | print_dwarf_vma (signature, 8); |
| 9102 | printf ("\n"); |
| 9103 | } |
| 9104 | |
| 9105 | printf (_("\nAddress table:\n")); |
| 9106 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
| 9107 | i += 2 * 8 + 4) |
| 9108 | { |
| 9109 | uint64_t low = byte_get_little_endian (address_table + i, 8); |
| 9110 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); |
| 9111 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); |
| 9112 | |
| 9113 | print_dwarf_vma (low, 8); |
| 9114 | print_dwarf_vma (high, 8); |
| 9115 | printf (_("%lu\n"), (unsigned long) cu_index); |
| 9116 | } |
| 9117 | |
| 9118 | printf (_("\nSymbol table:\n")); |
| 9119 | for (i = 0; i < symbol_table_slots; ++i) |
| 9120 | { |
| 9121 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); |
| 9122 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); |
| 9123 | uint32_t num_cus, cu; |
| 9124 | |
| 9125 | if (name_offset != 0 |
| 9126 | || cu_vector_offset != 0) |
| 9127 | { |
| 9128 | unsigned int j; |
| 9129 | unsigned char * adr; |
| 9130 | |
| 9131 | adr = constant_pool + name_offset; |
| 9132 | /* PR 17531: file: 5b7b07ad. */ |
| 9133 | if (adr < constant_pool || adr >= section->start + section->size) |
| 9134 | { |
| 9135 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); |
| 9136 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), |
| 9137 | name_offset, i); |
| 9138 | } |
| 9139 | else |
| 9140 | printf ("[%3u] %.*s:", i, |
| 9141 | (int) (section->size - (constant_pool_offset + name_offset)), |
| 9142 | constant_pool + name_offset); |
| 9143 | |
| 9144 | adr = constant_pool + cu_vector_offset; |
| 9145 | if (adr < constant_pool || adr >= section->start + section->size - 3) |
| 9146 | { |
| 9147 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); |
| 9148 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), |
| 9149 | cu_vector_offset, i); |
| 9150 | continue; |
| 9151 | } |
| 9152 | |
| 9153 | num_cus = byte_get_little_endian (adr, 4); |
| 9154 | |
| 9155 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
| 9156 | if (num_cus * 4 < num_cus |
| 9157 | || adr >= section->start + section->size |
| 9158 | || adr < constant_pool) |
| 9159 | { |
| 9160 | printf ("<invalid number of CUs: %d>\n", num_cus); |
| 9161 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
| 9162 | num_cus, i); |
| 9163 | continue; |
| 9164 | } |
| 9165 | |
| 9166 | if (num_cus > 1) |
| 9167 | printf ("\n"); |
| 9168 | |
| 9169 | for (j = 0; j < num_cus; ++j) |
| 9170 | { |
| 9171 | int is_static; |
| 9172 | gdb_index_symbol_kind kind; |
| 9173 | |
| 9174 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
| 9175 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
| 9176 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
| 9177 | cu = GDB_INDEX_CU_VALUE (cu); |
| 9178 | /* Convert to TU number if it's for a type unit. */ |
| 9179 | if (cu >= cu_list_elements / 2) |
| 9180 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
| 9181 | (unsigned long) (cu - cu_list_elements / 2)); |
| 9182 | else |
| 9183 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
| 9184 | |
| 9185 | printf (" [%s, %s]", |
| 9186 | is_static ? _("static") : _("global"), |
| 9187 | get_gdb_index_symbol_kind_name (kind)); |
| 9188 | if (num_cus > 1) |
| 9189 | printf ("\n"); |
| 9190 | } |
| 9191 | if (num_cus <= 1) |
| 9192 | printf ("\n"); |
| 9193 | } |
| 9194 | } |
| 9195 | |
| 9196 | return 1; |
| 9197 | } |
| 9198 | |
| 9199 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
| 9200 | |
| 9201 | static void |
| 9202 | prealloc_cu_tu_list (unsigned int nshndx) |
| 9203 | { |
| 9204 | if (shndx_pool == NULL) |
| 9205 | { |
| 9206 | shndx_pool_size = nshndx; |
| 9207 | shndx_pool_used = 0; |
| 9208 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, |
| 9209 | sizeof (unsigned int)); |
| 9210 | } |
| 9211 | else |
| 9212 | { |
| 9213 | shndx_pool_size = shndx_pool_used + nshndx; |
| 9214 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, |
| 9215 | sizeof (unsigned int)); |
| 9216 | } |
| 9217 | } |
| 9218 | |
| 9219 | static void |
| 9220 | add_shndx_to_cu_tu_entry (unsigned int shndx) |
| 9221 | { |
| 9222 | if (shndx_pool_used >= shndx_pool_size) |
| 9223 | { |
| 9224 | error (_("Internal error: out of space in the shndx pool.\n")); |
| 9225 | return; |
| 9226 | } |
| 9227 | shndx_pool [shndx_pool_used++] = shndx; |
| 9228 | } |
| 9229 | |
| 9230 | static void |
| 9231 | end_cu_tu_entry (void) |
| 9232 | { |
| 9233 | if (shndx_pool_used >= shndx_pool_size) |
| 9234 | { |
| 9235 | error (_("Internal error: out of space in the shndx pool.\n")); |
| 9236 | return; |
| 9237 | } |
| 9238 | shndx_pool [shndx_pool_used++] = 0; |
| 9239 | } |
| 9240 | |
| 9241 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
| 9242 | |
| 9243 | static const char * |
| 9244 | get_DW_SECT_short_name (unsigned int dw_sect) |
| 9245 | { |
| 9246 | static char buf[16]; |
| 9247 | |
| 9248 | switch (dw_sect) |
| 9249 | { |
| 9250 | case DW_SECT_INFO: |
| 9251 | return "info"; |
| 9252 | case DW_SECT_TYPES: |
| 9253 | return "types"; |
| 9254 | case DW_SECT_ABBREV: |
| 9255 | return "abbrev"; |
| 9256 | case DW_SECT_LINE: |
| 9257 | return "line"; |
| 9258 | case DW_SECT_LOC: |
| 9259 | return "loc"; |
| 9260 | case DW_SECT_STR_OFFSETS: |
| 9261 | return "str_off"; |
| 9262 | case DW_SECT_MACINFO: |
| 9263 | return "macinfo"; |
| 9264 | case DW_SECT_MACRO: |
| 9265 | return "macro"; |
| 9266 | default: |
| 9267 | break; |
| 9268 | } |
| 9269 | |
| 9270 | snprintf (buf, sizeof (buf), "%d", dw_sect); |
| 9271 | return buf; |
| 9272 | } |
| 9273 | |
| 9274 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. |
| 9275 | These sections are extensions for Fission. |
| 9276 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ |
| 9277 | |
| 9278 | static int |
| 9279 | process_cu_tu_index (struct dwarf_section *section, int do_display) |
| 9280 | { |
| 9281 | unsigned char *phdr = section->start; |
| 9282 | unsigned char *limit = phdr + section->size; |
| 9283 | unsigned char *phash; |
| 9284 | unsigned char *pindex; |
| 9285 | unsigned char *ppool; |
| 9286 | unsigned int version; |
| 9287 | unsigned int ncols = 0; |
| 9288 | unsigned int nused; |
| 9289 | unsigned int nslots; |
| 9290 | unsigned int i; |
| 9291 | unsigned int j; |
| 9292 | dwarf_vma signature_high; |
| 9293 | dwarf_vma signature_low; |
| 9294 | char buf[64]; |
| 9295 | |
| 9296 | /* PR 17512: file: 002-168123-0.004. */ |
| 9297 | if (phdr == NULL) |
| 9298 | { |
| 9299 | warn (_("Section %s is empty\n"), section->name); |
| 9300 | return 0; |
| 9301 | } |
| 9302 | /* PR 17512: file: 002-376-0.004. */ |
| 9303 | if (section->size < 24) |
| 9304 | { |
| 9305 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
| 9306 | section->name); |
| 9307 | return 0; |
| 9308 | } |
| 9309 | |
| 9310 | SAFE_BYTE_GET (version, phdr, 4, limit); |
| 9311 | if (version >= 2) |
| 9312 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
| 9313 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); |
| 9314 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); |
| 9315 | |
| 9316 | phash = phdr + 16; |
| 9317 | pindex = phash + (size_t) nslots * 8; |
| 9318 | ppool = pindex + (size_t) nslots * 4; |
| 9319 | |
| 9320 | if (do_display) |
| 9321 | { |
| 9322 | introduce (section, FALSE); |
| 9323 | |
| 9324 | printf (_(" Version: %u\n"), version); |
| 9325 | if (version >= 2) |
| 9326 | printf (_(" Number of columns: %u\n"), ncols); |
| 9327 | printf (_(" Number of used entries: %u\n"), nused); |
| 9328 | printf (_(" Number of slots: %u\n\n"), nslots); |
| 9329 | } |
| 9330 | |
| 9331 | /* PR 17531: file: 45d69832. */ |
| 9332 | if ((size_t) nslots * 8 / 8 != nslots |
| 9333 | || phash < phdr || phash > limit |
| 9334 | || pindex < phash || pindex > limit |
| 9335 | || ppool < pindex || ppool > limit) |
| 9336 | { |
| 9337 | warn (ngettext ("Section %s is too small for %u slot\n", |
| 9338 | "Section %s is too small for %u slots\n", |
| 9339 | nslots), |
| 9340 | section->name, nslots); |
| 9341 | return 0; |
| 9342 | } |
| 9343 | |
| 9344 | if (version == 1) |
| 9345 | { |
| 9346 | if (!do_display) |
| 9347 | prealloc_cu_tu_list ((limit - ppool) / 4); |
| 9348 | for (i = 0; i < nslots; i++) |
| 9349 | { |
| 9350 | unsigned char *shndx_list; |
| 9351 | unsigned int shndx; |
| 9352 | |
| 9353 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
| 9354 | if (signature_high != 0 || signature_low != 0) |
| 9355 | { |
| 9356 | SAFE_BYTE_GET (j, pindex, 4, limit); |
| 9357 | shndx_list = ppool + j * 4; |
| 9358 | /* PR 17531: file: 705e010d. */ |
| 9359 | if (shndx_list < ppool) |
| 9360 | { |
| 9361 | warn (_("Section index pool located before start of section\n")); |
| 9362 | return 0; |
| 9363 | } |
| 9364 | |
| 9365 | if (do_display) |
| 9366 | printf (_(" [%3d] Signature: 0x%s Sections: "), |
| 9367 | i, dwarf_vmatoa64 (signature_high, signature_low, |
| 9368 | buf, sizeof (buf))); |
| 9369 | for (;;) |
| 9370 | { |
| 9371 | if (shndx_list >= limit) |
| 9372 | { |
| 9373 | warn (_("Section %s too small for shndx pool\n"), |
| 9374 | section->name); |
| 9375 | return 0; |
| 9376 | } |
| 9377 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
| 9378 | if (shndx == 0) |
| 9379 | break; |
| 9380 | if (do_display) |
| 9381 | printf (" %d", shndx); |
| 9382 | else |
| 9383 | add_shndx_to_cu_tu_entry (shndx); |
| 9384 | shndx_list += 4; |
| 9385 | } |
| 9386 | if (do_display) |
| 9387 | printf ("\n"); |
| 9388 | else |
| 9389 | end_cu_tu_entry (); |
| 9390 | } |
| 9391 | phash += 8; |
| 9392 | pindex += 4; |
| 9393 | } |
| 9394 | } |
| 9395 | else if (version == 2) |
| 9396 | { |
| 9397 | unsigned int val; |
| 9398 | unsigned int dw_sect; |
| 9399 | unsigned char *ph = phash; |
| 9400 | unsigned char *pi = pindex; |
| 9401 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
| 9402 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; |
| 9403 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; |
| 9404 | bfd_boolean is_tu_index; |
| 9405 | struct cu_tu_set *this_set = NULL; |
| 9406 | unsigned int row; |
| 9407 | unsigned char *prow; |
| 9408 | |
| 9409 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; |
| 9410 | |
| 9411 | /* PR 17531: file: 0dd159bf. |
| 9412 | Check for integer overflow (can occur when size_t is 32-bit) |
| 9413 | with overlarge ncols or nused values. */ |
| 9414 | if (ncols > 0 |
| 9415 | && ((size_t) ncols * 4 / 4 != ncols |
| 9416 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused |
| 9417 | || poffsets < ppool || poffsets > limit |
| 9418 | || psizes < poffsets || psizes > limit |
| 9419 | || pend < psizes || pend > limit)) |
| 9420 | { |
| 9421 | warn (_("Section %s too small for offset and size tables\n"), |
| 9422 | section->name); |
| 9423 | return 0; |
| 9424 | } |
| 9425 | |
| 9426 | if (do_display) |
| 9427 | { |
| 9428 | printf (_(" Offset table\n")); |
| 9429 | printf (" slot %-16s ", |
| 9430 | is_tu_index ? _("signature") : _("dwo_id")); |
| 9431 | } |
| 9432 | else |
| 9433 | { |
| 9434 | if (is_tu_index) |
| 9435 | { |
| 9436 | tu_count = nused; |
| 9437 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
| 9438 | this_set = tu_sets; |
| 9439 | } |
| 9440 | else |
| 9441 | { |
| 9442 | cu_count = nused; |
| 9443 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
| 9444 | this_set = cu_sets; |
| 9445 | } |
| 9446 | } |
| 9447 | |
| 9448 | if (do_display) |
| 9449 | { |
| 9450 | for (j = 0; j < ncols; j++) |
| 9451 | { |
| 9452 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
| 9453 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
| 9454 | } |
| 9455 | printf ("\n"); |
| 9456 | } |
| 9457 | |
| 9458 | for (i = 0; i < nslots; i++) |
| 9459 | { |
| 9460 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
| 9461 | |
| 9462 | SAFE_BYTE_GET (row, pi, 4, limit); |
| 9463 | if (row != 0) |
| 9464 | { |
| 9465 | /* PR 17531: file: a05f6ab3. */ |
| 9466 | if (row > nused) |
| 9467 | { |
| 9468 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), |
| 9469 | row, nused); |
| 9470 | return 0; |
| 9471 | } |
| 9472 | |
| 9473 | if (!do_display) |
| 9474 | { |
| 9475 | size_t num_copy = sizeof (uint64_t); |
| 9476 | |
| 9477 | /* PR 23064: Beware of buffer overflow. */ |
| 9478 | if (ph + num_copy < limit) |
| 9479 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
| 9480 | else |
| 9481 | { |
| 9482 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); |
| 9483 | return 0; |
| 9484 | } |
| 9485 | } |
| 9486 | |
| 9487 | prow = poffsets + (row - 1) * ncols * 4; |
| 9488 | /* PR 17531: file: b8ce60a8. */ |
| 9489 | if (prow < poffsets || prow > limit) |
| 9490 | { |
| 9491 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), |
| 9492 | row, ncols); |
| 9493 | return 0; |
| 9494 | } |
| 9495 | |
| 9496 | if (do_display) |
| 9497 | printf (_(" [%3d] 0x%s"), |
| 9498 | i, dwarf_vmatoa64 (signature_high, signature_low, |
| 9499 | buf, sizeof (buf))); |
| 9500 | for (j = 0; j < ncols; j++) |
| 9501 | { |
| 9502 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
| 9503 | if (do_display) |
| 9504 | printf (" %8d", val); |
| 9505 | else |
| 9506 | { |
| 9507 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
| 9508 | |
| 9509 | /* PR 17531: file: 10796eb3. */ |
| 9510 | if (dw_sect >= DW_SECT_MAX) |
| 9511 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
| 9512 | else |
| 9513 | this_set [row - 1].section_offsets [dw_sect] = val; |
| 9514 | } |
| 9515 | } |
| 9516 | |
| 9517 | if (do_display) |
| 9518 | printf ("\n"); |
| 9519 | } |
| 9520 | ph += 8; |
| 9521 | pi += 4; |
| 9522 | } |
| 9523 | |
| 9524 | ph = phash; |
| 9525 | pi = pindex; |
| 9526 | if (do_display) |
| 9527 | { |
| 9528 | printf ("\n"); |
| 9529 | printf (_(" Size table\n")); |
| 9530 | printf (" slot %-16s ", |
| 9531 | is_tu_index ? _("signature") : _("dwo_id")); |
| 9532 | } |
| 9533 | |
| 9534 | for (j = 0; j < ncols; j++) |
| 9535 | { |
| 9536 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
| 9537 | if (do_display) |
| 9538 | printf (" %8s", get_DW_SECT_short_name (val)); |
| 9539 | } |
| 9540 | |
| 9541 | if (do_display) |
| 9542 | printf ("\n"); |
| 9543 | |
| 9544 | for (i = 0; i < nslots; i++) |
| 9545 | { |
| 9546 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
| 9547 | |
| 9548 | SAFE_BYTE_GET (row, pi, 4, limit); |
| 9549 | if (row != 0) |
| 9550 | { |
| 9551 | prow = psizes + (row - 1) * ncols * 4; |
| 9552 | |
| 9553 | if (do_display) |
| 9554 | printf (_(" [%3d] 0x%s"), |
| 9555 | i, dwarf_vmatoa64 (signature_high, signature_low, |
| 9556 | buf, sizeof (buf))); |
| 9557 | |
| 9558 | for (j = 0; j < ncols; j++) |
| 9559 | { |
| 9560 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
| 9561 | if (do_display) |
| 9562 | printf (" %8d", val); |
| 9563 | else |
| 9564 | { |
| 9565 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
| 9566 | if (dw_sect >= DW_SECT_MAX) |
| 9567 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
| 9568 | else |
| 9569 | this_set [row - 1].section_sizes [dw_sect] = val; |
| 9570 | } |
| 9571 | } |
| 9572 | |
| 9573 | if (do_display) |
| 9574 | printf ("\n"); |
| 9575 | } |
| 9576 | |
| 9577 | ph += 8; |
| 9578 | pi += 4; |
| 9579 | } |
| 9580 | } |
| 9581 | else if (do_display) |
| 9582 | printf (_(" Unsupported version (%d)\n"), version); |
| 9583 | |
| 9584 | if (do_display) |
| 9585 | printf ("\n"); |
| 9586 | |
| 9587 | return 1; |
| 9588 | } |
| 9589 | |
| 9590 | /* Load the CU and TU indexes if present. This will build a list of |
| 9591 | section sets that we can use to associate a .debug_info.dwo section |
| 9592 | with its associated .debug_abbrev.dwo section in a .dwp file. */ |
| 9593 | |
| 9594 | static bfd_boolean |
| 9595 | load_cu_tu_indexes (void *file) |
| 9596 | { |
| 9597 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
| 9598 | |
| 9599 | /* If we have already loaded (or tried to load) the CU and TU indexes |
| 9600 | then do not bother to repeat the task. */ |
| 9601 | if (cu_tu_indexes_read == -1) |
| 9602 | { |
| 9603 | cu_tu_indexes_read = TRUE; |
| 9604 | |
| 9605 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
| 9606 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
| 9607 | cu_tu_indexes_read = FALSE; |
| 9608 | |
| 9609 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
| 9610 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
| 9611 | cu_tu_indexes_read = FALSE; |
| 9612 | } |
| 9613 | |
| 9614 | return (bfd_boolean) cu_tu_indexes_read; |
| 9615 | } |
| 9616 | |
| 9617 | /* Find the set of sections that includes section SHNDX. */ |
| 9618 | |
| 9619 | unsigned int * |
| 9620 | find_cu_tu_set (void *file, unsigned int shndx) |
| 9621 | { |
| 9622 | unsigned int i; |
| 9623 | |
| 9624 | if (! load_cu_tu_indexes (file)) |
| 9625 | return NULL; |
| 9626 | |
| 9627 | /* Find SHNDX in the shndx pool. */ |
| 9628 | for (i = 0; i < shndx_pool_used; i++) |
| 9629 | if (shndx_pool [i] == shndx) |
| 9630 | break; |
| 9631 | |
| 9632 | if (i >= shndx_pool_used) |
| 9633 | return NULL; |
| 9634 | |
| 9635 | /* Now backup to find the first entry in the set. */ |
| 9636 | while (i > 0 && shndx_pool [i - 1] != 0) |
| 9637 | i--; |
| 9638 | |
| 9639 | return shndx_pool + i; |
| 9640 | } |
| 9641 | |
| 9642 | /* Display a .debug_cu_index or .debug_tu_index section. */ |
| 9643 | |
| 9644 | static int |
| 9645 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
| 9646 | { |
| 9647 | return process_cu_tu_index (section, 1); |
| 9648 | } |
| 9649 | |
| 9650 | static int |
| 9651 | display_debug_not_supported (struct dwarf_section *section, |
| 9652 | void *file ATTRIBUTE_UNUSED) |
| 9653 | { |
| 9654 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), |
| 9655 | section->name); |
| 9656 | |
| 9657 | return 1; |
| 9658 | } |
| 9659 | |
| 9660 | /* Like malloc, but takes two parameters like calloc. |
| 9661 | Verifies that the first parameter is not too large. |
| 9662 | Note: does *not* initialise the allocated memory to zero. */ |
| 9663 | |
| 9664 | void * |
| 9665 | cmalloc (size_t nmemb, size_t size) |
| 9666 | { |
| 9667 | /* Check for overflow. */ |
| 9668 | if (nmemb >= ~(size_t) 0 / size) |
| 9669 | return NULL; |
| 9670 | |
| 9671 | return xmalloc (nmemb * size); |
| 9672 | } |
| 9673 | |
| 9674 | /* Like xmalloc, but takes two parameters like calloc. |
| 9675 | Verifies that the first parameter is not too large. |
| 9676 | Note: does *not* initialise the allocated memory to zero. */ |
| 9677 | |
| 9678 | void * |
| 9679 | xcmalloc (size_t nmemb, size_t size) |
| 9680 | { |
| 9681 | /* Check for overflow. */ |
| 9682 | if (nmemb >= ~(size_t) 0 / size) |
| 9683 | { |
| 9684 | fprintf (stderr, |
| 9685 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), |
| 9686 | (long) nmemb); |
| 9687 | xexit (1); |
| 9688 | } |
| 9689 | |
| 9690 | return xmalloc (nmemb * size); |
| 9691 | } |
| 9692 | |
| 9693 | /* Like xrealloc, but takes three parameters. |
| 9694 | Verifies that the second parameter is not too large. |
| 9695 | Note: does *not* initialise any new memory to zero. */ |
| 9696 | |
| 9697 | void * |
| 9698 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
| 9699 | { |
| 9700 | /* Check for overflow. */ |
| 9701 | if (nmemb >= ~(size_t) 0 / size) |
| 9702 | { |
| 9703 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
| 9704 | (long) nmemb); |
| 9705 | xexit (1); |
| 9706 | } |
| 9707 | |
| 9708 | return xrealloc (ptr, nmemb * size); |
| 9709 | } |
| 9710 | |
| 9711 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
| 9712 | |
| 9713 | void * |
| 9714 | xcalloc2 (size_t nmemb, size_t size) |
| 9715 | { |
| 9716 | /* Check for overflow. */ |
| 9717 | if (nmemb >= ~(size_t) 0 / size) |
| 9718 | { |
| 9719 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
| 9720 | (long) nmemb); |
| 9721 | xexit (1); |
| 9722 | } |
| 9723 | |
| 9724 | return xcalloc (nmemb, size); |
| 9725 | } |
| 9726 | |
| 9727 | static unsigned long |
| 9728 | calc_gnu_debuglink_crc32 (unsigned long crc, |
| 9729 | const unsigned char * buf, |
| 9730 | bfd_size_type len) |
| 9731 | { |
| 9732 | static const unsigned long crc32_table[256] = |
| 9733 | { |
| 9734 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, |
| 9735 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, |
| 9736 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, |
| 9737 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
| 9738 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, |
| 9739 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, |
| 9740 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, |
| 9741 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
| 9742 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, |
| 9743 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, |
| 9744 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, |
| 9745 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
| 9746 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, |
| 9747 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, |
| 9748 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, |
| 9749 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
| 9750 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, |
| 9751 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, |
| 9752 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, |
| 9753 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
| 9754 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, |
| 9755 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, |
| 9756 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, |
| 9757 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
| 9758 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, |
| 9759 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, |
| 9760 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, |
| 9761 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
| 9762 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, |
| 9763 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, |
| 9764 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, |
| 9765 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
| 9766 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, |
| 9767 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, |
| 9768 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, |
| 9769 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
| 9770 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, |
| 9771 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, |
| 9772 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, |
| 9773 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
| 9774 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, |
| 9775 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, |
| 9776 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, |
| 9777 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
| 9778 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, |
| 9779 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, |
| 9780 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, |
| 9781 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
| 9782 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, |
| 9783 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, |
| 9784 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, |
| 9785 | 0x2d02ef8d |
| 9786 | }; |
| 9787 | const unsigned char *end; |
| 9788 | |
| 9789 | crc = ~crc & 0xffffffff; |
| 9790 | for (end = buf + len; buf < end; ++ buf) |
| 9791 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); |
| 9792 | return ~crc & 0xffffffff; |
| 9793 | } |
| 9794 | |
| 9795 | typedef bfd_boolean (* check_func_type) (const char *, void *); |
| 9796 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); |
| 9797 | |
| 9798 | static bfd_boolean |
| 9799 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
| 9800 | { |
| 9801 | static unsigned char buffer [8 * 1024]; |
| 9802 | FILE * f; |
| 9803 | bfd_size_type count; |
| 9804 | unsigned long crc = 0; |
| 9805 | void * sep_data; |
| 9806 | |
| 9807 | sep_data = open_debug_file (pathname); |
| 9808 | if (sep_data == NULL) |
| 9809 | return FALSE; |
| 9810 | |
| 9811 | /* Yes - we are opening the file twice... */ |
| 9812 | f = fopen (pathname, "rb"); |
| 9813 | if (f == NULL) |
| 9814 | { |
| 9815 | /* Paranoia: This should never happen. */ |
| 9816 | close_debug_file (sep_data); |
| 9817 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); |
| 9818 | return FALSE; |
| 9819 | } |
| 9820 | |
| 9821 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) |
| 9822 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); |
| 9823 | |
| 9824 | fclose (f); |
| 9825 | |
| 9826 | if (crc != * (unsigned long *) crc_pointer) |
| 9827 | { |
| 9828 | close_debug_file (sep_data); |
| 9829 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), |
| 9830 | pathname); |
| 9831 | return FALSE; |
| 9832 | } |
| 9833 | |
| 9834 | return TRUE; |
| 9835 | } |
| 9836 | |
| 9837 | static const char * |
| 9838 | parse_gnu_debuglink (struct dwarf_section * section, void * data) |
| 9839 | { |
| 9840 | const char * name; |
| 9841 | unsigned int crc_offset; |
| 9842 | unsigned long * crc32 = (unsigned long *) data; |
| 9843 | |
| 9844 | /* The name is first. |
| 9845 | The CRC value is stored after the filename, aligned up to 4 bytes. */ |
| 9846 | name = (const char *) section->start; |
| 9847 | |
| 9848 | |
| 9849 | crc_offset = strnlen (name, section->size) + 1; |
| 9850 | crc_offset = (crc_offset + 3) & ~3; |
| 9851 | if (crc_offset + 4 > section->size) |
| 9852 | return NULL; |
| 9853 | |
| 9854 | * crc32 = byte_get (section->start + crc_offset, 4); |
| 9855 | return name; |
| 9856 | } |
| 9857 | |
| 9858 | static bfd_boolean |
| 9859 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
| 9860 | { |
| 9861 | void * sep_data = open_debug_file (filename); |
| 9862 | |
| 9863 | if (sep_data == NULL) |
| 9864 | return FALSE; |
| 9865 | |
| 9866 | /* FIXME: We should now extract the build-id in the separate file |
| 9867 | and check it... */ |
| 9868 | |
| 9869 | return TRUE; |
| 9870 | } |
| 9871 | |
| 9872 | typedef struct build_id_data |
| 9873 | { |
| 9874 | bfd_size_type len; |
| 9875 | const unsigned char * data; |
| 9876 | } Build_id_data; |
| 9877 | |
| 9878 | static const char * |
| 9879 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) |
| 9880 | { |
| 9881 | const char * name; |
| 9882 | bfd_size_type namelen; |
| 9883 | bfd_size_type id_len; |
| 9884 | Build_id_data * build_id_data; |
| 9885 | |
| 9886 | /* The name is first. |
| 9887 | The build-id follows immediately, with no padding, up to the section's end. */ |
| 9888 | |
| 9889 | name = (const char *) section->start; |
| 9890 | namelen = strnlen (name, section->size) + 1; |
| 9891 | if (namelen >= section->size) |
| 9892 | return NULL; |
| 9893 | |
| 9894 | id_len = section->size - namelen; |
| 9895 | if (id_len < 0x14) |
| 9896 | return NULL; |
| 9897 | |
| 9898 | build_id_data = calloc (1, sizeof * build_id_data); |
| 9899 | if (build_id_data == NULL) |
| 9900 | return NULL; |
| 9901 | |
| 9902 | build_id_data->len = id_len; |
| 9903 | build_id_data->data = section->start + namelen; |
| 9904 | |
| 9905 | * (Build_id_data **) data = build_id_data; |
| 9906 | |
| 9907 | return name; |
| 9908 | } |
| 9909 | |
| 9910 | static void |
| 9911 | add_separate_debug_file (const char * filename, void * handle) |
| 9912 | { |
| 9913 | separate_info * i = xmalloc (sizeof * i); |
| 9914 | |
| 9915 | i->filename = filename; |
| 9916 | i->handle = handle; |
| 9917 | i->next = first_separate_info; |
| 9918 | first_separate_info = i; |
| 9919 | } |
| 9920 | |
| 9921 | static void * |
| 9922 | load_separate_debug_info (const char * main_filename, |
| 9923 | struct dwarf_section * xlink, |
| 9924 | parse_func_type parse_func, |
| 9925 | check_func_type check_func, |
| 9926 | void * func_data) |
| 9927 | { |
| 9928 | const char * separate_filename; |
| 9929 | char * debug_filename; |
| 9930 | char * canon_dir; |
| 9931 | size_t canon_dirlen; |
| 9932 | size_t dirlen; |
| 9933 | |
| 9934 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
| 9935 | { |
| 9936 | warn (_("Corrupt debuglink section: %s\n"), |
| 9937 | xlink->name ? xlink->name : xlink->uncompressed_name); |
| 9938 | return FALSE; |
| 9939 | } |
| 9940 | |
| 9941 | /* Attempt to locate the separate file. |
| 9942 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ |
| 9943 | |
| 9944 | canon_dir = lrealpath (main_filename); |
| 9945 | |
| 9946 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
| 9947 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) |
| 9948 | break; |
| 9949 | canon_dir[canon_dirlen] = '\0'; |
| 9950 | |
| 9951 | #ifndef DEBUGDIR |
| 9952 | #define DEBUGDIR "/lib/debug" |
| 9953 | #endif |
| 9954 | #ifndef EXTRA_DEBUG_ROOT1 |
| 9955 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" |
| 9956 | #endif |
| 9957 | #ifndef EXTRA_DEBUG_ROOT2 |
| 9958 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" |
| 9959 | #endif |
| 9960 | |
| 9961 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
| 9962 | + canon_dirlen |
| 9963 | + strlen (".debug/") |
| 9964 | #ifdef EXTRA_DEBUG_ROOT1 |
| 9965 | + strlen (EXTRA_DEBUG_ROOT1) |
| 9966 | #endif |
| 9967 | #ifdef EXTRA_DEBUG_ROOT2 |
| 9968 | + strlen (EXTRA_DEBUG_ROOT2) |
| 9969 | #endif |
| 9970 | + strlen (separate_filename) |
| 9971 | + 1); |
| 9972 | if (debug_filename == NULL) |
| 9973 | { |
| 9974 | warn (_("Out of memory")); |
| 9975 | free (canon_dir); |
| 9976 | return NULL; |
| 9977 | } |
| 9978 | |
| 9979 | /* First try in the current directory. */ |
| 9980 | sprintf (debug_filename, "%s", separate_filename); |
| 9981 | if (check_func (debug_filename, func_data)) |
| 9982 | goto found; |
| 9983 | |
| 9984 | /* Then try in a subdirectory called .debug. */ |
| 9985 | sprintf (debug_filename, ".debug/%s", separate_filename); |
| 9986 | if (check_func (debug_filename, func_data)) |
| 9987 | goto found; |
| 9988 | |
| 9989 | /* Then try in the same directory as the original file. */ |
| 9990 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
| 9991 | if (check_func (debug_filename, func_data)) |
| 9992 | goto found; |
| 9993 | |
| 9994 | /* And the .debug subdirectory of that directory. */ |
| 9995 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
| 9996 | if (check_func (debug_filename, func_data)) |
| 9997 | goto found; |
| 9998 | |
| 9999 | #ifdef EXTRA_DEBUG_ROOT1 |
| 10000 | /* Try the first extra debug file root. */ |
| 10001 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
| 10002 | if (check_func (debug_filename, func_data)) |
| 10003 | goto found; |
| 10004 | |
| 10005 | /* Try the first extra debug file root. */ |
| 10006 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
| 10007 | if (check_func (debug_filename, func_data)) |
| 10008 | goto found; |
| 10009 | #endif |
| 10010 | |
| 10011 | #ifdef EXTRA_DEBUG_ROOT2 |
| 10012 | /* Try the second extra debug file root. */ |
| 10013 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
| 10014 | if (check_func (debug_filename, func_data)) |
| 10015 | goto found; |
| 10016 | #endif |
| 10017 | |
| 10018 | /* Then try in the global debug_filename directory. */ |
| 10019 | strcpy (debug_filename, DEBUGDIR); |
| 10020 | dirlen = strlen (DEBUGDIR) - 1; |
| 10021 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') |
| 10022 | strcat (debug_filename, "/"); |
| 10023 | strcat (debug_filename, (const char *) separate_filename); |
| 10024 | |
| 10025 | if (check_func (debug_filename, func_data)) |
| 10026 | goto found; |
| 10027 | |
| 10028 | /* Failed to find the file. */ |
| 10029 | warn (_("could not find separate debug file '%s'\n"), separate_filename); |
| 10030 | warn (_("tried: %s\n"), debug_filename); |
| 10031 | |
| 10032 | #ifdef EXTRA_DEBUG_ROOT2 |
| 10033 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
| 10034 | warn (_("tried: %s\n"), debug_filename); |
| 10035 | #endif |
| 10036 | |
| 10037 | #ifdef EXTRA_DEBUG_ROOT1 |
| 10038 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
| 10039 | warn (_("tried: %s\n"), debug_filename); |
| 10040 | |
| 10041 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
| 10042 | warn (_("tried: %s\n"), debug_filename); |
| 10043 | #endif |
| 10044 | |
| 10045 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
| 10046 | warn (_("tried: %s\n"), debug_filename); |
| 10047 | |
| 10048 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
| 10049 | warn (_("tried: %s\n"), debug_filename); |
| 10050 | |
| 10051 | sprintf (debug_filename, ".debug/%s", separate_filename); |
| 10052 | warn (_("tried: %s\n"), debug_filename); |
| 10053 | |
| 10054 | sprintf (debug_filename, "%s", separate_filename); |
| 10055 | warn (_("tried: %s\n"), debug_filename); |
| 10056 | |
| 10057 | free (canon_dir); |
| 10058 | free (debug_filename); |
| 10059 | return NULL; |
| 10060 | |
| 10061 | found: |
| 10062 | free (canon_dir); |
| 10063 | |
| 10064 | void * debug_handle; |
| 10065 | |
| 10066 | /* Now open the file.... */ |
| 10067 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
| 10068 | { |
| 10069 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
| 10070 | free (debug_filename); |
| 10071 | return FALSE; |
| 10072 | } |
| 10073 | |
| 10074 | /* FIXME: We do not check to see if there are any other separate debug info |
| 10075 | files that would also match. */ |
| 10076 | |
| 10077 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
| 10078 | add_separate_debug_file (debug_filename, debug_handle); |
| 10079 | |
| 10080 | /* Do not free debug_filename - it might be referenced inside |
| 10081 | the structure returned by open_debug_file(). */ |
| 10082 | return debug_handle; |
| 10083 | } |
| 10084 | |
| 10085 | /* Attempt to load a separate dwarf object file. */ |
| 10086 | |
| 10087 | static void * |
| 10088 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
| 10089 | { |
| 10090 | char * separate_filename; |
| 10091 | void * separate_handle; |
| 10092 | |
| 10093 | /* FIXME: Skip adding / if dwo_dir ends in /. */ |
| 10094 | separate_filename = concat (dir, "/", name, NULL); |
| 10095 | if (separate_filename == NULL) |
| 10096 | { |
| 10097 | warn (_("Out of memory allocating dwo filename\n")); |
| 10098 | return NULL; |
| 10099 | } |
| 10100 | |
| 10101 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
| 10102 | { |
| 10103 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
| 10104 | free (separate_filename); |
| 10105 | return NULL; |
| 10106 | } |
| 10107 | |
| 10108 | /* FIXME: We should check the dwo_id. */ |
| 10109 | |
| 10110 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
| 10111 | add_separate_debug_file (separate_filename, separate_handle); |
| 10112 | /* Note - separate_filename will be freed in free_debug_memory(). */ |
| 10113 | return separate_handle; |
| 10114 | } |
| 10115 | |
| 10116 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
| 10117 | Returns TRUE if any were found, FALSE otherwise. |
| 10118 | If TRUE is returned then the linked list starting at first_separate_info |
| 10119 | will be populated with open file handles. */ |
| 10120 | |
| 10121 | bfd_boolean |
| 10122 | load_separate_debug_files (void * file, const char * filename) |
| 10123 | { |
| 10124 | /* Skip this operation if we are not interested in debug links. */ |
| 10125 | if (! do_follow_links && ! do_debug_links) |
| 10126 | return FALSE; |
| 10127 | |
| 10128 | /* See if there are any dwo links. */ |
| 10129 | if (load_debug_section (str, file) |
| 10130 | && load_debug_section (abbrev, file) |
| 10131 | && load_debug_section (info, file)) |
| 10132 | { |
| 10133 | free_dwo_info (); |
| 10134 | |
| 10135 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) |
| 10136 | { |
| 10137 | bfd_boolean introduced = FALSE; |
| 10138 | dwo_info * dwinfo; |
| 10139 | const char * dir = NULL; |
| 10140 | const char * id = NULL; |
| 10141 | |
| 10142 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) |
| 10143 | { |
| 10144 | switch (dwinfo->type) |
| 10145 | { |
| 10146 | case DWO_NAME: |
| 10147 | if (do_debug_links) |
| 10148 | { |
| 10149 | if (! introduced) |
| 10150 | { |
| 10151 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), |
| 10152 | debug_displays [info].section.uncompressed_name); |
| 10153 | introduced = TRUE; |
| 10154 | } |
| 10155 | |
| 10156 | printf (_(" Name: %s\n"), dwinfo->value); |
| 10157 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
| 10158 | if (id != NULL) |
| 10159 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); |
| 10160 | else |
| 10161 | printf (_(" ID: <unknown>\n")); |
| 10162 | printf ("\n\n"); |
| 10163 | } |
| 10164 | |
| 10165 | if (do_follow_links) |
| 10166 | load_dwo_file (filename, dwinfo->value, dir, id); |
| 10167 | break; |
| 10168 | |
| 10169 | case DWO_DIR: |
| 10170 | dir = dwinfo->value; |
| 10171 | break; |
| 10172 | |
| 10173 | case DWO_ID: |
| 10174 | id = dwinfo->value; |
| 10175 | break; |
| 10176 | |
| 10177 | default: |
| 10178 | error (_("Unexpected DWO INFO type")); |
| 10179 | break; |
| 10180 | } |
| 10181 | } |
| 10182 | } |
| 10183 | } |
| 10184 | |
| 10185 | if (! do_follow_links) |
| 10186 | /* The other debug links will be displayed by display_debug_links() |
| 10187 | so we do not need to do any further processing here. */ |
| 10188 | return FALSE; |
| 10189 | |
| 10190 | /* FIXME: We do not check for the presence of both link sections in the same file. */ |
| 10191 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ |
| 10192 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
| 10193 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
| 10194 | |
| 10195 | if (load_debug_section (gnu_debugaltlink, file)) |
| 10196 | { |
| 10197 | Build_id_data * build_id_data; |
| 10198 | |
| 10199 | load_separate_debug_info (filename, |
| 10200 | & debug_displays[gnu_debugaltlink].section, |
| 10201 | parse_gnu_debugaltlink, |
| 10202 | check_gnu_debugaltlink, |
| 10203 | & build_id_data); |
| 10204 | } |
| 10205 | |
| 10206 | if (load_debug_section (gnu_debuglink, file)) |
| 10207 | { |
| 10208 | unsigned long crc32; |
| 10209 | |
| 10210 | load_separate_debug_info (filename, |
| 10211 | & debug_displays[gnu_debuglink].section, |
| 10212 | parse_gnu_debuglink, |
| 10213 | check_gnu_debuglink, |
| 10214 | & crc32); |
| 10215 | } |
| 10216 | |
| 10217 | if (first_separate_info != NULL) |
| 10218 | return TRUE; |
| 10219 | |
| 10220 | do_follow_links = 0; |
| 10221 | return FALSE; |
| 10222 | } |
| 10223 | |
| 10224 | void |
| 10225 | free_debug_memory (void) |
| 10226 | { |
| 10227 | unsigned int i; |
| 10228 | |
| 10229 | free_abbrevs (); |
| 10230 | |
| 10231 | for (i = 0; i < max; i++) |
| 10232 | free_debug_section ((enum dwarf_section_display_enum) i); |
| 10233 | |
| 10234 | if (debug_information != NULL) |
| 10235 | { |
| 10236 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
| 10237 | { |
| 10238 | for (i = 0; i < num_debug_info_entries; i++) |
| 10239 | { |
| 10240 | if (!debug_information [i].max_loc_offsets) |
| 10241 | { |
| 10242 | free (debug_information [i].loc_offsets); |
| 10243 | free (debug_information [i].have_frame_base); |
| 10244 | } |
| 10245 | if (!debug_information [i].max_range_lists) |
| 10246 | free (debug_information [i].range_lists); |
| 10247 | } |
| 10248 | } |
| 10249 | free (debug_information); |
| 10250 | debug_information = NULL; |
| 10251 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
| 10252 | } |
| 10253 | |
| 10254 | separate_info * d; |
| 10255 | separate_info * next; |
| 10256 | |
| 10257 | for (d = first_separate_info; d != NULL; d = next) |
| 10258 | { |
| 10259 | close_debug_file (d->handle); |
| 10260 | free ((void *) d->filename); |
| 10261 | next = d->next; |
| 10262 | free ((void *) d); |
| 10263 | } |
| 10264 | first_separate_info = NULL; |
| 10265 | |
| 10266 | free_dwo_info (); |
| 10267 | } |
| 10268 | |
| 10269 | void |
| 10270 | dwarf_select_sections_by_names (const char *names) |
| 10271 | { |
| 10272 | typedef struct |
| 10273 | { |
| 10274 | const char * option; |
| 10275 | int * variable; |
| 10276 | int val; |
| 10277 | } |
| 10278 | debug_dump_long_opts; |
| 10279 | |
| 10280 | static const debug_dump_long_opts opts_table [] = |
| 10281 | { |
| 10282 | /* Please keep this table alpha- sorted. */ |
| 10283 | { "Ranges", & do_debug_ranges, 1 }, |
| 10284 | { "abbrev", & do_debug_abbrevs, 1 }, |
| 10285 | { "addr", & do_debug_addr, 1 }, |
| 10286 | { "aranges", & do_debug_aranges, 1 }, |
| 10287 | { "cu_index", & do_debug_cu_index, 1 }, |
| 10288 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, |
| 10289 | { "follow-links", & do_follow_links, 1 }, |
| 10290 | { "frames", & do_debug_frames, 1 }, |
| 10291 | { "frames-interp", & do_debug_frames_interp, 1 }, |
| 10292 | /* The special .gdb_index section. */ |
| 10293 | { "gdb_index", & do_gdb_index, 1 }, |
| 10294 | { "info", & do_debug_info, 1 }, |
| 10295 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ |
| 10296 | { "links", & do_debug_links, 1 }, |
| 10297 | { "loc", & do_debug_loc, 1 }, |
| 10298 | { "macro", & do_debug_macinfo, 1 }, |
| 10299 | { "pubnames", & do_debug_pubnames, 1 }, |
| 10300 | { "pubtypes", & do_debug_pubtypes, 1 }, |
| 10301 | /* This entry is for compatibility |
| 10302 | with earlier versions of readelf. */ |
| 10303 | { "ranges", & do_debug_aranges, 1 }, |
| 10304 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
| 10305 | { "str", & do_debug_str, 1 }, |
| 10306 | /* These trace_* sections are used by Itanium VMS. */ |
| 10307 | { "trace_abbrev", & do_trace_abbrevs, 1 }, |
| 10308 | { "trace_aranges", & do_trace_aranges, 1 }, |
| 10309 | { "trace_info", & do_trace_info, 1 }, |
| 10310 | { NULL, NULL, 0 } |
| 10311 | }; |
| 10312 | |
| 10313 | const char *p; |
| 10314 | |
| 10315 | p = names; |
| 10316 | while (*p) |
| 10317 | { |
| 10318 | const debug_dump_long_opts * entry; |
| 10319 | |
| 10320 | for (entry = opts_table; entry->option; entry++) |
| 10321 | { |
| 10322 | size_t len = strlen (entry->option); |
| 10323 | |
| 10324 | if (strncmp (p, entry->option, len) == 0 |
| 10325 | && (p[len] == ',' || p[len] == '\0')) |
| 10326 | { |
| 10327 | * entry->variable |= entry->val; |
| 10328 | |
| 10329 | /* The --debug-dump=frames-interp option also |
| 10330 | enables the --debug-dump=frames option. */ |
| 10331 | if (do_debug_frames_interp) |
| 10332 | do_debug_frames = 1; |
| 10333 | |
| 10334 | p += len; |
| 10335 | break; |
| 10336 | } |
| 10337 | } |
| 10338 | |
| 10339 | if (entry->option == NULL) |
| 10340 | { |
| 10341 | warn (_("Unrecognized debug option '%s'\n"), p); |
| 10342 | p = strchr (p, ','); |
| 10343 | if (p == NULL) |
| 10344 | break; |
| 10345 | } |
| 10346 | |
| 10347 | if (*p == ',') |
| 10348 | p++; |
| 10349 | } |
| 10350 | } |
| 10351 | |
| 10352 | void |
| 10353 | dwarf_select_sections_by_letters (const char *letters) |
| 10354 | { |
| 10355 | unsigned int lindex = 0; |
| 10356 | |
| 10357 | while (letters[lindex]) |
| 10358 | switch (letters[lindex++]) |
| 10359 | { |
| 10360 | case 'A': do_debug_addr = 1; break; |
| 10361 | case 'a': do_debug_abbrevs = 1; break; |
| 10362 | case 'c': do_debug_cu_index = 1; break; |
| 10363 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ |
| 10364 | case 'f': do_debug_frames = 1; break; |
| 10365 | case 'g': do_gdb_index = 1; break; |
| 10366 | case 'i': do_debug_info = 1; break; |
| 10367 | case 'K': do_follow_links = 1; break; |
| 10368 | case 'k': do_debug_links = 1; break; |
| 10369 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; |
| 10370 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; |
| 10371 | case 'm': do_debug_macinfo = 1; break; |
| 10372 | case 'o': do_debug_loc = 1; break; |
| 10373 | case 'p': do_debug_pubnames = 1; break; |
| 10374 | case 'R': do_debug_ranges = 1; break; |
| 10375 | case 'r': do_debug_aranges = 1; break; |
| 10376 | case 's': do_debug_str = 1; break; |
| 10377 | case 'T': do_trace_aranges = 1; break; |
| 10378 | case 't': do_debug_pubtypes = 1; break; |
| 10379 | case 'U': do_trace_info = 1; break; |
| 10380 | case 'u': do_trace_abbrevs = 1; break; |
| 10381 | |
| 10382 | default: |
| 10383 | warn (_("Unrecognized debug option '%s'\n"), letters); |
| 10384 | break; |
| 10385 | } |
| 10386 | } |
| 10387 | |
| 10388 | void |
| 10389 | dwarf_select_sections_all (void) |
| 10390 | { |
| 10391 | do_debug_info = 1; |
| 10392 | do_debug_abbrevs = 1; |
| 10393 | do_debug_lines = FLAG_DEBUG_LINES_RAW; |
| 10394 | do_debug_pubnames = 1; |
| 10395 | do_debug_pubtypes = 1; |
| 10396 | do_debug_aranges = 1; |
| 10397 | do_debug_ranges = 1; |
| 10398 | do_debug_frames = 1; |
| 10399 | do_debug_macinfo = 1; |
| 10400 | do_debug_str = 1; |
| 10401 | do_debug_loc = 1; |
| 10402 | do_gdb_index = 1; |
| 10403 | do_trace_info = 1; |
| 10404 | do_trace_abbrevs = 1; |
| 10405 | do_trace_aranges = 1; |
| 10406 | do_debug_addr = 1; |
| 10407 | do_debug_cu_index = 1; |
| 10408 | do_follow_links = 1; |
| 10409 | do_debug_links = 1; |
| 10410 | } |
| 10411 | |
| 10412 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
| 10413 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL |
| 10414 | |
| 10415 | /* N.B. The order here must match the order in section_display_enum. */ |
| 10416 | |
| 10417 | struct dwarf_section_display debug_displays[] = |
| 10418 | { |
| 10419 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
| 10420 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, |
| 10421 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, |
| 10422 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, |
| 10423 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, |
| 10424 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, |
| 10425 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, |
| 10426 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, |
| 10427 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, |
| 10428 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, |
| 10429 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, |
| 10430 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, |
| 10431 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, |
| 10432 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, |
| 10433 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, |
| 10434 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, |
| 10435 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, |
| 10436 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, |
| 10437 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, |
| 10438 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, |
| 10439 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, |
| 10440 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, |
| 10441 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, |
| 10442 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, |
| 10443 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, |
| 10444 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, |
| 10445 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, |
| 10446 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, |
| 10447 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
| 10448 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, |
| 10449 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, |
| 10450 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, |
| 10451 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, |
| 10452 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, |
| 10453 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, |
| 10454 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, |
| 10455 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, |
| 10456 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
| 10457 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, |
| 10458 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, |
| 10459 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, |
| 10460 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, |
| 10461 | /* Separate debug info files can containt their own .debug_str section, |
| 10462 | and this might be in *addition* to a .debug_str section already present |
| 10463 | in the main file. Hence we need to have two entries for .debug_str. */ |
| 10464 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, |
| 10465 | }; |
| 10466 | |
| 10467 | /* A static assertion. */ |
| 10468 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |