| 1 |
/* |
| 2 |
Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. |
| 3 |
Portions Copyright (C) 2007-2020 David Anderson. All Rights Reserved. |
| 4 |
Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it |
| 7 |
and/or modify it under the terms of version 2.1 of the |
| 8 |
GNU Lesser General Public License as published by the Free |
| 9 |
Software Foundation. |
| 10 |
|
| 11 |
This program is distributed in the hope that it would be |
| 12 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 13 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
PURPOSE. |
| 15 |
|
| 16 |
Further, this software is distributed without any warranty |
| 17 |
that it is free of the rightful claim of any third person |
| 18 |
regarding infringement or the like. Any license provided |
| 19 |
herein, whether implied or otherwise, applies only to this |
| 20 |
software file. Patent licenses, if any, provided herein |
| 21 |
do not apply to combinations of this program with other |
| 22 |
software, or any other product whatsoever. |
| 23 |
|
| 24 |
You should have received a copy of the GNU Lesser General |
| 25 |
Public License along with this program; if not, write the |
| 26 |
Free Software Foundation, Inc., 51 Franklin Street - Fifth |
| 27 |
Floor, Boston MA 02110-1301, USA. |
| 28 |
|
| 29 |
*/ |
| 30 |
|
| 31 |
/* This implements _dwarf_get_fde_list_internal() |
| 32 |
and related helper functions for reading cie/fde data. */ |
| 33 |
|
| 34 |
#include <config.h> |
| 35 |
|
| 36 |
#include <stdlib.h> /* qsort() */ |
| 37 |
#include <stdio.h> /* printf() */ |
| 38 |
#include <string.h> /* memcpy() memset() strcmp() |
| 39 |
strncmp() strlen() */ |
| 40 |
|
| 41 |
#if defined(_WIN32) && defined(HAVE_STDAFX_H) |
| 42 |
#include "stdafx.h" |
| 43 |
#endif /* HAVE_STDAFX_H */ |
| 44 |
|
| 45 |
#ifdef HAVE_STDINT_H |
| 46 |
#include <stdint.h> /* uintptr_t */ |
| 47 |
#endif /* HAVE_STDINT_H */ |
| 48 |
|
| 49 |
#include "dwarf.h" |
| 50 |
#include "libdwarf.h" |
| 51 |
#include "libdwarf_private.h" |
| 52 |
#include "dwarf_base_types.h" |
| 53 |
#include "dwarf_opaque.h" |
| 54 |
#include "dwarf_alloc.h" |
| 55 |
#include "dwarf_error.h" |
| 56 |
#include "dwarf_util.h" |
| 57 |
#include "dwarf_frame.h" |
| 58 |
#include "dwarf_arange.h" /* using Arange as a way to build a list */ |
| 59 |
#include "dwarf_string.h" |
| 60 |
|
| 61 |
/* For a little information about .eh_frame see |
| 62 |
https://stackoverflow.com/questions/14091231/ |
| 63 |
what-do-the-eh-frame-and-eh-frame-hdr-sections-store-exactly |
| 64 |
http://refspecs.linuxfoundation.org/LSB_3.0.0/ |
| 65 |
LSB-Core-generic/LSB-Core-generic/ehframechpt.html |
| 66 |
The above give information about fields and sizes but |
| 67 |
very very little about content. |
| 68 |
|
| 69 |
.eh_frame_hdr contains data for C++ unwinding. Namely |
| 70 |
tables for fast access into .eh_frame. |
| 71 |
*/ |
| 72 |
|
| 73 |
#if 0 /* dump_bytes FOR DEBUGGING */ |
| 74 |
/* For debugging only. */ |
| 75 |
static void |
| 76 |
dump_bytes(const char *msg,Dwarf_Small * start, long len) |
| 77 |
{ |
| 78 |
Dwarf_Small *end = start + len; |
| 79 |
Dwarf_Small *cur = start; |
| 80 |
printf("%s (0x%lx) ",msg,(unsigned long)start); |
| 81 |
for (; cur < end; cur++) { |
| 82 |
printf("%02x", *cur); |
| 83 |
} |
| 84 |
printf("\n"); |
| 85 |
} |
| 86 |
|
| 87 |
#endif |
| 88 |
|
| 89 |
static int _dwarf_find_existing_cie_ptr(Dwarf_Small * cie_ptr, |
| 90 |
Dwarf_Cie cur_cie_ptr, |
| 91 |
Dwarf_Cie * cie_ptr_to_use_out, |
| 92 |
Dwarf_Cie head_cie_ptr); |
| 93 |
static void _dwarf_dealloc_fde_cie_list_internal( |
| 94 |
Dwarf_Fde head_fde_ptr, |
| 95 |
Dwarf_Cie head_cie_ptr); |
| 96 |
static int _dwarf_create_cie_from_start(Dwarf_Debug dbg, |
| 97 |
Dwarf_Small * cie_ptr_val, |
| 98 |
Dwarf_Small * section_ptr, |
| 99 |
Dwarf_Unsigned section_index, |
| 100 |
Dwarf_Unsigned section_length, |
| 101 |
Dwarf_Small * section_ptr_end, |
| 102 |
Dwarf_Unsigned cie_id_value, |
| 103 |
Dwarf_Unsigned cie_count, |
| 104 |
int use_gnu_cie_calc, |
| 105 |
Dwarf_Cie * cie_ptr_to_use_out, |
| 106 |
Dwarf_Error * error); |
| 107 |
|
| 108 |
static int _dwarf_get_gcc_eh_augmentation(Dwarf_Debug dbg, |
| 109 |
Dwarf_Small * frame_ptr, |
| 110 |
Dwarf_Unsigned *size_of_augmentation_data, |
| 111 |
enum Dwarf_augmentation_type augtype, |
| 112 |
Dwarf_Small * section_end_pointer, |
| 113 |
char *augmentation, |
| 114 |
Dwarf_Error *error); |
| 115 |
|
| 116 |
static int |
| 117 |
_dwarf_gnu_aug_encodings(Dwarf_Debug dbg, char *augmentation, |
| 118 |
Dwarf_Small * aug_data, Dwarf_Unsigned aug_data_len, |
| 119 |
Dwarf_Half address_size, |
| 120 |
unsigned char *pers_hand_enc_out, |
| 121 |
unsigned char *lsda_enc_out, |
| 122 |
unsigned char *fde_begin_enc_out, |
| 123 |
Dwarf_Addr * gnu_pers_addr_out, |
| 124 |
Dwarf_Error *error); |
| 125 |
|
| 126 |
static int _dwarf_read_encoded_ptr(Dwarf_Debug dbg, |
| 127 |
Dwarf_Small * section_pointer, |
| 128 |
Dwarf_Small * input_field, |
| 129 |
int gnu_encoding, |
| 130 |
Dwarf_Small * section_ptr_end, |
| 131 |
Dwarf_Half address_size, |
| 132 |
Dwarf_Unsigned * addr, |
| 133 |
Dwarf_Small ** input_field_out, |
| 134 |
Dwarf_Error *error); |
| 135 |
|
| 136 |
/* Called by qsort to compare FDE entries. |
| 137 |
Consumer code expects the array of FDE pointers to be |
| 138 |
in address order. |
| 139 |
*/ |
| 140 |
static int |
| 141 |
qsort_compare(const void *elem1, const void *elem2) |
| 142 |
{ |
| 143 |
const Dwarf_Fde fde1 = *(const Dwarf_Fde *) elem1; |
| 144 |
const Dwarf_Fde fde2 = *(const Dwarf_Fde *) elem2; |
| 145 |
Dwarf_Addr addr1 = fde1->fd_initial_location; |
| 146 |
Dwarf_Addr addr2 = fde2->fd_initial_location; |
| 147 |
|
| 148 |
if (addr1 < addr2) { |
| 149 |
return -1; |
| 150 |
} else if (addr1 > addr2) { |
| 151 |
return 1; |
| 152 |
} |
| 153 |
return 0; |
| 154 |
} |
| 155 |
|
| 156 |
/* Adds 'newone' to the end of the list starting at 'head' |
| 157 |
and makes the new one current. */ |
| 158 |
static void |
| 159 |
chain_up_fde(Dwarf_Fde newone, Dwarf_Fde * head, Dwarf_Fde * cur) |
| 160 |
{ |
| 161 |
if (*head == NULL) |
| 162 |
*head = newone; |
| 163 |
else { |
| 164 |
(*cur)->fd_next = newone; |
| 165 |
} |
| 166 |
*cur = newone; |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
/* Adds 'newone' to the end of the list starting at 'head' |
| 171 |
and makes the new one current. */ |
| 172 |
static void |
| 173 |
chain_up_cie(Dwarf_Cie newone, Dwarf_Cie * head, Dwarf_Cie * cur) |
| 174 |
{ |
| 175 |
if (*head == NULL) { |
| 176 |
*head = newone; |
| 177 |
} else { |
| 178 |
(*cur)->ci_next = newone; |
| 179 |
} |
| 180 |
*cur = newone; |
| 181 |
} |
| 182 |
|
| 183 |
/* The size of the length field plus the |
| 184 |
value of length must be an integral |
| 185 |
multiple of the address size. Dwarf4 standard. |
| 186 |
|
| 187 |
A constant that gives the number of bytes of the CIE |
| 188 |
structure, not including the length field itself |
| 189 |
(where length mod <size of an address> == 0) |
| 190 |
(see Section 7.2.2). Dwarf3 standard. |
| 191 |
|
| 192 |
A uword constant that gives the number of bytes of |
| 193 |
the CIE structure, not including the |
| 194 |
length field, itself (length mod <addressing unit size> == 0). |
| 195 |
Dwarf2 standard.*/ |
| 196 |
static void |
| 197 |
validate_length(Dwarf_Debug dbg, |
| 198 |
Dwarf_Cie cieptr, Dwarf_Unsigned length, |
| 199 |
Dwarf_Unsigned length_size, |
| 200 |
Dwarf_Unsigned extension_size, |
| 201 |
Dwarf_Small * section_ptr, |
| 202 |
Dwarf_Small * ciefde_start, |
| 203 |
const char * cieorfde) |
| 204 |
{ |
| 205 |
Dwarf_Unsigned address_size = 0; |
| 206 |
Dwarf_Unsigned length_field_summed = length_size + extension_size; |
| 207 |
Dwarf_Unsigned total_len = length + length_field_summed; |
| 208 |
Dwarf_Unsigned mod = 0; |
| 209 |
|
| 210 |
if (cieptr) { |
| 211 |
address_size = cieptr->ci_address_size; |
| 212 |
} else { |
| 213 |
address_size = dbg->de_pointer_size; |
| 214 |
} |
| 215 |
mod = total_len % address_size; |
| 216 |
if (mod != 0) { |
| 217 |
dwarfstring harm; |
| 218 |
Dwarf_Unsigned sectionoffset = ciefde_start - section_ptr; |
| 219 |
|
| 220 |
dwarfstring_constructor(&harm); |
| 221 |
if (!cieorfde || (strlen(cieorfde) > 3)) { |
| 222 |
/* Coding error or memory corruption? */ |
| 223 |
cieorfde = "ERROR!"; |
| 224 |
} |
| 225 |
dwarfstring_append_printf_u(&harm, |
| 226 |
"DW_DLE_DEBUG_FRAME_LENGTH_NOT_MULTIPLE" |
| 227 |
" len=0x%" DW_PR_XZEROS DW_PR_DUx, |
| 228 |
length); |
| 229 |
dwarfstring_append_printf_u(&harm, |
| 230 |
", len size=0x%" DW_PR_XZEROS DW_PR_DUx, |
| 231 |
length_size); |
| 232 |
dwarfstring_append_printf_u(&harm, |
| 233 |
", extn size=0x%" DW_PR_XZEROS DW_PR_DUx, |
| 234 |
extension_size); |
| 235 |
dwarfstring_append_printf_u(&harm, |
| 236 |
", totl length=0x%" DW_PR_XZEROS DW_PR_DUx, |
| 237 |
total_len); |
| 238 |
dwarfstring_append_printf_u(&harm, |
| 239 |
", addr size=0x%" DW_PR_XZEROS DW_PR_DUx, |
| 240 |
address_size); |
| 241 |
dwarfstring_append_printf_u(&harm, |
| 242 |
", mod=0x%" DW_PR_XZEROS DW_PR_DUx " must be zero", |
| 243 |
mod); |
| 244 |
dwarfstring_append_printf_s(&harm, |
| 245 |
" in %s",(char *)cieorfde); |
| 246 |
dwarfstring_append_printf_u(&harm, |
| 247 |
", offset 0x%" DW_PR_XZEROS DW_PR_DUx ".", |
| 248 |
sectionoffset); |
| 249 |
dwarf_insert_harmless_error(dbg, |
| 250 |
dwarfstring_string(&harm)); |
| 251 |
dwarfstring_destructor(&harm); |
| 252 |
} |
| 253 |
return; |
| 254 |
} |
| 255 |
|
| 256 |
#if 0 /* print_prefix() FOR DEBUGGING */ |
| 257 |
/* For debugging only. */ |
| 258 |
static void |
| 259 |
print_prefix(struct cie_fde_prefix_s *prefix, int line) |
| 260 |
{ |
| 261 |
printf("prefix-print, prefix at 0x%lx, line %d\n", |
| 262 |
(unsigned long) prefix, line); |
| 263 |
printf(" start addr 0x%lx after prefix 0x%lx\n", |
| 264 |
(unsigned long) prefix->cf_start_addr, |
| 265 |
(unsigned long) prefix->cf_addr_after_prefix); |
| 266 |
printf(" length 0x%" DW_PR_DUx ", len size %d ext size %d\n", |
| 267 |
(Dwarf_Unsigned) prefix->cf_length, |
| 268 |
prefix->cf_local_length_size, |
| 269 |
prefix->cf_local_extension_size); |
| 270 |
printf(" cie_id 0x%" DW_PR_DUx " cie_id cie_id_addr 0x%lx\n", |
| 271 |
(Dwarf_Unsigned) prefix->cf_cie_id, |
| 272 |
(long) prefix->cf_cie_id_addr); |
| 273 |
printf |
| 274 |
(" sec ptr 0x%lx sec index %" DW_PR_DSd |
| 275 |
" sec len 0x%" DW_PR_DUx " sec past end 0x%lx\n", |
| 276 |
(unsigned long) prefix->cf_section_ptr, |
| 277 |
(Dwarf_Signed) prefix->cf_section_index, |
| 278 |
(Dwarf_Unsigned) prefix->cf_section_length, |
| 279 |
(unsigned long) prefix->cf_section_ptr + |
| 280 |
(unsigned long)prefix->cf_section_length); |
| 281 |
} |
| 282 |
#endif |
| 283 |
|
| 284 |
/* Make the 'cieptr' consistent across .debug_frame and .eh_frame. |
| 285 |
Calculate a pointer into section bytes given a cie_id in |
| 286 |
an FDE header. |
| 287 |
|
| 288 |
In .debug_frame, the CIE_pointer is an offset in .debug_frame. |
| 289 |
|
| 290 |
In .eh_frame, the CIE Pointer is, when |
| 291 |
cie_id_value subtracted from the |
| 292 |
cie_id_addr, the address in memory of |
| 293 |
a CIE length field. |
| 294 |
Since cie_id_addr is the address of an FDE CIE_Pointer |
| 295 |
field, cie_id_value for .eh_frame |
| 296 |
has to account for the length-prefix. |
| 297 |
so that the returned cieptr really points to |
| 298 |
a CIE length field. Whew! |
| 299 |
Available documentation on this is just a bit |
| 300 |
ambiguous, but this calculation is correct. |
| 301 |
*/ |
| 302 |
|
| 303 |
static int |
| 304 |
get_cieptr_given_offset(Dwarf_Debug dbg, |
| 305 |
Dwarf_Unsigned cie_id_value, |
| 306 |
int use_gnu_cie_calc, |
| 307 |
Dwarf_Small * section_ptr, |
| 308 |
Dwarf_Unsigned section_length, |
| 309 |
Dwarf_Small * cie_id_addr, |
| 310 |
Dwarf_Small ** ret_cieptr, |
| 311 |
Dwarf_Error *error) |
| 312 |
{ |
| 313 |
if (cie_id_value >= section_length) { |
| 314 |
_dwarf_error_string(dbg, error, |
| 315 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 316 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: in eh_frame " |
| 317 |
" cie_id value makes no sense. Corrupt DWARF"); |
| 318 |
return DW_DLV_ERROR; |
| 319 |
} |
| 320 |
if (use_gnu_cie_calc) { |
| 321 |
/* cie_id value is offset, in section, of the |
| 322 |
cie_id itself, to |
| 323 |
use vm ptr of the value, |
| 324 |
less the value, to get to the cie header. */ |
| 325 |
if ((Dwarf_Unsigned)(uintptr_t)cie_id_addr <= cie_id_value) { |
| 326 |
_dwarf_error_string(dbg, error, |
| 327 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 328 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: in eh_frame " |
| 329 |
" cie_id makes no sense. Corrupt DWARF"); |
| 330 |
return DW_DLV_ERROR; |
| 331 |
} |
| 332 |
*ret_cieptr = cie_id_addr - cie_id_value; |
| 333 |
} else { |
| 334 |
/* Traditional dwarf section offset is in cie_id */ |
| 335 |
*ret_cieptr = section_ptr + cie_id_value; |
| 336 |
} |
| 337 |
return DW_DLV_OK; |
| 338 |
} |
| 339 |
|
| 340 |
/* Internal function called from various places to create |
| 341 |
lists of CIEs and FDEs. Not directly called |
| 342 |
by consumer code */ |
| 343 |
int |
| 344 |
_dwarf_get_fde_list_internal(Dwarf_Debug dbg, Dwarf_Cie ** cie_data, |
| 345 |
Dwarf_Signed * cie_element_count, |
| 346 |
Dwarf_Fde ** fde_data, |
| 347 |
Dwarf_Signed * fde_element_count, |
| 348 |
Dwarf_Small * section_ptr, |
| 349 |
Dwarf_Unsigned section_index, |
| 350 |
Dwarf_Unsigned section_length, |
| 351 |
Dwarf_Unsigned cie_id_value, |
| 352 |
int use_gnu_cie_calc, Dwarf_Error * error) |
| 353 |
{ |
| 354 |
/* Scans the debug_frame section. */ |
| 355 |
Dwarf_Small *frame_ptr = section_ptr; |
| 356 |
Dwarf_Small *section_ptr_end = section_ptr + section_length; |
| 357 |
|
| 358 |
/* New_cie points to the Cie being read, and head_cie_ptr and |
| 359 |
cur_cie_ptr are used for chaining them up in sequence. |
| 360 |
In case cie's are reused aggressively we need tail_cie_ptr |
| 361 |
to add to the chain. If we re-use an early cie |
| 362 |
later on, that does not mean we chain a |
| 363 |
new cie to the early one, |
| 364 |
we always chain it to the tail. */ |
| 365 |
Dwarf_Cie head_cie_ptr = NULL; |
| 366 |
Dwarf_Cie cur_cie_ptr = NULL; |
| 367 |
Dwarf_Cie tail_cie_ptr = NULL; |
| 368 |
Dwarf_Unsigned cie_count = 0; |
| 369 |
|
| 370 |
/* Points to a list of contiguous pointers to |
| 371 |
Dwarf_Cie structures. |
| 372 |
*/ |
| 373 |
Dwarf_Cie *cie_list_ptr = 0; |
| 374 |
|
| 375 |
/* New_fde points to the Fde being created, and head_fde_ptr and |
| 376 |
cur_fde_ptr are used to chain them up. */ |
| 377 |
Dwarf_Fde head_fde_ptr = NULL; |
| 378 |
Dwarf_Fde cur_fde_ptr = NULL; |
| 379 |
Dwarf_Unsigned fde_count = 0; |
| 380 |
|
| 381 |
/* Points to a list of contiguous pointers to |
| 382 |
Dwarf_Fde structures. |
| 383 |
*/ |
| 384 |
Dwarf_Fde *fde_list_ptr = NULL; |
| 385 |
|
| 386 |
Dwarf_Unsigned i = 0; |
| 387 |
int res = DW_DLV_ERROR; |
| 388 |
|
| 389 |
if (frame_ptr == 0) { |
| 390 |
return DW_DLV_NO_ENTRY; |
| 391 |
} |
| 392 |
res = _dwarf_validate_register_numbers(dbg,error); |
| 393 |
if (res == DW_DLV_ERROR) { |
| 394 |
return res; |
| 395 |
} |
| 396 |
|
| 397 |
/* We create the fde and cie arrays. |
| 398 |
Processing each CIE as we come |
| 399 |
to it or as an FDE refers to it. |
| 400 |
We cannot process 'late' CIEs |
| 401 |
late as GNU .eh_frame complexities |
| 402 |
mean we need the whole CIE |
| 403 |
before we can process the FDE correctly. */ |
| 404 |
while (frame_ptr < section_ptr_end) { |
| 405 |
|
| 406 |
struct cie_fde_prefix_s prefix; |
| 407 |
|
| 408 |
/* First read in the 'common prefix' to |
| 409 |
figure out what we are |
| 410 |
to do with this entry. */ |
| 411 |
memset(&prefix, 0, sizeof(prefix)); |
| 412 |
res = _dwarf_read_cie_fde_prefix(dbg, |
| 413 |
frame_ptr, section_ptr, |
| 414 |
section_index, |
| 415 |
section_length, &prefix, error); |
| 416 |
if (res == DW_DLV_ERROR) { |
| 417 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 418 |
head_cie_ptr); |
| 419 |
return res; |
| 420 |
} |
| 421 |
if (res == DW_DLV_NO_ENTRY) { |
| 422 |
break; |
| 423 |
} |
| 424 |
frame_ptr = prefix.cf_addr_after_prefix; |
| 425 |
if (frame_ptr >= section_ptr_end) { |
| 426 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 427 |
head_cie_ptr); |
| 428 |
_dwarf_error_string(dbg, error, |
| 429 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 430 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: following " |
| 431 |
"a the start of a cie/fde we have run off" |
| 432 |
" the end of the section. Corrupt Dwarf"); |
| 433 |
|
| 434 |
return DW_DLV_ERROR; |
| 435 |
} |
| 436 |
|
| 437 |
if (prefix.cf_cie_id == cie_id_value) { |
| 438 |
/* This is a CIE. */ |
| 439 |
Dwarf_Cie cie_ptr_to_use = 0; |
| 440 |
int resc = 0; |
| 441 |
|
| 442 |
resc = _dwarf_find_existing_cie_ptr(prefix.cf_start_addr, |
| 443 |
cur_cie_ptr, |
| 444 |
&cie_ptr_to_use, |
| 445 |
head_cie_ptr); |
| 446 |
if (resc == DW_DLV_OK) { |
| 447 |
cur_cie_ptr = cie_ptr_to_use; |
| 448 |
/* Ok. Seen already. */ |
| 449 |
} else if (resc == DW_DLV_NO_ENTRY) { |
| 450 |
/* CIE before its FDE in this case. */ |
| 451 |
resc = _dwarf_create_cie_from_after_start(dbg, |
| 452 |
&prefix, |
| 453 |
section_ptr, |
| 454 |
frame_ptr, |
| 455 |
section_ptr_end, |
| 456 |
cie_count, |
| 457 |
use_gnu_cie_calc, |
| 458 |
&cie_ptr_to_use, |
| 459 |
error); |
| 460 |
if (resc != DW_DLV_OK) { |
| 461 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 462 |
head_cie_ptr); |
| 463 |
return resc; |
| 464 |
} |
| 465 |
cie_count++; |
| 466 |
chain_up_cie(cie_ptr_to_use, &head_cie_ptr, |
| 467 |
&tail_cie_ptr); |
| 468 |
cur_cie_ptr = tail_cie_ptr; |
| 469 |
} else { /* res == DW_DLV_ERROR */ |
| 470 |
|
| 471 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 472 |
head_cie_ptr); |
| 473 |
return resc; |
| 474 |
} |
| 475 |
frame_ptr = cie_ptr_to_use->ci_cie_start + |
| 476 |
cie_ptr_to_use->ci_length + |
| 477 |
cie_ptr_to_use->ci_length_size + |
| 478 |
cie_ptr_to_use->ci_extension_size; |
| 479 |
continue; |
| 480 |
} else { |
| 481 |
/* This is an FDE, Frame Description Entry, see the Dwarf |
| 482 |
Spec, (section 6.4.1 in DWARF2, DWARF3, DWARF4, ...) |
| 483 |
Or see the .eh_frame specification, |
| 484 |
from the Linux Foundation (or other source). */ |
| 485 |
int resf = DW_DLV_ERROR; |
| 486 |
Dwarf_Cie cie_ptr_to_use = 0; |
| 487 |
Dwarf_Fde fde_ptr_to_use = 0; |
| 488 |
Dwarf_Small *cieptr_val = 0; |
| 489 |
|
| 490 |
resf = get_cieptr_given_offset(dbg, |
| 491 |
prefix.cf_cie_id, |
| 492 |
use_gnu_cie_calc, |
| 493 |
section_ptr, |
| 494 |
section_length, |
| 495 |
prefix.cf_cie_id_addr,&cieptr_val,error); |
| 496 |
if (resf != DW_DLV_OK) { |
| 497 |
return resf; |
| 498 |
} |
| 499 |
resf = _dwarf_find_existing_cie_ptr(cieptr_val, |
| 500 |
cur_cie_ptr, |
| 501 |
&cie_ptr_to_use, |
| 502 |
head_cie_ptr); |
| 503 |
if (resf == DW_DLV_OK) { |
| 504 |
cur_cie_ptr = cie_ptr_to_use; |
| 505 |
/* Ok. Seen CIE already. */ |
| 506 |
} else if (resf == DW_DLV_NO_ENTRY) { |
| 507 |
resf = _dwarf_create_cie_from_start(dbg, |
| 508 |
cieptr_val, |
| 509 |
section_ptr, |
| 510 |
section_index, |
| 511 |
section_length, |
| 512 |
section_ptr_end, |
| 513 |
cie_id_value, |
| 514 |
cie_count, |
| 515 |
use_gnu_cie_calc, |
| 516 |
&cie_ptr_to_use, |
| 517 |
error); |
| 518 |
if (resf == DW_DLV_ERROR) { |
| 519 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 520 |
head_cie_ptr); |
| 521 |
return resf; |
| 522 |
} else if (resf == DW_DLV_NO_ENTRY) { |
| 523 |
return resf; |
| 524 |
} |
| 525 |
++cie_count; |
| 526 |
chain_up_cie(cie_ptr_to_use, &head_cie_ptr, |
| 527 |
&tail_cie_ptr); |
| 528 |
cur_cie_ptr = tail_cie_ptr; |
| 529 |
|
| 530 |
} else { |
| 531 |
/* DW_DLV_ERROR */ |
| 532 |
return resf; |
| 533 |
} |
| 534 |
|
| 535 |
resf = _dwarf_create_fde_from_after_start(dbg, |
| 536 |
&prefix, |
| 537 |
section_ptr, |
| 538 |
section_length, |
| 539 |
frame_ptr, |
| 540 |
section_ptr_end, |
| 541 |
use_gnu_cie_calc, |
| 542 |
cie_ptr_to_use, |
| 543 |
cie_ptr_to_use->ci_address_size, |
| 544 |
&fde_ptr_to_use, |
| 545 |
error); |
| 546 |
if (resf == DW_DLV_ERROR) { |
| 547 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 548 |
head_cie_ptr); |
| 549 |
return resf; |
| 550 |
} |
| 551 |
if (resf == DW_DLV_NO_ENTRY) { |
| 552 |
/* impossible. */ |
| 553 |
return resf; |
| 554 |
} |
| 555 |
chain_up_fde(fde_ptr_to_use, &head_fde_ptr, &cur_fde_ptr); |
| 556 |
fde_count++; |
| 557 |
/* ASSERT: DW_DLV_OK. */ |
| 558 |
frame_ptr = cur_fde_ptr->fd_fde_start + |
| 559 |
cur_fde_ptr->fd_length + |
| 560 |
cur_fde_ptr->fd_length_size + |
| 561 |
cur_fde_ptr->fd_extension_size; |
| 562 |
if (frame_ptr < fde_ptr_to_use->fd_fde_instr_start) { |
| 563 |
/* Sanity check. With a really short fde instruction |
| 564 |
set and address_size we think is 8 |
| 565 |
as it is ELF64 (but is |
| 566 |
really 4, as in DWARF{2,3} where we have |
| 567 |
no FDE address_size) we emit an error. |
| 568 |
This error means things will not go well. */ |
| 569 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 570 |
head_cie_ptr); |
| 571 |
_dwarf_error(dbg,error, |
| 572 |
DW_DLE_DEBUG_FRAME_POSSIBLE_ADDRESS_BOTCH); |
| 573 |
return DW_DLV_ERROR; |
| 574 |
} |
| 575 |
continue; |
| 576 |
} |
| 577 |
} |
| 578 |
/* Now build list of CIEs from the list. If there are no CIEs |
| 579 |
there should be no FDEs. */ |
| 580 |
if (cie_count > 0) { |
| 581 |
cie_list_ptr = (Dwarf_Cie *) |
| 582 |
_dwarf_get_alloc(dbg, DW_DLA_LIST, cie_count); |
| 583 |
} else { |
| 584 |
if (fde_count > 0) { |
| 585 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 586 |
head_cie_ptr); |
| 587 |
_dwarf_error(dbg, error, DW_DLE_ORPHAN_FDE); |
| 588 |
return DW_DLV_ERROR; |
| 589 |
} |
| 590 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 591 |
head_cie_ptr); |
| 592 |
return DW_DLV_NO_ENTRY; |
| 593 |
} |
| 594 |
if (cie_list_ptr == NULL) { |
| 595 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 596 |
head_cie_ptr); |
| 597 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 598 |
return DW_DLV_ERROR; |
| 599 |
} |
| 600 |
if (!head_cie_ptr) { |
| 601 |
/* Should be impossible. */ |
| 602 |
_dwarf_error_string(dbg, error,DW_DLE_DEBUGFRAME_ERROR, |
| 603 |
"DW_DLE_DEBUGFRAME_ERROR" |
| 604 |
"Impossible no head_cie_ptr"); |
| 605 |
return DW_DLV_ERROR; |
| 606 |
} |
| 607 |
cur_cie_ptr = head_cie_ptr; |
| 608 |
for (i = 0; i < cie_count; i++) { |
| 609 |
*(cie_list_ptr + i) = cur_cie_ptr; |
| 610 |
cur_cie_ptr = cur_cie_ptr->ci_next; |
| 611 |
} |
| 612 |
|
| 613 |
/* Now build array of FDEs from the list. |
| 614 |
With orphan CIEs (meaning no FDEs) |
| 615 |
lets not return DW_DLV_NO_ENTRY */ |
| 616 |
if (fde_count > 0) { |
| 617 |
fde_list_ptr = (Dwarf_Fde *) |
| 618 |
_dwarf_get_alloc(dbg, DW_DLA_LIST, fde_count); |
| 619 |
if (!fde_list_ptr) { |
| 620 |
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr, |
| 621 |
head_cie_ptr); |
| 622 |
_dwarf_error_string(dbg, error,DW_DLE_ALLOC_FAIL, |
| 623 |
"DW_DLE_ALLOC_FAIL" |
| 624 |
"getting DW_DLA_LIST given fde_count"); |
| 625 |
return DW_DLV_ERROR; |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
/* It is ok if fde_list_ptr is NULL, we just have no fdes. */ |
| 630 |
cur_fde_ptr = head_fde_ptr; |
| 631 |
for (i = 0; i < fde_count; i++) { |
| 632 |
*(fde_list_ptr + i) = cur_fde_ptr; |
| 633 |
cur_fde_ptr = cur_fde_ptr->fd_next; |
| 634 |
} |
| 635 |
|
| 636 |
/* Return arguments. */ |
| 637 |
*cie_data = cie_list_ptr; |
| 638 |
*cie_element_count = cie_count; |
| 639 |
|
| 640 |
*fde_data = fde_list_ptr; |
| 641 |
*fde_element_count = fde_count; |
| 642 |
if (use_gnu_cie_calc) { |
| 643 |
dbg->de_fde_data_eh = fde_list_ptr; |
| 644 |
dbg->de_fde_count_eh = fde_count; |
| 645 |
dbg->de_cie_data_eh = cie_list_ptr; |
| 646 |
dbg->de_cie_count_eh = cie_count; |
| 647 |
} else { |
| 648 |
dbg->de_fde_data = fde_list_ptr; |
| 649 |
dbg->de_fde_count = fde_count; |
| 650 |
dbg->de_cie_data = cie_list_ptr; |
| 651 |
dbg->de_cie_count = cie_count; |
| 652 |
} |
| 653 |
|
| 654 |
/* Sort the list by the address so that |
| 655 |
dwarf_get_fde_at_pc() can |
| 656 |
binary search this list. */ |
| 657 |
if (fde_count > 0) { |
| 658 |
qsort((void *) fde_list_ptr, fde_count, sizeof(Dwarf_Ptr), |
| 659 |
qsort_compare); |
| 660 |
} |
| 661 |
|
| 662 |
return DW_DLV_OK; |
| 663 |
} |
| 664 |
|
| 665 |
/* Internal function, not called by consumer code. |
| 666 |
'prefix' has accumulated the info up thru the cie-id |
| 667 |
and now we consume the rest and build a Dwarf_Cie_s structure. |
| 668 |
*/ |
| 669 |
int |
| 670 |
_dwarf_create_cie_from_after_start(Dwarf_Debug dbg, |
| 671 |
struct cie_fde_prefix_s *prefix, |
| 672 |
Dwarf_Small * section_pointer, |
| 673 |
Dwarf_Small * frame_ptr, |
| 674 |
Dwarf_Small * section_ptr_end, |
| 675 |
Dwarf_Unsigned cie_count, |
| 676 |
int use_gnu_cie_calc, |
| 677 |
Dwarf_Cie * cie_ptr_out, |
| 678 |
Dwarf_Error * error) |
| 679 |
{ |
| 680 |
Dwarf_Cie new_cie = 0; |
| 681 |
|
| 682 |
/* egcs-1.1.2 .eh_frame uses 0 as the distinguishing |
| 683 |
id. sgi uses |
| 684 |
-1 (in .debug_frame). .eh_frame not quite identical to |
| 685 |
.debug_frame */ |
| 686 |
/* We here default the address size as it is not present |
| 687 |
in DWARF2 or DWARF3 cie data, below we set it right if |
| 688 |
it is present. */ |
| 689 |
Dwarf_Half address_size = dbg->de_pointer_size; |
| 690 |
Dwarf_Small *augmentation = 0; |
| 691 |
Dwarf_Half segment_size = 0; |
| 692 |
Dwarf_Signed data_alignment_factor = -1; |
| 693 |
Dwarf_Unsigned code_alignment_factor = 4; |
| 694 |
Dwarf_Unsigned return_address_register = 31; |
| 695 |
int local_length_size = 0; |
| 696 |
Dwarf_Unsigned leb128_length = 0; |
| 697 |
Dwarf_Unsigned cie_aug_data_len = 0; |
| 698 |
Dwarf_Small *cie_aug_data = 0; |
| 699 |
Dwarf_Addr gnu_personality_handler_addr = 0; |
| 700 |
unsigned char gnu_personality_handler_encoding = 0; |
| 701 |
unsigned char gnu_lsda_encoding = 0; |
| 702 |
unsigned char gnu_fde_begin_encoding = 0; |
| 703 |
int res = 0; |
| 704 |
Dwarf_Small version = 0; |
| 705 |
|
| 706 |
enum Dwarf_augmentation_type augt = aug_unknown; |
| 707 |
|
| 708 |
/* This is a CIE, Common Information Entry: See the dwarf spec, |
| 709 |
section 6.4.1 */ |
| 710 |
if (frame_ptr >= section_ptr_end) { |
| 711 |
_dwarf_error_string(dbg, error, |
| 712 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 713 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: reading a cie" |
| 714 |
" version byte we have run off" |
| 715 |
" the end of the section. Corrupt Dwarf"); |
| 716 |
return DW_DLV_ERROR; |
| 717 |
} |
| 718 |
version = *(Dwarf_Small *) frame_ptr; |
| 719 |
|
| 720 |
if ((frame_ptr+2) >= section_ptr_end) { |
| 721 |
_dwarf_error_string(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 722 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: reading an augmentation" |
| 723 |
" would run off" |
| 724 |
" the end of the section. Corrupt Dwarf"); |
| 725 |
return DW_DLV_ERROR; |
| 726 |
} |
| 727 |
if (version != DW_CIE_VERSION && version != DW_CIE_VERSION3 && |
| 728 |
version != DW_CIE_VERSION4 && version != DW_CIE_VERSION5) { |
| 729 |
dwarfstring m; |
| 730 |
dwarfstring_constructor(&m); |
| 731 |
dwarfstring_append_printf_u(&m, |
| 732 |
"DW_DLE_FRAME_VERSION_BAD: cie version %u unknown", |
| 733 |
version); |
| 734 |
_dwarf_error_string(dbg, error, |
| 735 |
DW_DLE_FRAME_VERSION_BAD, |
| 736 |
dwarfstring_string(&m)); |
| 737 |
dwarfstring_destructor(&m); |
| 738 |
return DW_DLV_ERROR; |
| 739 |
} |
| 740 |
frame_ptr++; |
| 741 |
augmentation = frame_ptr; |
| 742 |
res = _dwarf_check_string_valid(dbg,section_pointer, |
| 743 |
frame_ptr,section_ptr_end, |
| 744 |
DW_DLE_AUGMENTATION_STRING_OFF_END,error); |
| 745 |
if (res != DW_DLV_OK) { |
| 746 |
return res; |
| 747 |
} |
| 748 |
frame_ptr = frame_ptr + strlen((char *) frame_ptr) + 1; |
| 749 |
if (frame_ptr >= section_ptr_end) { |
| 750 |
_dwarf_error_string(dbg, error, |
| 751 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 752 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: following any " |
| 753 |
"augmentation field we have run off " |
| 754 |
"the end of the section " |
| 755 |
"with the CIE incomplete. Corrupt Dwarf"); |
| 756 |
return DW_DLV_ERROR; |
| 757 |
} |
| 758 |
augt = _dwarf_get_augmentation_type(dbg, |
| 759 |
augmentation, use_gnu_cie_calc); |
| 760 |
if (augt == aug_eh) { |
| 761 |
if ((frame_ptr+local_length_size) >= section_ptr_end) { |
| 762 |
_dwarf_error_string(dbg, error, |
| 763 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 764 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: following " |
| 765 |
"type field we have run off the end of the section " |
| 766 |
"with the CIE incomplete. Corrupt Dwarf"); |
| 767 |
return DW_DLV_ERROR; |
| 768 |
} |
| 769 |
#if 0 /* obsolete sgi exception table reference. Ignore. */ |
| 770 |
/* REFERENCED *//* Not used in this instance */ |
| 771 |
Dwarf_Unsigned exception_table_addr = 0; |
| 772 |
/* this is per egcs-1.1.2 as on RH 6.0 */ |
| 773 |
READ_UNALIGNED_CK(dbg, exception_table_addr, |
| 774 |
Dwarf_Unsigned, frame_ptr, local_length_size, |
| 775 |
error,section_ptr_end); |
| 776 |
#endif |
| 777 |
frame_ptr += local_length_size; |
| 778 |
} |
| 779 |
{ |
| 780 |
Dwarf_Unsigned lreg = 0; |
| 781 |
unsigned long size = 0; |
| 782 |
|
| 783 |
if (version == DW_CIE_VERSION4) { |
| 784 |
if ((frame_ptr+2) >= section_ptr_end) { |
| 785 |
_dwarf_error_string(dbg, error, |
| 786 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 787 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 788 |
"We would run off the end of the section " |
| 789 |
"in a DWARF4 cie header. Corrupt Dwarf"); |
| 790 |
return DW_DLV_ERROR; |
| 791 |
} |
| 792 |
address_size = *((unsigned char *)frame_ptr); |
| 793 |
if (address_size < 1) { |
| 794 |
_dwarf_error_string(dbg, error, |
| 795 |
DW_DLE_ADDRESS_SIZE_ZERO, |
| 796 |
"DW_DLE_ADDRESS_SIZE_ZERO: bad address size " |
| 797 |
"for a DWARF4 cie header"); |
| 798 |
return DW_DLV_ERROR; |
| 799 |
} |
| 800 |
if (address_size > sizeof(Dwarf_Addr)) { |
| 801 |
_dwarf_create_address_size_dwarf_error(dbg, |
| 802 |
error,address_size, |
| 803 |
DW_DLE_ADDRESS_SIZE_ERROR, |
| 804 |
"DW_DLE_ADDRESS_SIZE_ERROR..:"); |
| 805 |
return DW_DLV_ERROR; |
| 806 |
} |
| 807 |
if ((frame_ptr+2) >= section_ptr_end) { |
| 808 |
_dwarf_error_string(dbg, error, |
| 809 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 810 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 811 |
"Running off the end " |
| 812 |
" of a CIE header. Corrupt DWARF4"); |
| 813 |
return DW_DLV_ERROR; |
| 814 |
} |
| 815 |
++frame_ptr; |
| 816 |
segment_size = *((unsigned char *)frame_ptr); |
| 817 |
++frame_ptr; |
| 818 |
if (segment_size > sizeof(Dwarf_Addr)) { |
| 819 |
_dwarf_error(dbg, error, DW_DLE_SEGMENT_SIZE_BAD); |
| 820 |
return DW_DLV_ERROR; |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
/* Not a great test. But the DECODE* do checking so ok. */ |
| 825 |
if ((frame_ptr+2) >= section_ptr_end) { |
| 826 |
_dwarf_error_string(dbg, error, |
| 827 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 828 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: Running off the end " |
| 829 |
" of a CIE header before the code alignment value " |
| 830 |
"read. Corrupt DWARF"); |
| 831 |
return DW_DLV_ERROR; |
| 832 |
} |
| 833 |
DECODE_LEB128_UWORD_CK(frame_ptr, lreg,dbg,error, |
| 834 |
section_ptr_end); |
| 835 |
code_alignment_factor = (Dwarf_Unsigned) lreg; |
| 836 |
res = dwarf_decode_signed_leb128( |
| 837 |
(char *)frame_ptr, |
| 838 |
&leb128_length,&data_alignment_factor, |
| 839 |
(char *)section_ptr_end); |
| 840 |
if (res != DW_DLV_OK) { |
| 841 |
return res; |
| 842 |
} |
| 843 |
frame_ptr = frame_ptr + leb128_length; |
| 844 |
if ((frame_ptr+1) >= section_ptr_end) { |
| 845 |
_dwarf_error_string(dbg, error, |
| 846 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 847 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: Running off the end " |
| 848 |
"of a CIE header before the return address register " |
| 849 |
"number read. Corrupt DWARF"); |
| 850 |
|
| 851 |
return DW_DLV_ERROR; |
| 852 |
} |
| 853 |
res = _dwarf_get_return_address_reg(frame_ptr, version, |
| 854 |
dbg,section_ptr_end, &size, |
| 855 |
&return_address_register,error); |
| 856 |
if (res != DW_DLV_OK) { |
| 857 |
return res; |
| 858 |
} |
| 859 |
if (return_address_register > |
| 860 |
dbg->de_frame_reg_rules_entry_count) { |
| 861 |
_dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); |
| 862 |
return DW_DLV_ERROR; |
| 863 |
} |
| 864 |
frame_ptr += size; |
| 865 |
if ((frame_ptr) > section_ptr_end) { |
| 866 |
_dwarf_error_string(dbg, error, |
| 867 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 868 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: Past the end " |
| 869 |
"of a CIE header before reading " |
| 870 |
"the augmentation string." |
| 871 |
" Corrupt DWARF"); |
| 872 |
return DW_DLV_ERROR; |
| 873 |
} |
| 874 |
} |
| 875 |
switch (augt) { |
| 876 |
case aug_empty_string: |
| 877 |
break; |
| 878 |
case aug_irix_mti_v1: |
| 879 |
break; |
| 880 |
case aug_irix_exception_table:{ |
| 881 |
Dwarf_Unsigned lreg = 0; |
| 882 |
Dwarf_Unsigned length_of_augmented_fields; |
| 883 |
|
| 884 |
/* Decode the length of augmented fields. */ |
| 885 |
DECODE_LEB128_UWORD_CK(frame_ptr, lreg, |
| 886 |
dbg,error,section_ptr_end); |
| 887 |
length_of_augmented_fields = (Dwarf_Unsigned) lreg; |
| 888 |
if (length_of_augmented_fields >= dbg->de_filesize) { |
| 889 |
_dwarf_error_string(dbg,error, |
| 890 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 891 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 892 |
"The irix exception table length is too large " |
| 893 |
"to be real"); |
| 894 |
return DW_DLV_ERROR; |
| 895 |
} |
| 896 |
/* set the frame_ptr to point at the instruction start. */ |
| 897 |
frame_ptr += length_of_augmented_fields; |
| 898 |
} |
| 899 |
break; |
| 900 |
|
| 901 |
case aug_eh:{ |
| 902 |
int err = 0; |
| 903 |
Dwarf_Unsigned increment = 0; |
| 904 |
|
| 905 |
if (!use_gnu_cie_calc) { |
| 906 |
/* This should be impossible. */ |
| 907 |
_dwarf_error(dbg, error, |
| 908 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 909 |
return DW_DLV_ERROR; |
| 910 |
} |
| 911 |
|
| 912 |
err = _dwarf_get_gcc_eh_augmentation(dbg, frame_ptr, |
| 913 |
&increment, |
| 914 |
augt, |
| 915 |
section_ptr_end, |
| 916 |
(char *) augmentation,error); |
| 917 |
if (err == DW_DLV_ERROR) { |
| 918 |
_dwarf_error(dbg, error, |
| 919 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 920 |
return DW_DLV_ERROR; |
| 921 |
} |
| 922 |
frame_ptr += increment; |
| 923 |
} |
| 924 |
break; |
| 925 |
case aug_gcc_eh_z:{ |
| 926 |
/* Here we have Augmentation Data Length (uleb128) followed |
| 927 |
by Augmentation Data bytes (not a string). */ |
| 928 |
int resz = DW_DLV_ERROR; |
| 929 |
Dwarf_Unsigned adlen = 0; |
| 930 |
|
| 931 |
if ((frame_ptr+1) > section_ptr_end) { |
| 932 |
_dwarf_error_string(dbg, error, |
| 933 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 934 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 935 |
"gcc .eh_frame augmentation data " |
| 936 |
"cannot be read. Out of room in the section." |
| 937 |
" Corrupt DWARF."); |
| 938 |
return DW_DLV_ERROR; |
| 939 |
} |
| 940 |
DECODE_LEB128_UWORD_CK(frame_ptr, adlen, |
| 941 |
dbg,error,section_ptr_end); |
| 942 |
cie_aug_data_len = adlen; |
| 943 |
cie_aug_data = frame_ptr; |
| 944 |
if (adlen) { |
| 945 |
Dwarf_Small *cie_aug_data_end = cie_aug_data+adlen; |
| 946 |
if (cie_aug_data_end < cie_aug_data || |
| 947 |
cie_aug_data_end > section_ptr_end) { |
| 948 |
dwarfstring m; |
| 949 |
|
| 950 |
dwarfstring_constructor(&m); |
| 951 |
dwarfstring_append_printf_u(&m, |
| 952 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 953 |
"gcc .eh_frame augmentation data " |
| 954 |
"length of %" DW_PR_DUu " is too long to" |
| 955 |
" fit in the section.",adlen); |
| 956 |
_dwarf_error_string(dbg, error, |
| 957 |
DW_DLE_AUG_DATA_LENGTH_BAD, |
| 958 |
dwarfstring_string(&m)); |
| 959 |
dwarfstring_destructor(&m); |
| 960 |
return DW_DLV_ERROR; |
| 961 |
} |
| 962 |
} |
| 963 |
resz = _dwarf_gnu_aug_encodings(dbg, |
| 964 |
(char *) augmentation, |
| 965 |
cie_aug_data, |
| 966 |
cie_aug_data_len, |
| 967 |
address_size, |
| 968 |
&gnu_personality_handler_encoding, |
| 969 |
&gnu_lsda_encoding, |
| 970 |
&gnu_fde_begin_encoding, |
| 971 |
&gnu_personality_handler_addr, |
| 972 |
error); |
| 973 |
if (resz != DW_DLV_OK) { |
| 974 |
if (resz == DW_DLV_ERROR) { |
| 975 |
_dwarf_error_string(dbg, error, |
| 976 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN, |
| 977 |
"DW_DLE_FRAME_AUGMENTATION_UNKNOWN " |
| 978 |
" Reading gnu aug encodings failed"); |
| 979 |
} /* DW_DLV_NO_ENTRY seems impossible. */ |
| 980 |
return resz; |
| 981 |
} |
| 982 |
frame_ptr += adlen; |
| 983 |
} |
| 984 |
break; |
| 985 |
case aug_armcc: |
| 986 |
break; |
| 987 |
default:{ |
| 988 |
/* We do not understand the augmentation string. No |
| 989 |
assumption can be made about any fields other than what |
| 990 |
we have already read. */ |
| 991 |
frame_ptr = prefix->cf_start_addr + |
| 992 |
prefix->cf_length + prefix->cf_local_length_size |
| 993 |
+ prefix->cf_local_extension_size; |
| 994 |
/* FIX -- What are the values of data_alignment_factor, |
| 995 |
code_alignment_factor, return_address_register and |
| 996 |
instruction start? They were clearly uninitialized in the |
| 997 |
previous version and I am leaving them the same way. */ |
| 998 |
} |
| 999 |
if ((frame_ptr) > section_ptr_end) { |
| 1000 |
_dwarf_error_string(dbg, error, |
| 1001 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1002 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 1003 |
"Reading an unknown type of augmentation string " |
| 1004 |
"run off the end of the section. Corrupt DWARF."); |
| 1005 |
return DW_DLV_ERROR; |
| 1006 |
} |
| 1007 |
break; |
| 1008 |
} /* End switch on augmentation type. */ |
| 1009 |
|
| 1010 |
new_cie = (Dwarf_Cie) _dwarf_get_alloc(dbg, DW_DLA_CIE, 1); |
| 1011 |
if (new_cie == NULL) { |
| 1012 |
_dwarf_error_string(dbg, error, |
| 1013 |
DW_DLE_ALLOC_FAIL, |
| 1014 |
"DW_DLE_ALLOC_FAIL " |
| 1015 |
"attempting to allocate a Dwarf_Cie"); |
| 1016 |
return DW_DLV_ERROR; |
| 1017 |
} |
| 1018 |
|
| 1019 |
new_cie->ci_cie_version_number = version; |
| 1020 |
new_cie->ci_initial_table = NULL; |
| 1021 |
new_cie->ci_length = (Dwarf_Unsigned) prefix->cf_length; |
| 1022 |
new_cie->ci_length_size = |
| 1023 |
(Dwarf_Small)prefix->cf_local_length_size; |
| 1024 |
new_cie->ci_extension_size = |
| 1025 |
(Dwarf_Small)prefix->cf_local_extension_size; |
| 1026 |
new_cie->ci_augmentation = (char *) augmentation; |
| 1027 |
|
| 1028 |
new_cie->ci_data_alignment_factor = |
| 1029 |
(Dwarf_Sbyte) data_alignment_factor; |
| 1030 |
new_cie->ci_code_alignment_factor = |
| 1031 |
(Dwarf_Small) code_alignment_factor; |
| 1032 |
new_cie->ci_return_address_register = return_address_register; |
| 1033 |
new_cie->ci_cie_start = prefix->cf_start_addr; |
| 1034 |
|
| 1035 |
if ( frame_ptr > section_ptr_end) { |
| 1036 |
_dwarf_error(dbg, error, DW_DLE_DF_FRAME_DECODING_ERROR); |
| 1037 |
return DW_DLV_ERROR; |
| 1038 |
} |
| 1039 |
new_cie->ci_cie_instr_start = frame_ptr; |
| 1040 |
new_cie->ci_dbg = dbg; |
| 1041 |
new_cie->ci_augmentation_type = augt; |
| 1042 |
new_cie->ci_gnu_eh_augmentation_len = cie_aug_data_len; |
| 1043 |
new_cie->ci_gnu_eh_augmentation_bytes = cie_aug_data; |
| 1044 |
new_cie->ci_gnu_personality_handler_encoding = |
| 1045 |
gnu_personality_handler_encoding; |
| 1046 |
new_cie->ci_gnu_personality_handler_addr = |
| 1047 |
gnu_personality_handler_addr; |
| 1048 |
new_cie->ci_gnu_lsda_encoding = gnu_lsda_encoding; |
| 1049 |
new_cie->ci_gnu_fde_begin_encoding = gnu_fde_begin_encoding; |
| 1050 |
|
| 1051 |
new_cie->ci_index = cie_count; |
| 1052 |
new_cie->ci_section_ptr = prefix->cf_section_ptr; |
| 1053 |
new_cie->ci_section_end = section_ptr_end; |
| 1054 |
new_cie->ci_cie_end = new_cie->ci_cie_start + new_cie->ci_length + |
| 1055 |
new_cie->ci_length_size+ new_cie->ci_extension_size; |
| 1056 |
if ( new_cie->ci_cie_end > section_ptr_end) { |
| 1057 |
dwarf_dealloc(dbg,new_cie,DW_DLA_CIE); |
| 1058 |
_dwarf_error(dbg, error, DW_DLE_DF_FRAME_DECODING_ERROR); |
| 1059 |
return DW_DLV_ERROR; |
| 1060 |
} |
| 1061 |
|
| 1062 |
/* The Following new in DWARF4 */ |
| 1063 |
new_cie->ci_address_size = address_size; |
| 1064 |
new_cie->ci_segment_size = segment_size; |
| 1065 |
validate_length(dbg,new_cie,new_cie->ci_length, |
| 1066 |
new_cie->ci_length_size, new_cie->ci_extension_size, |
| 1067 |
new_cie->ci_section_ptr, |
| 1068 |
new_cie->ci_cie_start,"cie"); |
| 1069 |
*cie_ptr_out = new_cie; |
| 1070 |
return DW_DLV_OK; |
| 1071 |
} |
| 1072 |
|
| 1073 |
/* Internal function, not called by consumer code. |
| 1074 |
'prefix' has accumulated the info up thru the cie-id |
| 1075 |
and now we consume the rest and build a Dwarf_Fde_s structure. |
| 1076 |
Can be called with cie_ptr_in NULL from dwarf_frame.c */ |
| 1077 |
|
| 1078 |
int |
| 1079 |
_dwarf_create_fde_from_after_start(Dwarf_Debug dbg, |
| 1080 |
struct cie_fde_prefix_s *prefix, |
| 1081 |
Dwarf_Small *section_pointer, |
| 1082 |
Dwarf_Unsigned section_length, |
| 1083 |
Dwarf_Small *frame_ptr, |
| 1084 |
Dwarf_Small *section_ptr_end, |
| 1085 |
int use_gnu_cie_calc, |
| 1086 |
Dwarf_Cie cie_ptr_in, |
| 1087 |
Dwarf_Half address_size, |
| 1088 |
Dwarf_Fde *fde_ptr_out, |
| 1089 |
Dwarf_Error *error) |
| 1090 |
{ |
| 1091 |
Dwarf_Fde new_fde = 0; |
| 1092 |
Dwarf_Cie cieptr = 0; |
| 1093 |
Dwarf_Small *saved_frame_ptr = 0; |
| 1094 |
|
| 1095 |
Dwarf_Small *initloc = frame_ptr; |
| 1096 |
Dwarf_Signed offset_into_exception_tables |
| 1097 |
= (Dwarf_Signed) DW_DLX_NO_EH_OFFSET; |
| 1098 |
Dwarf_Small *fde_aug_data = 0; |
| 1099 |
Dwarf_Unsigned fde_aug_data_len = 0; |
| 1100 |
Dwarf_Addr cie_base_offset = prefix->cf_cie_id; |
| 1101 |
Dwarf_Addr initial_location = 0; /* must be min de_pointer_size |
| 1102 |
bytes in size */ |
| 1103 |
Dwarf_Addr address_range = 0; /* must be min de_pointer_size |
| 1104 |
bytes in size */ |
| 1105 |
Dwarf_Unsigned eh_table_value = 0; |
| 1106 |
Dwarf_Bool eh_table_value_set = FALSE; |
| 1107 |
/* Temporary assumption. */ |
| 1108 |
enum Dwarf_augmentation_type augt = aug_empty_string; |
| 1109 |
|
| 1110 |
if (cie_ptr_in) { |
| 1111 |
cieptr = cie_ptr_in; |
| 1112 |
augt = cieptr->ci_augmentation_type; |
| 1113 |
} |
| 1114 |
if (augt == aug_gcc_eh_z) { |
| 1115 |
/* If z augmentation this is eh_frame, |
| 1116 |
and initial_location and |
| 1117 |
address_range in the FDE are read according to the CIE |
| 1118 |
augmentation string instructions. */ |
| 1119 |
|
| 1120 |
if (cieptr) { |
| 1121 |
Dwarf_Small *fp_updated = 0; |
| 1122 |
int res = _dwarf_read_encoded_ptr(dbg, |
| 1123 |
section_pointer, |
| 1124 |
frame_ptr, |
| 1125 |
cieptr-> ci_gnu_fde_begin_encoding, |
| 1126 |
section_ptr_end, |
| 1127 |
address_size, |
| 1128 |
&initial_location, |
| 1129 |
&fp_updated,error); |
| 1130 |
if (res != DW_DLV_OK) { |
| 1131 |
return res; |
| 1132 |
} |
| 1133 |
frame_ptr = fp_updated; |
| 1134 |
/* For the address-range it makes no sense to be |
| 1135 |
pc-relative, so we turn it off |
| 1136 |
with a section_pointer of |
| 1137 |
NULL. Masking off DW_EH_PE_pcrel from the |
| 1138 |
ci_gnu_fde_begin_encoding in this |
| 1139 |
call would also work |
| 1140 |
to turn off DW_EH_PE_pcrel. */ |
| 1141 |
res = _dwarf_read_encoded_ptr(dbg, (Dwarf_Small *) NULL, |
| 1142 |
frame_ptr, |
| 1143 |
cieptr->ci_gnu_fde_begin_encoding, |
| 1144 |
section_ptr_end, |
| 1145 |
address_size, |
| 1146 |
&address_range, &fp_updated,error); |
| 1147 |
if (res != DW_DLV_OK) { |
| 1148 |
return res; |
| 1149 |
} |
| 1150 |
frame_ptr = fp_updated; |
| 1151 |
} /* We know cieptr was set as was augt, no else needed |
| 1152 |
converity scan CID 323429 */ |
| 1153 |
{ |
| 1154 |
Dwarf_Unsigned adlen = 0; |
| 1155 |
|
| 1156 |
DECODE_LEB128_UWORD_CK(frame_ptr, adlen, |
| 1157 |
dbg,error,section_ptr_end); |
| 1158 |
fde_aug_data_len = adlen; |
| 1159 |
fde_aug_data = frame_ptr; |
| 1160 |
if (frame_ptr < section_ptr_end) { |
| 1161 |
Dwarf_Unsigned remaininglen = 0; |
| 1162 |
remaininglen = (Dwarf_Unsigned) |
| 1163 |
(section_ptr_end - frame_ptr); |
| 1164 |
if (remaininglen <= adlen) { |
| 1165 |
_dwarf_error_string(dbg, error, |
| 1166 |
DW_DLE_AUG_DATA_LENGTH_BAD, |
| 1167 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 1168 |
"augmentation length is too large for " |
| 1169 |
"the frame section, corrupt DWARF"); |
| 1170 |
return DW_DLV_ERROR; |
| 1171 |
} |
| 1172 |
} else { |
| 1173 |
_dwarf_error_string(dbg, error, |
| 1174 |
DW_DLE_AUG_DATA_LENGTH_BAD, |
| 1175 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 1176 |
"frame pointer has stepped off the end " |
| 1177 |
"of the frame section on reading augmentation " |
| 1178 |
"length. Corrupt DWARF"); |
| 1179 |
return DW_DLV_ERROR; |
| 1180 |
} |
| 1181 |
if ( adlen >= section_length) { |
| 1182 |
dwarfstring m; |
| 1183 |
|
| 1184 |
dwarfstring_constructor(&m); |
| 1185 |
dwarfstring_append_printf_u(&m, |
| 1186 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 1187 |
"gcc .eh_frame augmentation data " |
| 1188 |
"length of %" DW_PR_DUu " is too long to" |
| 1189 |
" fit in the section.",adlen); |
| 1190 |
_dwarf_error_string(dbg, error, |
| 1191 |
DW_DLE_AUG_DATA_LENGTH_BAD, |
| 1192 |
dwarfstring_string(&m)); |
| 1193 |
dwarfstring_destructor(&m); |
| 1194 |
return DW_DLV_ERROR; |
| 1195 |
} |
| 1196 |
frame_ptr += adlen; |
| 1197 |
if (adlen) { |
| 1198 |
if (frame_ptr < fde_aug_data || |
| 1199 |
frame_ptr >= section_ptr_end ) { |
| 1200 |
dwarfstring m; |
| 1201 |
|
| 1202 |
dwarfstring_constructor(&m); |
| 1203 |
dwarfstring_append_printf_u(&m, |
| 1204 |
"DW_DLE_AUG_DATA_LENGTH_BAD: The " |
| 1205 |
"gcc .eh_frame augmentation data " |
| 1206 |
"length of %" DW_PR_DUu " is too long to" |
| 1207 |
" fit in the section.",adlen); |
| 1208 |
_dwarf_error_string(dbg, error, |
| 1209 |
DW_DLE_AUG_DATA_LENGTH_BAD, |
| 1210 |
dwarfstring_string(&m)); |
| 1211 |
dwarfstring_destructor(&m); |
| 1212 |
return DW_DLV_ERROR; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
} |
| 1216 |
} else { |
| 1217 |
if ((frame_ptr + 2*address_size) > section_ptr_end) { |
| 1218 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1219 |
return DW_DLV_ERROR; |
| 1220 |
} |
| 1221 |
READ_UNALIGNED_CK(dbg, initial_location, Dwarf_Addr, |
| 1222 |
frame_ptr, address_size, |
| 1223 |
error,section_ptr_end); |
| 1224 |
frame_ptr += address_size; |
| 1225 |
READ_UNALIGNED_CK(dbg, address_range, Dwarf_Addr, |
| 1226 |
frame_ptr, address_size, |
| 1227 |
error,section_ptr_end); |
| 1228 |
frame_ptr += address_size; |
| 1229 |
} |
| 1230 |
switch (augt) { |
| 1231 |
case aug_irix_mti_v1: |
| 1232 |
case aug_empty_string: |
| 1233 |
break; |
| 1234 |
case aug_irix_exception_table:{ |
| 1235 |
Dwarf_Unsigned lreg = 0; |
| 1236 |
Dwarf_Unsigned length_of_augmented_fields = 0; |
| 1237 |
|
| 1238 |
DECODE_LEB128_UWORD_CK(frame_ptr, lreg, |
| 1239 |
dbg,error,section_ptr_end); |
| 1240 |
length_of_augmented_fields = (Dwarf_Unsigned) lreg; |
| 1241 |
|
| 1242 |
if (length_of_augmented_fields >= dbg->de_filesize) { |
| 1243 |
_dwarf_error_string(dbg, error, |
| 1244 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1245 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD " |
| 1246 |
"in irix exception table length of augmented " |
| 1247 |
"fields is too large to be real"); |
| 1248 |
return DW_DLV_ERROR; |
| 1249 |
} |
| 1250 |
saved_frame_ptr = frame_ptr; |
| 1251 |
/* The first word is an offset into exception tables. |
| 1252 |
Defined as a 32bit offset even for CC -64. */ |
| 1253 |
if ((frame_ptr + DWARF_32BIT_SIZE) > section_ptr_end) { |
| 1254 |
_dwarf_error_string(dbg,error, |
| 1255 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1256 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD " |
| 1257 |
"irix:frame does not fit in the DWARF section"); |
| 1258 |
return DW_DLV_ERROR; |
| 1259 |
} |
| 1260 |
READ_UNALIGNED_CK(dbg, offset_into_exception_tables, |
| 1261 |
Dwarf_Addr, frame_ptr, DWARF_32BIT_SIZE, |
| 1262 |
error,section_ptr_end); |
| 1263 |
SIGN_EXTEND(offset_into_exception_tables, |
| 1264 |
DWARF_32BIT_SIZE); |
| 1265 |
if (offset_into_exception_tables > 0) { |
| 1266 |
if ((Dwarf_Unsigned)offset_into_exception_tables >= |
| 1267 |
dbg->de_filesize) { |
| 1268 |
_dwarf_error_string(dbg,error, |
| 1269 |
DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1270 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD " |
| 1271 |
"Irix offset into exception tables"); |
| 1272 |
return DW_DLV_ERROR; |
| 1273 |
} |
| 1274 |
} /* nobody uses irix anyway now */ |
| 1275 |
frame_ptr = saved_frame_ptr + length_of_augmented_fields; |
| 1276 |
} |
| 1277 |
break; |
| 1278 |
case aug_eh:{ |
| 1279 |
|
| 1280 |
if (!use_gnu_cie_calc) { |
| 1281 |
/* This should be impossible. */ |
| 1282 |
_dwarf_error(dbg, error, |
| 1283 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1284 |
return DW_DLV_ERROR; |
| 1285 |
} |
| 1286 |
|
| 1287 |
/* gnu eh fde case. we do not need to do anything */ |
| 1288 |
/*REFERENCED*/ /* Not used in this instance of the macro */ |
| 1289 |
if ((frame_ptr + address_size) > section_ptr_end) { |
| 1290 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1291 |
return DW_DLV_ERROR; |
| 1292 |
} |
| 1293 |
READ_UNALIGNED_CK(dbg, eh_table_value, |
| 1294 |
Dwarf_Unsigned, frame_ptr, |
| 1295 |
address_size, |
| 1296 |
error,section_ptr_end); |
| 1297 |
eh_table_value_set = TRUE; |
| 1298 |
frame_ptr += address_size; |
| 1299 |
} |
| 1300 |
break; |
| 1301 |
|
| 1302 |
case aug_gcc_eh_z:{ |
| 1303 |
/* The Augmentation Data Length is here, followed by the |
| 1304 |
Augmentation Data bytes themselves. */ |
| 1305 |
} |
| 1306 |
break; |
| 1307 |
case aug_armcc: |
| 1308 |
break; |
| 1309 |
case aug_past_last: |
| 1310 |
break; |
| 1311 |
|
| 1312 |
case aug_metaware: /* No special fields. See dwarf_util.h */ |
| 1313 |
break; |
| 1314 |
|
| 1315 |
case aug_unknown: |
| 1316 |
_dwarf_error(dbg, error, DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1317 |
return DW_DLV_ERROR; |
| 1318 |
default: break; |
| 1319 |
} /* End switch on augmentation type */ |
| 1320 |
if ( frame_ptr > section_ptr_end) { |
| 1321 |
_dwarf_error(dbg, error, DW_DLE_DF_FRAME_DECODING_ERROR); |
| 1322 |
return DW_DLV_ERROR; |
| 1323 |
} |
| 1324 |
if ( frame_ptr < initloc) { |
| 1325 |
_dwarf_error_string(dbg, error, |
| 1326 |
DW_DLE_DF_FRAME_DECODING_ERROR, |
| 1327 |
"DW_DLE_DF_FRAME_DECODING_ERROR " |
| 1328 |
"frame pointer decreased.Impossible. " |
| 1329 |
"arithmetic overflow"); |
| 1330 |
return DW_DLV_ERROR; |
| 1331 |
} |
| 1332 |
|
| 1333 |
new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1); |
| 1334 |
if (new_fde == NULL) { |
| 1335 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1336 |
return DW_DLV_ERROR; |
| 1337 |
} |
| 1338 |
|
| 1339 |
new_fde->fd_length = prefix->cf_length; |
| 1340 |
new_fde->fd_length_size = |
| 1341 |
(Dwarf_Small)prefix->cf_local_length_size; |
| 1342 |
new_fde->fd_extension_size = |
| 1343 |
(Dwarf_Small)prefix->cf_local_extension_size; |
| 1344 |
new_fde->fd_is_eh = (Dwarf_Small)use_gnu_cie_calc; |
| 1345 |
new_fde->fd_cie_offset = cie_base_offset; |
| 1346 |
if (cieptr) { |
| 1347 |
new_fde->fd_cie_index = cieptr->ci_index; |
| 1348 |
} |
| 1349 |
new_fde->fd_cie = cieptr; |
| 1350 |
new_fde->fd_initial_location = initial_location; |
| 1351 |
new_fde->fd_initial_loc_pos = initloc; |
| 1352 |
new_fde->fd_address_range = address_range; |
| 1353 |
new_fde->fd_fde_start = prefix->cf_start_addr; |
| 1354 |
|
| 1355 |
new_fde->fd_fde_instr_start = frame_ptr; |
| 1356 |
new_fde->fd_fde_end = prefix->cf_start_addr + |
| 1357 |
prefix->cf_length + prefix->cf_local_length_size + |
| 1358 |
prefix->cf_local_extension_size; |
| 1359 |
if ( new_fde->fd_fde_end > section_ptr_end) { |
| 1360 |
_dwarf_error(dbg, error, DW_DLE_DF_FRAME_DECODING_ERROR); |
| 1361 |
dwarf_dealloc(dbg,new_fde,DW_DLA_FDE); |
| 1362 |
return DW_DLV_ERROR; |
| 1363 |
} |
| 1364 |
|
| 1365 |
new_fde->fd_dbg = dbg; |
| 1366 |
new_fde->fd_offset_into_exception_tables = |
| 1367 |
offset_into_exception_tables; |
| 1368 |
new_fde->fd_eh_table_value = eh_table_value; |
| 1369 |
new_fde->fd_eh_table_value_set = eh_table_value_set; |
| 1370 |
|
| 1371 |
new_fde->fd_section_ptr = prefix->cf_section_ptr; |
| 1372 |
new_fde->fd_section_index = prefix->cf_section_index; |
| 1373 |
new_fde->fd_section_length = prefix->cf_section_length; |
| 1374 |
new_fde->fd_section_end = section_ptr_end; |
| 1375 |
|
| 1376 |
if (augt == aug_gcc_eh_z) { |
| 1377 |
new_fde->fd_gnu_eh_aug_present = TRUE; |
| 1378 |
} |
| 1379 |
new_fde->fd_gnu_eh_augmentation_bytes = fde_aug_data; |
| 1380 |
new_fde->fd_gnu_eh_augmentation_len = fde_aug_data_len; |
| 1381 |
validate_length(dbg,cieptr,new_fde->fd_length, |
| 1382 |
new_fde->fd_length_size, new_fde->fd_extension_size, |
| 1383 |
new_fde->fd_section_ptr,new_fde->fd_fde_start,"fde"); |
| 1384 |
*fde_ptr_out = new_fde; |
| 1385 |
return DW_DLV_OK; |
| 1386 |
} |
| 1387 |
|
| 1388 |
/* Read in the common cie/fde prefix, including reading |
| 1389 |
the cie-value which shows which this is: cie or fde. */ |
| 1390 |
int |
| 1391 |
_dwarf_read_cie_fde_prefix(Dwarf_Debug dbg, |
| 1392 |
Dwarf_Small * frame_ptr_in, |
| 1393 |
Dwarf_Small * section_ptr_in, |
| 1394 |
Dwarf_Unsigned section_index_in, |
| 1395 |
Dwarf_Unsigned section_length_in, |
| 1396 |
struct cie_fde_prefix_s *data_out, |
| 1397 |
Dwarf_Error * error) |
| 1398 |
{ |
| 1399 |
Dwarf_Unsigned length = 0; |
| 1400 |
int local_length_size = 0; |
| 1401 |
int local_extension_size = 0; |
| 1402 |
Dwarf_Small *frame_ptr = frame_ptr_in; |
| 1403 |
Dwarf_Small *cie_ptr_addr = 0; |
| 1404 |
Dwarf_Unsigned cie_id = 0; |
| 1405 |
Dwarf_Small *section_end = section_ptr_in + section_length_in; |
| 1406 |
|
| 1407 |
if (frame_ptr_in < section_ptr_in || |
| 1408 |
frame_ptr_in >= section_end) { |
| 1409 |
_dwarf_error_string(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1410 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 1411 |
"The frame point given _dwarf_read_cie_fde_prefix() " |
| 1412 |
"is invalid"); |
| 1413 |
return DW_DLV_ERROR; |
| 1414 |
} |
| 1415 |
if (section_end < (frame_ptr +4)) { |
| 1416 |
dwarfstring m; |
| 1417 |
Dwarf_Unsigned u = |
| 1418 |
(Dwarf_Unsigned)(uintptr_t)(frame_ptr+4) - |
| 1419 |
(Dwarf_Unsigned)(uintptr_t)section_end; |
| 1420 |
|
| 1421 |
dwarfstring_constructor(&m); |
| 1422 |
dwarfstring_append_printf_u(&m, |
| 1423 |
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: " |
| 1424 |
"Reading the cie/fde prefix would " |
| 1425 |
"put us %u bytes past the end of the " |
| 1426 |
"frame section. Corrupt Dwarf.",u); |
| 1427 |
_dwarf_error_string(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD, |
| 1428 |
dwarfstring_string(&m)); |
| 1429 |
dwarfstring_destructor(&m); |
| 1430 |
return DW_DLV_ERROR; |
| 1431 |
} |
| 1432 |
/* READ_AREA_LENGTH updates frame_ptr for consumed bytes */ |
| 1433 |
READ_AREA_LENGTH_CK(dbg, length, Dwarf_Unsigned, |
| 1434 |
frame_ptr, local_length_size, |
| 1435 |
local_extension_size,error, |
| 1436 |
section_length_in,section_end); |
| 1437 |
if (length == 0) { |
| 1438 |
/* nul bytes at end of section, seen at end of egcs eh_frame |
| 1439 |
sections (in a.out). Take this as meaning no more CIE/FDE |
| 1440 |
data. We should be very close to end of section. */ |
| 1441 |
return DW_DLV_NO_ENTRY; |
| 1442 |
} |
| 1443 |
if (length >= dbg->de_filesize) { |
| 1444 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1445 |
return DW_DLV_ERROR; |
| 1446 |
} |
| 1447 |
if (length > section_length_in || |
| 1448 |
(length +local_length_size + local_extension_size) > |
| 1449 |
section_length_in) { |
| 1450 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1451 |
return DW_DLV_ERROR; |
| 1452 |
} |
| 1453 |
if ((frame_ptr + local_length_size) >= section_end) { |
| 1454 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1455 |
return DW_DLV_ERROR; |
| 1456 |
} |
| 1457 |
|
| 1458 |
cie_ptr_addr = frame_ptr; |
| 1459 |
READ_UNALIGNED_CK(dbg, cie_id, Dwarf_Unsigned, |
| 1460 |
frame_ptr, local_length_size,error,section_end); |
| 1461 |
SIGN_EXTEND(cie_id, local_length_size); |
| 1462 |
frame_ptr += local_length_size; |
| 1463 |
|
| 1464 |
data_out->cf_start_addr = frame_ptr_in; |
| 1465 |
data_out->cf_addr_after_prefix = frame_ptr; |
| 1466 |
|
| 1467 |
data_out->cf_length = length; |
| 1468 |
if (length > section_length_in) { |
| 1469 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1470 |
return DW_DLV_ERROR; |
| 1471 |
} |
| 1472 |
if (cie_ptr_addr+length > section_end) { |
| 1473 |
_dwarf_error(dbg,error,DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1474 |
return DW_DLV_ERROR; |
| 1475 |
} |
| 1476 |
data_out->cf_local_length_size = local_length_size; |
| 1477 |
data_out->cf_local_extension_size = local_extension_size; |
| 1478 |
|
| 1479 |
/* We do not know if it is a CIE or FDE id yet. |
| 1480 |
How we check and what it means |
| 1481 |
depends whether it is .debug_frame |
| 1482 |
or .eh_frame. */ |
| 1483 |
data_out->cf_cie_id = cie_id; |
| 1484 |
|
| 1485 |
/* The address of the CIE_id or FDE_id value in memory. */ |
| 1486 |
data_out->cf_cie_id_addr = cie_ptr_addr; |
| 1487 |
|
| 1488 |
data_out->cf_section_ptr = section_ptr_in; |
| 1489 |
data_out->cf_section_index = section_index_in; |
| 1490 |
data_out->cf_section_length = section_length_in; |
| 1491 |
return DW_DLV_OK; |
| 1492 |
} |
| 1493 |
|
| 1494 |
/* On various errors previously-allocated CIEs and FDEs |
| 1495 |
must be cleaned up. |
| 1496 |
This helps avoid leaks in case of errors. |
| 1497 |
*/ |
| 1498 |
static void |
| 1499 |
_dwarf_dealloc_fde_cie_list_internal(Dwarf_Fde head_fde_ptr, |
| 1500 |
Dwarf_Cie head_cie_ptr) |
| 1501 |
{ |
| 1502 |
Dwarf_Fde curfde = 0; |
| 1503 |
Dwarf_Cie curcie = 0; |
| 1504 |
Dwarf_Fde nextfde = 0; |
| 1505 |
Dwarf_Cie nextcie = 0; |
| 1506 |
|
| 1507 |
for (curfde = head_fde_ptr; curfde; curfde = nextfde) { |
| 1508 |
nextfde = curfde->fd_next; |
| 1509 |
dwarf_dealloc(curfde->fd_dbg, curfde, DW_DLA_FDE); |
| 1510 |
} |
| 1511 |
for (curcie = head_cie_ptr; curcie; curcie = nextcie) { |
| 1512 |
Dwarf_Frame frame = curcie->ci_initial_table; |
| 1513 |
|
| 1514 |
nextcie = curcie->ci_next; |
| 1515 |
if (frame) |
| 1516 |
dwarf_dealloc(curcie->ci_dbg, frame, DW_DLA_FRAME); |
| 1517 |
dwarf_dealloc(curcie->ci_dbg, curcie, DW_DLA_CIE); |
| 1518 |
} |
| 1519 |
} |
| 1520 |
|
| 1521 |
/* Find the cie whose id value is given: the id |
| 1522 |
value is, per DWARF2/3, an offset in the section. |
| 1523 |
For .debug_frame, zero is a legal offset. For |
| 1524 |
GNU .eh_frame it is not a legal offset. |
| 1525 |
'cie_ptr' is a pointer into our section, not an offset. */ |
| 1526 |
static int |
| 1527 |
_dwarf_find_existing_cie_ptr(Dwarf_Small * cie_ptr, |
| 1528 |
Dwarf_Cie cur_cie_ptr, |
| 1529 |
Dwarf_Cie * cie_ptr_to_use_out, |
| 1530 |
Dwarf_Cie head_cie_ptr) |
| 1531 |
{ |
| 1532 |
Dwarf_Cie next = 0; |
| 1533 |
|
| 1534 |
if (cur_cie_ptr && cie_ptr == cur_cie_ptr->ci_cie_start) { |
| 1535 |
/* Usually, we use the same cie again and again. */ |
| 1536 |
*cie_ptr_to_use_out = cur_cie_ptr; |
| 1537 |
return DW_DLV_OK; |
| 1538 |
} |
| 1539 |
for (next = head_cie_ptr; next; next = next->ci_next) { |
| 1540 |
if (cie_ptr == next->ci_cie_start) { |
| 1541 |
*cie_ptr_to_use_out = next; |
| 1542 |
return DW_DLV_OK; |
| 1543 |
} |
| 1544 |
} |
| 1545 |
return DW_DLV_NO_ENTRY; |
| 1546 |
} |
| 1547 |
|
| 1548 |
/* We have a valid cie_ptr_val that has not been |
| 1549 |
turned into an internal Cie yet. Do so now. |
| 1550 |
Returns DW_DLV_OK or DW_DLV_ERROR, never |
| 1551 |
DW_DLV_NO_ENTRY. |
| 1552 |
|
| 1553 |
'section_ptr' - Points to first byte of section data. |
| 1554 |
'section_length' - Length of the section, in bytes. |
| 1555 |
'section_ptr_end' - Points 1-past last byte of section data. */ |
| 1556 |
static int |
| 1557 |
_dwarf_create_cie_from_start(Dwarf_Debug dbg, |
| 1558 |
Dwarf_Small * cie_ptr_val, |
| 1559 |
Dwarf_Small * section_ptr, |
| 1560 |
Dwarf_Unsigned section_index, |
| 1561 |
Dwarf_Unsigned section_length, |
| 1562 |
Dwarf_Small * section_ptr_end, |
| 1563 |
Dwarf_Unsigned cie_id_value, |
| 1564 |
Dwarf_Unsigned cie_count, |
| 1565 |
int use_gnu_cie_calc, |
| 1566 |
Dwarf_Cie * cie_ptr_to_use_out, |
| 1567 |
Dwarf_Error * error) |
| 1568 |
{ |
| 1569 |
struct cie_fde_prefix_s prefix; |
| 1570 |
int res = DW_DLV_ERROR; |
| 1571 |
Dwarf_Small *frame_ptr = cie_ptr_val; |
| 1572 |
|
| 1573 |
if (frame_ptr < section_ptr || frame_ptr >= section_ptr_end) { |
| 1574 |
_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD); |
| 1575 |
return DW_DLV_ERROR; |
| 1576 |
} |
| 1577 |
/* First read in the 'common prefix' to figure out |
| 1578 |
what * we are to |
| 1579 |
do with this entry. If it is not a cie * |
| 1580 |
we are in big trouble. */ |
| 1581 |
memset(&prefix, 0, sizeof(prefix)); |
| 1582 |
res = _dwarf_read_cie_fde_prefix(dbg, frame_ptr, section_ptr, |
| 1583 |
section_index, section_length, |
| 1584 |
&prefix, error); |
| 1585 |
if (res == DW_DLV_ERROR) { |
| 1586 |
return res; |
| 1587 |
} |
| 1588 |
if (res == DW_DLV_NO_ENTRY) { |
| 1589 |
/* error. */ |
| 1590 |
_dwarf_error(dbg, error, DW_DLE_FRAME_CIE_DECODE_ERROR); |
| 1591 |
return DW_DLV_ERROR; |
| 1592 |
|
| 1593 |
} |
| 1594 |
|
| 1595 |
if (prefix.cf_cie_id != cie_id_value) { |
| 1596 |
_dwarf_error(dbg, error, DW_DLE_FRAME_CIE_DECODE_ERROR); |
| 1597 |
return DW_DLV_ERROR; |
| 1598 |
} |
| 1599 |
frame_ptr = prefix.cf_addr_after_prefix; |
| 1600 |
res = _dwarf_create_cie_from_after_start(dbg, |
| 1601 |
&prefix, |
| 1602 |
section_ptr, |
| 1603 |
frame_ptr, |
| 1604 |
section_ptr_end, |
| 1605 |
cie_count, |
| 1606 |
use_gnu_cie_calc, |
| 1607 |
cie_ptr_to_use_out, error); |
| 1608 |
return res; |
| 1609 |
|
| 1610 |
} |
| 1611 |
|
| 1612 |
/* This is for gnu eh frames, the 'z' case. |
| 1613 |
We find the letter involved |
| 1614 |
Return the augmentation character and, if applicable, |
| 1615 |
the personality routine address. |
| 1616 |
|
| 1617 |
personality_routine_out - |
| 1618 |
if 'P' is augchar, is personality handler addr. |
| 1619 |
Otherwise is not set. |
| 1620 |
aug_data - if 'P' points to data space of the |
| 1621 |
aug_data_len - length of areas aug_data points to. |
| 1622 |
*/ |
| 1623 |
|
| 1624 |
/* It is not clear if this is entirely correct. */ |
| 1625 |
static int |
| 1626 |
_dwarf_gnu_aug_encodings(Dwarf_Debug dbg, char *augmentation, |
| 1627 |
Dwarf_Small * aug_data, Dwarf_Unsigned aug_data_len, |
| 1628 |
Dwarf_Half address_size, |
| 1629 |
unsigned char *pers_hand_enc_out, |
| 1630 |
unsigned char *lsda_enc_out, |
| 1631 |
unsigned char *fde_begin_enc_out, |
| 1632 |
Dwarf_Addr * gnu_pers_addr_out, |
| 1633 |
Dwarf_Error * error) |
| 1634 |
{ |
| 1635 |
char *nc = 0; |
| 1636 |
Dwarf_Small *cur_aug_p = aug_data; |
| 1637 |
Dwarf_Small *end_aug_p = aug_data + aug_data_len; |
| 1638 |
|
| 1639 |
for (nc = augmentation; *nc; ++nc) { |
| 1640 |
char c = *nc; |
| 1641 |
|
| 1642 |
switch (c) { |
| 1643 |
case 'z': |
| 1644 |
/* Means that the augmentation data is present. */ |
| 1645 |
continue; |
| 1646 |
|
| 1647 |
case 'S': |
| 1648 |
/* Indicates this is a signal stack frame. |
| 1649 |
Debuggers have to do |
| 1650 |
special handling. We don't need to do more than |
| 1651 |
print this flag at the right time, though |
| 1652 |
(see dwarfdump where it prints the augmentation |
| 1653 |
string). |
| 1654 |
A signal stack frame (in some OS's) can only be |
| 1655 |
unwound (backtraced) by knowing it is a signal |
| 1656 |
stack frame (perhaps by noticing the name of the |
| 1657 |
function for the stack frame if the name can be |
| 1658 |
found somehow) and figuring |
| 1659 |
out (or knowing) how the kernel and libc |
| 1660 |
pushed a structure |
| 1661 |
onto the stack and loading registers from |
| 1662 |
that structure. |
| 1663 |
Totally different from normal stack unwinding. |
| 1664 |
This flag gives an unwinder a big leg up by |
| 1665 |
decoupling the 'hint: this is a stack frame' |
| 1666 |
from knowledge like |
| 1667 |
the function name (the name might be |
| 1668 |
unavailable at unwind time). |
| 1669 |
*/ |
| 1670 |
break; |
| 1671 |
|
| 1672 |
case 'L': |
| 1673 |
if (cur_aug_p >= end_aug_p) { |
| 1674 |
_dwarf_error_string(dbg, error, |
| 1675 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN, |
| 1676 |
"DW_DLE_FRAME_AUGMENTATION_UNKNOWN: " |
| 1677 |
" Augmentation L runs off the end" |
| 1678 |
" of augmentation bytes"); |
| 1679 |
return DW_DLV_ERROR; |
| 1680 |
} |
| 1681 |
*lsda_enc_out = *(unsigned char *) cur_aug_p; |
| 1682 |
++cur_aug_p; |
| 1683 |
break; |
| 1684 |
case 'R': |
| 1685 |
/* Followed by a one byte argument giving the |
| 1686 |
pointer encoding for the address |
| 1687 |
pointers in the fde. */ |
| 1688 |
if (cur_aug_p >= end_aug_p) { |
| 1689 |
_dwarf_error(dbg, error, |
| 1690 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1691 |
return DW_DLV_ERROR; |
| 1692 |
} |
| 1693 |
*fde_begin_enc_out = *(unsigned char *) cur_aug_p; |
| 1694 |
++cur_aug_p; |
| 1695 |
break; |
| 1696 |
case 'P':{ |
| 1697 |
int res = DW_DLV_ERROR; |
| 1698 |
Dwarf_Small *updated_aug_p = 0; |
| 1699 |
unsigned char encoding = 0; |
| 1700 |
|
| 1701 |
if (cur_aug_p >= end_aug_p) { |
| 1702 |
_dwarf_error(dbg, error, |
| 1703 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1704 |
return DW_DLV_ERROR; |
| 1705 |
} |
| 1706 |
encoding = *(unsigned char *) cur_aug_p; |
| 1707 |
*pers_hand_enc_out = encoding; |
| 1708 |
++cur_aug_p; |
| 1709 |
if (cur_aug_p > end_aug_p) { |
| 1710 |
_dwarf_error(dbg, error, |
| 1711 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1712 |
return DW_DLV_ERROR; |
| 1713 |
} |
| 1714 |
/* DW_EH_PE_pcrel makes no sense here, so we turn it |
| 1715 |
off via a section pointer of NULL. */ |
| 1716 |
res = _dwarf_read_encoded_ptr(dbg, |
| 1717 |
(Dwarf_Small *) NULL, |
| 1718 |
cur_aug_p, |
| 1719 |
encoding, |
| 1720 |
end_aug_p, |
| 1721 |
address_size, |
| 1722 |
gnu_pers_addr_out, |
| 1723 |
&updated_aug_p, |
| 1724 |
error); |
| 1725 |
if (res != DW_DLV_OK) { |
| 1726 |
return res; |
| 1727 |
} |
| 1728 |
cur_aug_p = updated_aug_p; |
| 1729 |
if (cur_aug_p > end_aug_p) { |
| 1730 |
_dwarf_error(dbg, error, |
| 1731 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1732 |
return DW_DLV_ERROR; |
| 1733 |
} |
| 1734 |
} |
| 1735 |
break; |
| 1736 |
default: |
| 1737 |
_dwarf_error(dbg, error, |
| 1738 |
DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1739 |
return DW_DLV_ERROR; |
| 1740 |
|
| 1741 |
} |
| 1742 |
} |
| 1743 |
return DW_DLV_OK; |
| 1744 |
} |
| 1745 |
|
| 1746 |
/* Given augmentation character (the encoding) giving the |
| 1747 |
address format, read the address from input_field |
| 1748 |
and return an incremented value 1 past the input bytes of the |
| 1749 |
address. |
| 1750 |
Push the address read back thru the *addr pointer. |
| 1751 |
See LSB (Linux Standard Base) exception handling documents. */ |
| 1752 |
static int |
| 1753 |
_dwarf_read_encoded_ptr(Dwarf_Debug dbg, |
| 1754 |
Dwarf_Small * section_pointer, |
| 1755 |
Dwarf_Small * input_field, |
| 1756 |
int gnu_encoding, |
| 1757 |
Dwarf_Small * section_end, |
| 1758 |
Dwarf_Half address_size, |
| 1759 |
Dwarf_Unsigned * addr, |
| 1760 |
Dwarf_Small ** input_field_updated, |
| 1761 |
Dwarf_Error *error) |
| 1762 |
{ |
| 1763 |
int value_type = gnu_encoding & 0xf; |
| 1764 |
Dwarf_Small *input_field_original = input_field; |
| 1765 |
|
| 1766 |
if (gnu_encoding == 0xff) { |
| 1767 |
/* There is no data here. */ |
| 1768 |
|
| 1769 |
*addr = 0; |
| 1770 |
*input_field_updated = input_field; |
| 1771 |
/* Should we return DW_DLV_NO_ENTRY? */ |
| 1772 |
return DW_DLV_OK; |
| 1773 |
} |
| 1774 |
switch (value_type) { |
| 1775 |
case DW_EH_PE_absptr:{ |
| 1776 |
/* value_type is zero. Treat as pointer size of the object. |
| 1777 |
*/ |
| 1778 |
Dwarf_Unsigned ret_value = 0; |
| 1779 |
|
| 1780 |
READ_UNALIGNED_CK(dbg, ret_value, Dwarf_Unsigned, |
| 1781 |
input_field, address_size,error,section_end); |
| 1782 |
*addr = ret_value; |
| 1783 |
*input_field_updated = input_field + address_size; |
| 1784 |
} |
| 1785 |
break; |
| 1786 |
case DW_EH_PE_uleb128:{ |
| 1787 |
Dwarf_Unsigned val = 0; |
| 1788 |
|
| 1789 |
DECODE_LEB128_UWORD_CK(input_field,val,dbg,error,section_end); |
| 1790 |
*addr = val; |
| 1791 |
*input_field_updated = input_field; |
| 1792 |
} |
| 1793 |
break; |
| 1794 |
case DW_EH_PE_udata2:{ |
| 1795 |
Dwarf_Unsigned ret_value = 0; |
| 1796 |
|
| 1797 |
READ_UNALIGNED_CK(dbg, ret_value, Dwarf_Unsigned, |
| 1798 |
input_field, 2,error,section_end); |
| 1799 |
*addr = ret_value; |
| 1800 |
*input_field_updated = input_field + 2; |
| 1801 |
} |
| 1802 |
break; |
| 1803 |
|
| 1804 |
case DW_EH_PE_udata4:{ |
| 1805 |
Dwarf_Unsigned ret_value = 0; |
| 1806 |
|
| 1807 |
READ_UNALIGNED_CK(dbg, ret_value, Dwarf_Unsigned, |
| 1808 |
input_field, DWARF_32BIT_SIZE,error,section_end); |
| 1809 |
*addr = ret_value; |
| 1810 |
*input_field_updated = input_field + DWARF_32BIT_SIZE; |
| 1811 |
} |
| 1812 |
break; |
| 1813 |
|
| 1814 |
case DW_EH_PE_udata8:{ |
| 1815 |
Dwarf_Unsigned ret_value = 0; |
| 1816 |
|
| 1817 |
/* ASSERT: sizeof(Dwarf_Unsigned) == 8 */ |
| 1818 |
READ_UNALIGNED_CK(dbg, ret_value, Dwarf_Unsigned, |
| 1819 |
input_field, DWARF_64BIT_SIZE,error,section_end); |
| 1820 |
*addr = ret_value; |
| 1821 |
*input_field_updated = input_field + DWARF_64BIT_SIZE; |
| 1822 |
} |
| 1823 |
break; |
| 1824 |
|
| 1825 |
case DW_EH_PE_sleb128:{ |
| 1826 |
Dwarf_Signed val = 0; |
| 1827 |
|
| 1828 |
DECODE_LEB128_SWORD_CK(input_field,val,dbg,error,section_end); |
| 1829 |
*addr = (Dwarf_Unsigned) val; |
| 1830 |
*input_field_updated = input_field; |
| 1831 |
} |
| 1832 |
break; |
| 1833 |
case DW_EH_PE_sdata2:{ |
| 1834 |
Dwarf_Unsigned val = 0; |
| 1835 |
|
| 1836 |
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned, input_field, 2, |
| 1837 |
error,section_end); |
| 1838 |
SIGN_EXTEND(val, 2); |
| 1839 |
*addr = (Dwarf_Unsigned) val; |
| 1840 |
*input_field_updated = input_field + 2; |
| 1841 |
} |
| 1842 |
break; |
| 1843 |
|
| 1844 |
case DW_EH_PE_sdata4:{ |
| 1845 |
Dwarf_Unsigned val = 0; |
| 1846 |
|
| 1847 |
READ_UNALIGNED_CK(dbg, val, |
| 1848 |
Dwarf_Unsigned, input_field, |
| 1849 |
DWARF_32BIT_SIZE,error,section_end); |
| 1850 |
SIGN_EXTEND(val, DWARF_32BIT_SIZE); |
| 1851 |
*addr = (Dwarf_Unsigned) val; |
| 1852 |
*input_field_updated = input_field + DWARF_32BIT_SIZE; |
| 1853 |
} |
| 1854 |
break; |
| 1855 |
case DW_EH_PE_sdata8:{ |
| 1856 |
Dwarf_Unsigned val = 0; |
| 1857 |
|
| 1858 |
/* ASSERT: sizeof(Dwarf_Unsigned) == 8 */ |
| 1859 |
READ_UNALIGNED_CK(dbg, val, |
| 1860 |
Dwarf_Unsigned, input_field, |
| 1861 |
DWARF_64BIT_SIZE,error,section_end); |
| 1862 |
*addr = (Dwarf_Unsigned) val; |
| 1863 |
*input_field_updated = input_field + DWARF_64BIT_SIZE; |
| 1864 |
} |
| 1865 |
break; |
| 1866 |
default: |
| 1867 |
_dwarf_error(dbg, error, DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 1868 |
return DW_DLV_ERROR; |
| 1869 |
|
| 1870 |
}; |
| 1871 |
/* The ELF ABI for gnu does not document the meaning of |
| 1872 |
DW_EH_PE_pcrel, which is awkward. |
| 1873 |
It apparently means the value |
| 1874 |
we got above is pc-relative (meaning section-relative), |
| 1875 |
so we adjust the value. Section_pointer may be null |
| 1876 |
if it is known DW_EH_PE_pcrel cannot apply, |
| 1877 |
such as for .debug_frame or for an |
| 1878 |
address-range value. */ |
| 1879 |
if (section_pointer && ((gnu_encoding & 0x70) == |
| 1880 |
DW_EH_PE_pcrel)) { |
| 1881 |
/* Address (*addr) above is pc relative with respect to a |
| 1882 |
section. Add to the offset the base address (from elf) of |
| 1883 |
section and the distance of the field we are reading from |
| 1884 |
the section-beginning to get the actual address. */ |
| 1885 |
/* ASSERT: input_field_original >= section_pointer */ |
| 1886 |
Dwarf_Unsigned distance = |
| 1887 |
input_field_original - section_pointer; |
| 1888 |
*addr += dbg->de_debug_frame_eh_gnu.dss_addr + distance; |
| 1889 |
} |
| 1890 |
return DW_DLV_OK; |
| 1891 |
} |
| 1892 |
|
| 1893 |
/* All augmentation string checking done here now. |
| 1894 |
|
| 1895 |
For .eh_frame, gcc from 3.3 uses the z style, earlier used |
| 1896 |
only "eh" as augmentation. We don't yet handle |
| 1897 |
decoding .eh_frame with the z style extensions like L P. |
| 1898 |
_dwarf_gnu_aug_encodings() does handle L P. |
| 1899 |
|
| 1900 |
These are nasty heuristics, but then that's life |
| 1901 |
as augmentations are implementation specific. */ |
| 1902 |
/* ARGSUSED */ |
| 1903 |
enum Dwarf_augmentation_type |
| 1904 |
_dwarf_get_augmentation_type(Dwarf_Debug dbg, |
| 1905 |
Dwarf_Small * augmentation_string, |
| 1906 |
int is_gcc_eh_frame) |
| 1907 |
{ |
| 1908 |
enum Dwarf_augmentation_type t = aug_unknown; |
| 1909 |
char *ag_string = (char *) augmentation_string; |
| 1910 |
|
| 1911 |
(void)dbg; |
| 1912 |
if (!ag_string[0]) { |
| 1913 |
/* Empty string. We'll just guess that we know |
| 1914 |
what this means: |
| 1915 |
standard dwarf2/3 with no |
| 1916 |
implementation-defined fields. */ |
| 1917 |
t = aug_empty_string; |
| 1918 |
} else if (!strcmp(ag_string, DW_DEBUG_FRAME_AUGMENTER_STRING)) { |
| 1919 |
/* The string is "mti v1". Used internally at SGI, probably |
| 1920 |
never shipped. Replaced by "z". Treat like 'nothing |
| 1921 |
special'. */ |
| 1922 |
t = aug_irix_mti_v1; |
| 1923 |
} else if (ag_string[0] == 'z') { |
| 1924 |
/* If it's IRIX cc, z means aug_irix_exception_table. z1 z2 |
| 1925 |
were designed as for IRIX CC, but never implemented */ |
| 1926 |
/* If it's gcc, z may be any of several things. "z" or z |
| 1927 |
followed optionally followed by one or more of L R P, |
| 1928 |
each of which means a value may be present. |
| 1929 |
Should be in eh_frame |
| 1930 |
only, I think. */ |
| 1931 |
if (is_gcc_eh_frame) { |
| 1932 |
t = aug_gcc_eh_z; |
| 1933 |
} else if (!ag_string[1]) { |
| 1934 |
/* This is the normal IRIX C++ case, where there is an |
| 1935 |
offset into a table in each fde. The table being for |
| 1936 |
IRIX CC exception handling. */ |
| 1937 |
/* DW_CIE_AUGMENTER_STRING_V0 "z" */ |
| 1938 |
t = aug_irix_exception_table; |
| 1939 |
} /* Else unknown. */ |
| 1940 |
} else if (!strncmp(ag_string, "eh", 2)) { |
| 1941 |
/* gcc .eh_frame augmentation for egcs and gcc 2.x, at least |
| 1942 |
for x86. */ |
| 1943 |
t = aug_eh; |
| 1944 |
} else if (!strcmp(ag_string, "armcc+")) { |
| 1945 |
/* Arm uses this string to mean a bug in |
| 1946 |
in Arm compilers was fixed, changing to the standard |
| 1947 |
calculation of the CFA. See |
| 1948 |
http://sourceware.org/ml/gdb-patches/ |
| 1949 |
2006-12/msg00249.html |
| 1950 |
for details. */ |
| 1951 |
t = aug_armcc; |
| 1952 |
} else if (!strcmp(ag_string, "HC")) { |
| 1953 |
t = aug_metaware; |
| 1954 |
} else { |
| 1955 |
} |
| 1956 |
return t; |
| 1957 |
} |
| 1958 |
|
| 1959 |
/* Using augmentation, and version |
| 1960 |
read in the augmentation data for GNU eh. |
| 1961 |
|
| 1962 |
Return DW_DLV_OK if we succeeded, |
| 1963 |
DW_DLV_ERR if we fail. |
| 1964 |
|
| 1965 |
On success, update 'size_of_augmentation_data' with |
| 1966 |
the length of the fields that are part of augmentation (so the |
| 1967 |
caller can increment frame_ptr appropriately). |
| 1968 |
|
| 1969 |
'frame_ptr' points within section. |
| 1970 |
'section_end' points to end of section area of interest. |
| 1971 |
|
| 1972 |
*/ |
| 1973 |
/* ARGSUSED */ |
| 1974 |
static int |
| 1975 |
_dwarf_get_gcc_eh_augmentation(Dwarf_Debug dbg, |
| 1976 |
Dwarf_Small * frame_ptr, |
| 1977 |
Dwarf_Unsigned *size_of_augmentation_data, |
| 1978 |
enum Dwarf_augmentation_type augtype, |
| 1979 |
Dwarf_Small * section_ptr_end, char *augmentation, |
| 1980 |
Dwarf_Error *error) |
| 1981 |
{ |
| 1982 |
char *suffix = 0; |
| 1983 |
Dwarf_Unsigned augdata_size = 0; |
| 1984 |
|
| 1985 |
if (augtype == aug_gcc_eh_z) { |
| 1986 |
/* Has leading 'z'. */ |
| 1987 |
Dwarf_Unsigned leb128_length = 0; |
| 1988 |
|
| 1989 |
/* Dwarf_Unsigned eh_value = */ |
| 1990 |
SKIP_LEB128_LEN_CK(frame_ptr,leb128_length, |
| 1991 |
dbg,error,section_ptr_end); |
| 1992 |
augdata_size += leb128_length; |
| 1993 |
suffix = augmentation + 1; |
| 1994 |
} else { |
| 1995 |
/* Prefix is 'eh'. As in gcc 3.2. No suffix present |
| 1996 |
apparently. */ |
| 1997 |
suffix = augmentation + 2; |
| 1998 |
} |
| 1999 |
if (*suffix) { |
| 2000 |
/* We have no idea what this is as yet. |
| 2001 |
Some extensions beyond |
| 2002 |
dwarf exist which we do not yet handle. */ |
| 2003 |
_dwarf_error(dbg, error, DW_DLE_FRAME_AUGMENTATION_UNKNOWN); |
| 2004 |
return DW_DLV_ERROR; |
| 2005 |
|
| 2006 |
} |
| 2007 |
|
| 2008 |
*size_of_augmentation_data = augdata_size; |
| 2009 |
return DW_DLV_OK; |
| 2010 |
} |
| 2011 |
|
| 2012 |
/* To properly release all spaced used. |
| 2013 |
Earlier approaches (before July 15, 2005) |
| 2014 |
letting client do the dealloc directly left |
| 2015 |
some data allocated. |
| 2016 |
This is directly called by consumer code. |
| 2017 |
*/ |
| 2018 |
void |
| 2019 |
dwarf_dealloc_fde_cie_list(Dwarf_Debug dbg, |
| 2020 |
Dwarf_Cie * cie_data, |
| 2021 |
Dwarf_Signed cie_element_count, |
| 2022 |
Dwarf_Fde * fde_data, |
| 2023 |
Dwarf_Signed fde_element_count) |
| 2024 |
{ |
| 2025 |
Dwarf_Signed i = 0; |
| 2026 |
|
| 2027 |
for (i = 0; i < cie_element_count; ++i) { |
| 2028 |
Dwarf_Frame frame = cie_data[i]->ci_initial_table; |
| 2029 |
|
| 2030 |
if (frame) { |
| 2031 |
dwarf_dealloc(dbg, frame, DW_DLA_FRAME); |
| 2032 |
} |
| 2033 |
dwarf_dealloc(dbg, cie_data[i], DW_DLA_CIE); |
| 2034 |
} |
| 2035 |
for (i = 0; i < fde_element_count; ++i) { |
| 2036 |
dwarf_dealloc(dbg, fde_data[i], DW_DLA_FDE); |
| 2037 |
} |
| 2038 |
if (cie_data) { |
| 2039 |
dwarf_dealloc(dbg, cie_data, DW_DLA_LIST); |
| 2040 |
} |
| 2041 |
if (fde_data) { |
| 2042 |
dwarf_dealloc(dbg, fde_data, DW_DLA_LIST); |
| 2043 |
} |
| 2044 |
} |