00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "config.h"
00043 #include "dwarf_incl.h"
00044 #include "dwarf_die_deliv.h"
00045
00046 int
00047 dwarf_hasform(Dwarf_Attribute attr,
00048 Dwarf_Half form,
00049 Dwarf_Bool * return_bool, Dwarf_Error * error)
00050 {
00051 Dwarf_CU_Context cu_context;
00052
00053 if (attr == NULL) {
00054 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00055 return (DW_DLV_ERROR);
00056 }
00057
00058 cu_context = attr->ar_cu_context;
00059 if (cu_context == NULL) {
00060 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00061 return (DW_DLV_ERROR);
00062 }
00063
00064 if (cu_context->cc_dbg == NULL) {
00065 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00066 return (DW_DLV_ERROR);
00067 }
00068
00069 *return_bool = (attr->ar_attribute_form == form);
00070 return DW_DLV_OK;
00071 }
00072
00073
00074
00075
00076 int
00077 dwarf_whatform_direct(Dwarf_Attribute attr,
00078 Dwarf_Half * return_form, Dwarf_Error * error)
00079 {
00080 int res = dwarf_whatform(attr, return_form, error);
00081
00082 if (res != DW_DLV_OK) {
00083 return res;
00084 }
00085
00086 *return_form = attr->ar_attribute_form_direct;
00087 return (DW_DLV_OK);
00088 }
00089
00090 int
00091 dwarf_whatform(Dwarf_Attribute attr,
00092 Dwarf_Half * return_form, Dwarf_Error * error)
00093 {
00094 Dwarf_CU_Context cu_context;
00095
00096 if (attr == NULL) {
00097 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00098 return (DW_DLV_ERROR);
00099 }
00100
00101 cu_context = attr->ar_cu_context;
00102 if (cu_context == NULL) {
00103 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00104 return (DW_DLV_ERROR);
00105 }
00106
00107 if (cu_context->cc_dbg == NULL) {
00108 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00109 return (DW_DLV_ERROR);
00110 }
00111
00112 *return_form = attr->ar_attribute_form;
00113 return (DW_DLV_OK);
00114 }
00115
00116
00117
00118
00119
00120
00121
00122 int
00123 dwarf_whatattr(Dwarf_Attribute attr,
00124 Dwarf_Half * return_attr, Dwarf_Error * error)
00125 {
00126 Dwarf_CU_Context cu_context;
00127
00128 if (attr == NULL) {
00129 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00130 return (DW_DLV_ERROR);
00131 }
00132
00133 cu_context = attr->ar_cu_context;
00134 if (cu_context == NULL) {
00135 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00136 return (DW_DLV_ERROR);
00137 }
00138
00139 if (cu_context->cc_dbg == NULL) {
00140 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00141 return (DW_DLV_ERROR);
00142 }
00143
00144 *return_attr = (attr->ar_attribute);
00145 return DW_DLV_OK;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 int
00161 dwarf_formref(Dwarf_Attribute attr,
00162 Dwarf_Off * ret_offset, Dwarf_Error * error)
00163 {
00164 Dwarf_Debug dbg;
00165 Dwarf_Unsigned offset;
00166 Dwarf_CU_Context cu_context;
00167
00168
00169 if (attr == NULL) {
00170 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00171 return (DW_DLV_ERROR);
00172 }
00173
00174 cu_context = attr->ar_cu_context;
00175 if (cu_context == NULL) {
00176 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00177 return (DW_DLV_ERROR);
00178 }
00179
00180 if (cu_context->cc_dbg == NULL) {
00181 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00182 return (DW_DLV_ERROR);
00183 }
00184 dbg = cu_context->cc_dbg;
00185
00186 switch (attr->ar_attribute_form) {
00187
00188 case DW_FORM_ref1:
00189 offset = *(Dwarf_Small *) attr->ar_debug_info_ptr;
00190 break;
00191
00192 case DW_FORM_ref2:
00193 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00194 attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
00195 break;
00196
00197 case DW_FORM_ref4:
00198 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00199 attr->ar_debug_info_ptr, sizeof(Dwarf_ufixed));
00200 break;
00201
00202 case DW_FORM_ref8:
00203 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00204 attr->ar_debug_info_ptr, sizeof(Dwarf_Unsigned));
00205 break;
00206
00207 case DW_FORM_ref_udata:
00208 offset = _dwarf_decode_u_leb128(attr->ar_debug_info_ptr, NULL);
00209 break;
00210
00211 default:
00212 _dwarf_error(dbg, error, DW_DLE_BAD_REF_FORM);
00213 return (DW_DLV_ERROR);
00214 }
00215
00216
00217
00218 if (offset >= cu_context->cc_length +
00219 cu_context->cc_length_size + cu_context->cc_extension_size) {
00220 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
00221 return (DW_DLV_ERROR);
00222 }
00223
00224 *ret_offset = (offset);
00225 return DW_DLV_OK;
00226 }
00227
00228
00229
00230
00231
00232
00233
00234 int
00235 dwarf_global_formref(Dwarf_Attribute attr,
00236 Dwarf_Off * ret_offset, Dwarf_Error * error)
00237 {
00238 Dwarf_Debug dbg;
00239 Dwarf_Unsigned offset;
00240 Dwarf_Addr ref_addr;
00241 Dwarf_CU_Context cu_context;
00242
00243 if (attr == NULL) {
00244 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00245 return (DW_DLV_ERROR);
00246 }
00247
00248 cu_context = attr->ar_cu_context;
00249 if (cu_context == NULL) {
00250 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00251 return (DW_DLV_ERROR);
00252 }
00253
00254 if (cu_context->cc_dbg == NULL) {
00255 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00256 return (DW_DLV_ERROR);
00257 }
00258 dbg = cu_context->cc_dbg;
00259
00260 switch (attr->ar_attribute_form) {
00261
00262 case DW_FORM_ref1:
00263 offset = *(Dwarf_Small *) attr->ar_debug_info_ptr;
00264 goto fixoffset;
00265
00266 case DW_FORM_ref2:
00267 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00268 attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
00269 goto fixoffset;
00270
00271 case DW_FORM_ref4:
00272 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00273 attr->ar_debug_info_ptr, sizeof(Dwarf_ufixed));
00274 goto fixoffset;
00275
00276 case DW_FORM_ref8:
00277 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00278 attr->ar_debug_info_ptr, sizeof(Dwarf_Unsigned));
00279 goto fixoffset;
00280
00281 case DW_FORM_ref_udata:
00282 offset = _dwarf_decode_u_leb128(attr->ar_debug_info_ptr, NULL);
00283
00284 fixoffset:
00285
00286
00287
00288 if (offset >= cu_context->cc_length +
00289 cu_context->cc_length_size +
00290 cu_context->cc_extension_size) {
00291 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
00292 return (DW_DLV_ERROR);
00293 }
00294
00295
00296 offset += cu_context->cc_debug_info_offset;
00297 break;
00298
00299 case DW_FORM_ref_addr:
00300
00301
00302 READ_UNALIGNED(dbg, ref_addr, Dwarf_Addr,
00303 attr->ar_debug_info_ptr,
00304 cu_context->cc_length_size);
00305 offset = ref_addr;
00306 break;
00307 default:
00308 _dwarf_error(dbg, error, DW_DLE_BAD_REF_FORM);
00309 return (DW_DLV_ERROR);
00310 }
00311
00312
00313
00314 *ret_offset = (offset);
00315 return DW_DLV_OK;
00316 }
00317
00318
00319 int
00320 dwarf_formaddr(Dwarf_Attribute attr,
00321 Dwarf_Addr * return_addr, Dwarf_Error * error)
00322 {
00323 Dwarf_Debug dbg;
00324 Dwarf_Addr ret_addr;
00325 Dwarf_CU_Context cu_context;
00326
00327 if (attr == NULL) {
00328 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00329 return (DW_DLV_ERROR);
00330 }
00331
00332 cu_context = attr->ar_cu_context;
00333 if (cu_context == NULL) {
00334 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00335 return (DW_DLV_ERROR);
00336 }
00337
00338 if (cu_context->cc_dbg == NULL) {
00339 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00340 return (DW_DLV_ERROR);
00341 }
00342 dbg = cu_context->cc_dbg;
00343
00344 if (attr->ar_attribute_form == DW_FORM_addr
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 ) {
00355
00356 READ_UNALIGNED(dbg, ret_addr, Dwarf_Addr,
00357 attr->ar_debug_info_ptr, dbg->de_pointer_size);
00358 *return_addr = ret_addr;
00359 return (DW_DLV_OK);
00360 }
00361
00362 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
00363 return (DW_DLV_ERROR);
00364 }
00365
00366
00367 int
00368 dwarf_formflag(Dwarf_Attribute attr,
00369 Dwarf_Bool * ret_bool, Dwarf_Error * error)
00370 {
00371 Dwarf_CU_Context cu_context;
00372
00373 if (attr == NULL) {
00374 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00375 return (DW_DLV_ERROR);
00376 }
00377
00378 cu_context = attr->ar_cu_context;
00379 if (cu_context == NULL) {
00380 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00381 return (DW_DLV_ERROR);
00382 }
00383
00384 if (cu_context->cc_dbg == NULL) {
00385 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00386 return (DW_DLV_ERROR);
00387 }
00388
00389 if (attr->ar_attribute_form == DW_FORM_flag) {
00390 *ret_bool = (*(Dwarf_Small *) attr->ar_debug_info_ptr != 0);
00391 return (DW_DLV_OK);
00392 }
00393 _dwarf_error(cu_context->cc_dbg, error, DW_DLE_ATTR_FORM_BAD);
00394 return (DW_DLV_ERROR);
00395 }
00396
00397
00398 int
00399 dwarf_formudata(Dwarf_Attribute attr,
00400 Dwarf_Unsigned * return_uval, Dwarf_Error * error)
00401 {
00402 Dwarf_Unsigned ret_value;
00403 Dwarf_Debug dbg;
00404 Dwarf_CU_Context cu_context;
00405
00406 if (attr == NULL) {
00407 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00408 return (DW_DLV_ERROR);
00409 }
00410
00411
00412 cu_context = attr->ar_cu_context;
00413 if (cu_context == NULL) {
00414 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00415 return (DW_DLV_ERROR);
00416 }
00417
00418 dbg = cu_context->cc_dbg;
00419 if (dbg == NULL) {
00420 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00421 return (DW_DLV_ERROR);
00422 }
00423
00424 switch (attr->ar_attribute_form) {
00425
00426 case DW_FORM_data1:
00427 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00428 attr->ar_debug_info_ptr, sizeof(Dwarf_Small));
00429 *return_uval = ret_value;
00430 return DW_DLV_OK;
00431
00432 case DW_FORM_data2:{
00433 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00434 attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
00435 *return_uval = ret_value;
00436 return DW_DLV_OK;
00437 }
00438
00439 case DW_FORM_data4:{
00440 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00441 attr->ar_debug_info_ptr,
00442 sizeof(Dwarf_ufixed));
00443 *return_uval = ret_value;
00444 return DW_DLV_OK;
00445 }
00446
00447 case DW_FORM_data8:{
00448 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00449 attr->ar_debug_info_ptr,
00450 sizeof(Dwarf_Unsigned));
00451 *return_uval = ret_value;
00452 return DW_DLV_OK;
00453 }
00454
00455 case DW_FORM_udata:
00456 ret_value =
00457 (_dwarf_decode_u_leb128(attr->ar_debug_info_ptr, NULL));
00458 *return_uval = ret_value;
00459 return DW_DLV_OK;
00460
00461
00462
00463
00464
00465
00466 default:
00467 break;
00468 }
00469 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
00470 return (DW_DLV_ERROR);
00471 }
00472
00473
00474 int
00475 dwarf_formsdata(Dwarf_Attribute attr,
00476 Dwarf_Signed * return_sval, Dwarf_Error * error)
00477 {
00478 Dwarf_Signed ret_value;
00479 Dwarf_Debug dbg;
00480 Dwarf_CU_Context cu_context;
00481
00482 if (attr == NULL) {
00483 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00484 return (DW_DLV_ERROR);
00485 }
00486
00487 cu_context = attr->ar_cu_context;
00488 if (cu_context == NULL) {
00489 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00490 return (DW_DLV_ERROR);
00491 }
00492
00493 dbg = cu_context->cc_dbg;
00494 if (dbg == NULL) {
00495 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00496 return (DW_DLV_ERROR);
00497 }
00498
00499 switch (attr->ar_attribute_form) {
00500
00501 case DW_FORM_data1:
00502 *return_sval = (*(Dwarf_Sbyte *) attr->ar_debug_info_ptr);
00503 return DW_DLV_OK;
00504
00505 case DW_FORM_data2:{
00506 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00507 attr->ar_debug_info_ptr,
00508 sizeof(Dwarf_Shalf));
00509 *return_sval = (Dwarf_Shalf) ret_value;
00510 return DW_DLV_OK;
00511
00512 }
00513
00514 case DW_FORM_data4:{
00515 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00516 attr->ar_debug_info_ptr,
00517 sizeof(Dwarf_sfixed));
00518 *return_sval = (Dwarf_Sword) ret_value;
00519 return DW_DLV_OK;
00520 }
00521
00522 case DW_FORM_data8:{
00523 READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
00524 attr->ar_debug_info_ptr,
00525 sizeof(Dwarf_Signed));
00526 *return_sval = (Dwarf_Signed) ret_value;
00527 return DW_DLV_OK;
00528 }
00529
00530 case DW_FORM_sdata:
00531 ret_value =
00532 (_dwarf_decode_s_leb128(attr->ar_debug_info_ptr, NULL));
00533 *return_sval = ret_value;
00534 return DW_DLV_OK;
00535
00536
00537
00538
00539
00540
00541 default:
00542 break;
00543 }
00544 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
00545 return (DW_DLV_ERROR);
00546 }
00547
00548
00549 int
00550 dwarf_formblock(Dwarf_Attribute attr,
00551 Dwarf_Block ** return_block, Dwarf_Error * error)
00552 {
00553 Dwarf_CU_Context cu_context;
00554 Dwarf_Debug dbg;
00555 Dwarf_Unsigned length;
00556 Dwarf_Small *data;
00557 Dwarf_Word leb128_length;
00558 Dwarf_Block *ret_block;
00559
00560 if (attr == NULL) {
00561 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00562 return (DW_DLV_ERROR);
00563 }
00564
00565 cu_context = attr->ar_cu_context;
00566 if (cu_context == NULL) {
00567 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00568 return (DW_DLV_ERROR);
00569 }
00570
00571 if (cu_context->cc_dbg == NULL) {
00572 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00573 return (DW_DLV_ERROR);
00574 }
00575 dbg = cu_context->cc_dbg;
00576
00577 switch (attr->ar_attribute_form) {
00578
00579 case DW_FORM_block1:
00580 length = *(Dwarf_Small *) attr->ar_debug_info_ptr;
00581 data = attr->ar_debug_info_ptr + sizeof(Dwarf_Small);
00582 break;
00583
00584 case DW_FORM_block2:
00585 READ_UNALIGNED(dbg, length, Dwarf_Unsigned,
00586 attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
00587 data = attr->ar_debug_info_ptr + sizeof(Dwarf_Half);
00588 break;
00589
00590 case DW_FORM_block4:
00591 READ_UNALIGNED(dbg, length, Dwarf_Unsigned,
00592 attr->ar_debug_info_ptr, sizeof(Dwarf_ufixed));
00593 data = attr->ar_debug_info_ptr + sizeof(Dwarf_ufixed);
00594 break;
00595
00596 case DW_FORM_block:
00597 length = _dwarf_decode_u_leb128(attr->ar_debug_info_ptr,
00598 &leb128_length);
00599 data = attr->ar_debug_info_ptr + leb128_length;
00600 break;
00601
00602 default:
00603 _dwarf_error(cu_context->cc_dbg, error, DW_DLE_ATTR_FORM_BAD);
00604 return (DW_DLV_ERROR);
00605 }
00606
00607
00608 if (attr->ar_debug_info_ptr + length >=
00609 dbg->de_debug_info + cu_context->cc_debug_info_offset +
00610 cu_context->cc_length + cu_context->cc_length_size +
00611 cu_context->cc_extension_size) {
00612 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
00613 return (DW_DLV_ERROR);
00614 }
00615
00616 ret_block = (Dwarf_Block *) _dwarf_get_alloc(dbg, DW_DLA_BLOCK, 1);
00617 if (ret_block == NULL) {
00618 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
00619 return (DW_DLV_ERROR);
00620 }
00621
00622 ret_block->bl_len = length;
00623 ret_block->bl_data = (Dwarf_Ptr) data;
00624 ret_block->bl_from_loclist = 0;
00625 ret_block->bl_section_offset = data - dbg->de_debug_info;
00626
00627
00628 *return_block = ret_block;
00629 return (DW_DLV_OK);
00630 }
00631
00632
00633 int
00634 dwarf_formstring(Dwarf_Attribute attr,
00635 char **return_str, Dwarf_Error * error)
00636 {
00637 Dwarf_CU_Context cu_context;
00638 Dwarf_Debug dbg;
00639 Dwarf_Unsigned offset;
00640 int res;
00641
00642 if (attr == NULL) {
00643 _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
00644 return (DW_DLV_ERROR);
00645 }
00646
00647 cu_context = attr->ar_cu_context;
00648 if (cu_context == NULL) {
00649 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
00650 return (DW_DLV_ERROR);
00651 }
00652
00653 if (cu_context->cc_dbg == NULL) {
00654 _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
00655 return (DW_DLV_ERROR);
00656 }
00657 dbg = cu_context->cc_dbg;
00658
00659 if (attr->ar_attribute_form == DW_FORM_string) {
00660
00661 void *begin = attr->ar_debug_info_ptr;
00662
00663 if (0 == dbg->de_assume_string_in_bounds) {
00664
00665
00666 void *end = dbg->de_debug_info +
00667 cu_context->cc_debug_info_offset +
00668 cu_context->cc_length + cu_context->cc_length_size +
00669 cu_context->cc_extension_size;
00670 if (0 == _dwarf_string_valid(begin, end)) {
00671 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
00672 return (DW_DLV_ERROR);
00673 }
00674 }
00675 *return_str = (char *) (begin);
00676 return DW_DLV_OK;
00677 }
00678
00679 if (attr->ar_attribute_form == DW_FORM_strp) {
00680 READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
00681 attr->ar_debug_info_ptr,
00682 cu_context->cc_length_size);
00683
00684 res =
00685 _dwarf_load_section(dbg,
00686 dbg->de_debug_str_index,
00687 &dbg->de_debug_str, error);
00688 if (res != DW_DLV_OK) {
00689 return res;
00690 }
00691
00692 *return_str = (char *) (dbg->de_debug_str + offset);
00693 return DW_DLV_OK;
00694 }
00695
00696 _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
00697 return (DW_DLV_ERROR);
00698 }