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 #include "globals.h"
00035 #include "dwarf_names.h"
00036
00037 static void get_attr_value(Dwarf_Debug dbg, Dwarf_Half tag,
00038 Dwarf_Attribute attrib, char **srcfiles,
00039 Dwarf_Signed cnt);
00040 static void print_attribute(Dwarf_Debug dbg, Dwarf_Die die,
00041 Dwarf_Half attr,
00042 Dwarf_Attribute actual_addr,
00043 boolean print_information, char **srcfiles,
00044 Dwarf_Signed cnt);
00045 static void get_location_list(Dwarf_Debug dbg, Dwarf_Die die,
00046 Dwarf_Attribute attr);
00047 static int tag_attr_combination(Dwarf_Half tag, Dwarf_Half attr);
00048
00049 static int indent_level = 0;
00050 static boolean local_symbols_already_began = FALSE;
00051
00052 Dwarf_Off fde_offset_for_cu_low = DW_DLV_BADOFFSET;
00053 Dwarf_Off fde_offset_for_cu_high = DW_DLV_BADOFFSET;
00054
00055
00056
00057
00058 #define DIE_STACK_SIZE 50
00059 static Dwarf_Die die_stack[DIE_STACK_SIZE];
00060
00061
00062 string attrib_buf;
00063 int attrib_bufsiz;
00064
00065 #define PUSH_DIE_STACK(x) { die_stack[indent_level] = x; }
00066 #define POP_DIE_STACK { die_stack[indent_level] = 0; }
00067
00068 #include "_tag_tree_table.c"
00069
00070
00071
00072
00073
00074
00075
00076 #define MAX_CHECKED_TAG_ID 0x35
00077 static int
00078 tag_tree_combination(Dwarf_Half tag_parent, Dwarf_Half tag_child)
00079 {
00080 if (tag_parent > 0 && tag_parent <= MAX_CHECKED_TAG_ID
00081 && tag_child > 0 && tag_child <= MAX_CHECKED_TAG_ID) {
00082 return ((tag_tree_combination_table[tag_parent]
00083 [tag_child / 0x20]
00084 & (1 << (tag_child % 0x20))) > 0 ? TRUE : FALSE);
00085 } else
00086 return (FALSE);
00087 }
00088
00089
00090 extern void
00091 print_die_and_children(Dwarf_Debug dbg, Dwarf_Die in_die_in,
00092 char **srcfiles, Dwarf_Signed cnt)
00093 {
00094 Dwarf_Die child;
00095 Dwarf_Die sibling;
00096 Dwarf_Error err;
00097 int tres;
00098 int cdres;
00099 Dwarf_Die in_die = in_die_in;
00100
00101 for (;;) {
00102 PUSH_DIE_STACK(in_die);
00103
00104 if (check_tag_tree) {
00105 tag_tree_result.checks++;
00106 if (indent_level == 0) {
00107 Dwarf_Half tag;
00108
00109 tres = dwarf_tag(in_die, &tag, &err);
00110 if (tres != DW_DLV_OK) {
00111 tag_tree_result.errors++;
00112 DWARF_CHECK_ERROR
00113 ("Tag-tree root is not DW_TAG_compile_unit")
00114 } else if (tag == DW_TAG_compile_unit) {
00115
00116 } else {
00117 tag_tree_result.errors++;
00118 DWARF_CHECK_ERROR
00119 ("tag-tree root is not DW_TAG_compile_unit")
00120 }
00121 } else {
00122 Dwarf_Half tag_parent, tag_child;
00123 int pres;
00124 int cres;
00125
00126 pres =
00127 dwarf_tag(die_stack[indent_level - 1], &tag_parent,
00128 &err);
00129 cres = dwarf_tag(in_die, &tag_child, &err);
00130 if (pres != DW_DLV_OK)
00131 tag_parent = 0;
00132 if (cres != DW_DLV_OK)
00133 tag_child = 0;
00134 if (pres != cres) {
00135 if (cres == DW_DLV_OK) {
00136 DWARF_CHECK_ERROR2(get_TAG_name(dbg, tag_child),
00137 "Tag-tree relation is not valid.")
00138 } else {
00139 DWARF_CHECK_ERROR2("<child has no name>",
00140 "Tag-tree relation is not valid..")
00141 }
00142 } else if (pres != DW_DLV_OK) {
00143 if (cres == DW_DLV_OK) {
00144 DWARF_CHECK_ERROR2(get_TAG_name(dbg, tag_child),
00145 "Tag-tree Relation is not valid...")
00146 } else {
00147 DWARF_CHECK_ERROR2("<child has no name>",
00148 "Tag-tree relation is not valid....")
00149 }
00150 } else if (tag_tree_combination(tag_parent, tag_child)) {
00151
00152 } else {
00153 DWARF_CHECK_ERROR2(get_TAG_name(dbg, tag_child),
00154 "tag-tree relation is not valid")
00155 }
00156 }
00157 }
00158
00159
00160 print_one_die(dbg, in_die, info_flag, srcfiles, cnt);
00161
00162 cdres = dwarf_child(in_die, &child, &err);
00163
00164 if (cdres == DW_DLV_OK) {
00165 indent_level++;
00166 print_die_and_children(dbg, child, srcfiles, cnt);
00167 indent_level--;
00168 if (indent_level == 0)
00169 local_symbols_already_began = FALSE;
00170 dwarf_dealloc(dbg, child, DW_DLA_DIE);
00171 } else if (cdres == DW_DLV_ERROR) {
00172 print_error(dbg, "dwarf_child", cdres, err);
00173 }
00174
00175 cdres = dwarf_siblingof(dbg, in_die, &sibling, &err);
00176 if (cdres == DW_DLV_OK) {
00177
00178
00179
00180
00181 } else if (cdres == DW_DLV_ERROR) {
00182 print_error(dbg, "dwarf_siblingof", cdres, err);
00183 }
00184
00185
00186
00187
00188 POP_DIE_STACK;
00189 if (in_die != in_die_in) {
00190
00191
00192
00193 dwarf_dealloc(dbg, in_die, DW_DLA_DIE);
00194 }
00195 if (cdres == DW_DLV_OK) {
00196
00197 in_die = sibling;
00198 } else {
00199
00200
00201 break;
00202 }
00203 }
00204 return;
00205 }
00206
00207 #define SPACE(x) { register int i; for (i=0;i<x;i++) putchar(' '); }
00208
00209
00210
00211 void
00212 print_one_die(Dwarf_Debug dbg, Dwarf_Die die, boolean print_information,
00213 char **srcfiles, Dwarf_Signed cnt)
00214 {
00215 Dwarf_Signed i;
00216 Dwarf_Off offset, overall_offset;
00217 string tagname;
00218 Dwarf_Half tag;
00219 Dwarf_Signed atcnt;
00220 Dwarf_Attribute *atlist;
00221 int tres;
00222 int ores;
00223 int atres;
00224
00225 tres = dwarf_tag(die, &tag, &err);
00226 if (tres != DW_DLV_OK) {
00227 print_error(dbg, "accessing tag of die!", tres, err);
00228 }
00229 tagname = get_TAG_name(dbg, tag);
00230 ores = dwarf_dieoffset(die, &overall_offset, &err);
00231 if (ores != DW_DLV_OK) {
00232 print_error(dbg, "dwarf_dieoffset", ores, err);
00233 }
00234 ores = dwarf_die_CU_offset(die, &offset, &err);
00235 if (ores != DW_DLV_OK) {
00236 print_error(dbg, "dwarf_die_CU_offset", ores, err);
00237 }
00238
00239 if (!dst_format && print_information) {
00240 if (indent_level == 0) {
00241 if (dense)
00242 printf("\n");
00243 else {
00244 printf
00245 ("\nCOMPILE_UNIT<header overall offset = %llu>:\n",
00246 overall_offset - offset);
00247 }
00248 } else if (local_symbols_already_began == FALSE &&
00249 indent_level == 1 && !dense) {
00250 printf("\nLOCAL_SYMBOLS:\n");
00251 local_symbols_already_began = TRUE;
00252 }
00253 if (dense) {
00254 SPACE(2 * indent_level);
00255 if (indent_level == 0) {
00256 printf("<%d><%llu+%llu><%s>", indent_level,
00257 overall_offset - offset, offset, tagname);
00258 } else {
00259 printf("<%d><%llu><%s>", indent_level, offset, tagname);
00260 }
00261 } else {
00262 printf("<%d><%5llu>\t%s\n", indent_level, offset, tagname);
00263 }
00264 }
00265
00266 atres = dwarf_attrlist(die, &atlist, &atcnt, &err);
00267 if (atres == DW_DLV_ERROR) {
00268 print_error(dbg, "dwarf_attrlist", atres, err);
00269 } else if (atres == DW_DLV_NO_ENTRY) {
00270
00271 atcnt = 0;
00272 }
00273
00274
00275 for (i = 0; i < atcnt; i++) {
00276 Dwarf_Half attr;
00277 int ares;
00278
00279 ares = dwarf_whatattr(atlist[i], &attr, &err);
00280 if (ares == DW_DLV_OK) {
00281 print_attribute(dbg, die, attr,
00282 atlist[i],
00283 print_information, srcfiles, cnt);
00284 } else {
00285 print_error(dbg, "dwarf_whatattr entry missing", ares, err);
00286 }
00287 }
00288
00289 for (i = 0; i < atcnt; i++) {
00290 dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
00291 }
00292 if (atres == DW_DLV_OK) {
00293 dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
00294 }
00295
00296 if (dense && print_information) {
00297 printf("\n\n");
00298 }
00299 return;
00300 }
00301
00302
00303 static void
00304 print_attribute(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Half attr,
00305 Dwarf_Attribute attr_in,
00306 boolean print_information,
00307 char **srcfiles, Dwarf_Signed cnt)
00308 {
00309 Dwarf_Attribute attrib;
00310 Dwarf_Signed sval;
00311 string atname;
00312 string valname;
00313 int tres;
00314 int vres;
00315 Dwarf_Half tag;
00316
00317 atname = get_AT_name(dbg, attr);
00318
00319
00320
00321 attrib = attr_in;
00322
00323
00324
00325
00326
00327 tres = dwarf_tag(die, &tag, &err);
00328 if (tres == DW_DLV_ERROR) {
00329 tag = 0;
00330 } else if (tres == DW_DLV_NO_ENTRY) {
00331 tag = 0;
00332 } else {
00333
00334 }
00335 if (check_attr_tag) {
00336 attr_tag_result.checks++;
00337 if (tres == DW_DLV_ERROR) {
00338 attr_tag_result.errors++;
00339 DWARF_CHECK_ERROR2(get_AT_name(dbg, attr),
00340 "make sure of the tag-attr combination..")
00341 } else if (tres == DW_DLV_NO_ENTRY) {
00342 attr_tag_result.errors++;
00343 DWARF_CHECK_ERROR2(get_AT_name(dbg, attr),
00344 "make sure of the tag-attr combination..")
00345 } else if (tag_attr_combination(tag, attr)) {
00346
00347 } else {
00348 attr_tag_result.errors++;
00349 DWARF_CHECK_ERROR2(get_AT_name(dbg, attr),
00350 "make sure of the tag-attr combination")
00351 }
00352 }
00353
00354 switch (attr) {
00355 case DW_AT_language:
00356 vres = dwarf_formsdata(attrib, &sval, &err);
00357 if (vres != DW_DLV_OK) {
00358 sval = -1;
00359 }
00360 valname = get_LANG_name(dbg, sval);
00361 break;
00362 case DW_AT_accessibility:
00363 vres = dwarf_formsdata(attrib, &sval, &err);
00364 if (vres != DW_DLV_OK) {
00365 sval = -1;
00366 }
00367 valname = get_ACCESS_name(dbg, sval);
00368 break;
00369 case DW_AT_visibility:
00370 vres = dwarf_formsdata(attrib, &sval, &err);
00371 if (vres != DW_DLV_OK) {
00372 sval = -1;
00373 }
00374 valname = get_VIS_name(dbg, sval);
00375 break;
00376 case DW_AT_virtuality:
00377 vres = dwarf_formsdata(attrib, &sval, &err);
00378 if (vres != DW_DLV_OK) {
00379 sval = -1;
00380 }
00381 valname = get_VIRTUALITY_name(dbg, sval);
00382 break;
00383 case DW_AT_identifier_case:
00384 vres = dwarf_formsdata(attrib, &sval, &err);
00385 if (vres != DW_DLV_OK) {
00386 sval = -1;
00387 }
00388 valname = get_ID_name(dbg, sval);
00389 break;
00390 case DW_AT_inline:
00391 vres = dwarf_formsdata(attrib, &sval, &err);
00392 if (vres != DW_DLV_OK) {
00393 sval = -1;
00394 }
00395 valname = get_INL_name(dbg, sval);
00396 break;
00397 case DW_AT_encoding:
00398 vres = dwarf_formsdata(attrib, &sval, &err);
00399 if (vres != DW_DLV_OK) {
00400 sval = -1;
00401 }
00402 valname = get_ATE_name(dbg, sval);
00403 break;
00404 case DW_AT_ordering:
00405 vres = dwarf_formsdata(attrib, &sval, &err);
00406 if (vres != DW_DLV_OK) {
00407 sval = -1;
00408 }
00409 valname = get_ORD_name(dbg, sval);
00410 break;
00411 case DW_AT_calling_convention:
00412 vres = dwarf_formsdata(attrib, &sval, &err);
00413 if (vres != DW_DLV_OK) {
00414 sval = -1;
00415 }
00416 valname = get_CC_name(dbg, sval);
00417 break;
00418 case DW_AT_location:
00419 case DW_AT_data_member_location:
00420 case DW_AT_vtable_elem_location:
00421 case DW_AT_string_length:
00422 case DW_AT_return_addr:
00423 case DW_AT_use_location:
00424 case DW_AT_static_link:
00425 case DW_AT_frame_base:
00426
00427 get_location_list(dbg, die, attrib);
00428 valname = attrib_buf;
00429 break;
00430 default:
00431 get_attr_value(dbg, tag, attrib, srcfiles, cnt);
00432 valname = attrib_buf;
00433 break;
00434 }
00435 if (print_information) {
00436 if (dense)
00437 printf(" %s<%s>", atname, valname);
00438 else
00439 printf("\t\t%-28s%s\n", atname, valname);
00440 }
00441 }
00442
00443
00444
00445 static int
00446 _dwarf_print_one_locdesc(Dwarf_Debug dbg,
00447 Dwarf_Locdesc * llbuf,
00448 char *start_buf, char **out_buf)
00449 {
00450 char *p = start_buf;
00451 Dwarf_Locdesc *locd;
00452 Dwarf_Half no_of_ops = 0;
00453 string op_name;
00454 int i;
00455
00456 if (verbose || llbuf->ld_from_loclist) {
00457 sprintf(p, "<lowpc=0x%llx>",
00458 (unsigned long long) llbuf->ld_lopc);
00459 p += strlen(p);
00460 sprintf(p, "<highpc=0x%llx>",
00461 (unsigned long long) llbuf->ld_hipc);
00462 p += strlen(p);
00463 if (verbose) {
00464 sprintf(p, "<from %s offset 0x%llx>",
00465 llbuf->
00466 ld_from_loclist ? ".debug_loc" : ".debug_info",
00467 (unsigned long long) llbuf->ld_section_offset);
00468 p += strlen(p);
00469 }
00470 }
00471
00472
00473 locd = llbuf;
00474 no_of_ops = llbuf->ld_cents;
00475 for (i = 0; i < no_of_ops; i++) {
00476 Dwarf_Small op;
00477 Dwarf_Unsigned opd1, opd2;
00478
00479 if (i > 0)
00480 *p++ = ' ';
00481
00482 op = locd->ld_s[i].lr_atom;
00483 if (op > DW_OP_nop) {
00484 print_error(dbg, "dwarf_op unexpected value", DW_DLV_OK,
00485 err);
00486 return DW_DLV_ERROR;
00487 }
00488 op_name = get_OP_name(dbg, op);
00489 strcpy(p, op_name);
00490 p += strlen(op_name);
00491 opd1 = locd->ld_s[i].lr_number;
00492 if (op >= DW_OP_breg0 && op <= DW_OP_breg31) {
00493 sprintf(p, "%+lld", (Dwarf_Signed) opd1);
00494 p += strlen(p);
00495 } else {
00496 switch (op) {
00497 case DW_OP_addr:
00498 sprintf(p, " %#llx", opd1);
00499 p += strlen(p);
00500 break;
00501 case DW_OP_const1s:
00502 case DW_OP_const2s:
00503 case DW_OP_const4s:
00504 case DW_OP_const8s:
00505 case DW_OP_consts:
00506 case DW_OP_skip:
00507 case DW_OP_bra:
00508 case DW_OP_fbreg:
00509 sprintf(p, " %lld", (Dwarf_Signed) opd1);
00510 p += strlen(p);
00511 break;
00512 case DW_OP_const1u:
00513 case DW_OP_const2u:
00514 case DW_OP_const4u:
00515 case DW_OP_const8u:
00516 case DW_OP_constu:
00517 case DW_OP_pick:
00518 case DW_OP_plus_uconst:
00519 case DW_OP_regx:
00520 case DW_OP_piece:
00521 case DW_OP_deref_size:
00522 case DW_OP_xderef_size:
00523 sprintf(p, " %llu", opd1);
00524 p += strlen(p);
00525 break;
00526 case DW_OP_bregx:
00527 sprintf(p, "%llu", opd1);
00528 p += strlen(p);
00529 opd2 = locd->ld_s[i].lr_number2;
00530 sprintf(p, "%+lld", (Dwarf_Signed) opd2);
00531 p += strlen(p);
00532 break;
00533 default:
00534 break;
00535 }
00536 }
00537 }
00538
00539 *out_buf = p;
00540 return DW_DLV_OK;
00541 }
00542
00543
00544
00545
00546
00547 static void
00548 get_location_list(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Attribute attr)
00549 {
00550 Dwarf_Locdesc *llbuf = 0;
00551 Dwarf_Locdesc **llbufarray = 0;
00552 Dwarf_Signed no_of_elements;
00553 Dwarf_Error err;
00554 int i;
00555 string p;
00556 int lres;
00557 int llent = 0;
00558
00559 if (use_old_dwarf_loclist) {
00560 char *buf_out;
00561
00562 lres = dwarf_loclist(attr, &llbuf, &no_of_elements, &err);
00563 if (lres == DW_DLV_ERROR)
00564 print_error(dbg, "dwarf_loclist", lres, err);
00565 if (lres == DW_DLV_NO_ENTRY)
00566 return;
00567
00568 _dwarf_print_one_locdesc(dbg, llbuf, attrib_buf, &buf_out);
00569 dwarf_dealloc(dbg, llbuf->ld_s, DW_DLA_LOC_BLOCK);
00570 dwarf_dealloc(dbg, llbuf, DW_DLA_LOCDESC);
00571 return;
00572 }
00573
00574
00575
00576
00577 lres = dwarf_loclist_n(attr, &llbufarray, &no_of_elements, &err);
00578 if (lres == DW_DLV_ERROR)
00579 print_error(dbg, "dwarf_loclist", lres, err);
00580 if (lres == DW_DLV_NO_ENTRY)
00581 return;
00582 p = attrib_buf;
00583
00584 for (llent = 0; llent < no_of_elements; ++llent) {
00585 char *buf_out;
00586
00587 llbuf = llbufarray[llent];
00588 if (!dense && llbuf->ld_from_loclist) {
00589 sprintf(p, "[%2d]", llent);
00590 p += strlen(p);
00591 }
00592 lres = _dwarf_print_one_locdesc(dbg, llbuf, p, &buf_out);
00593 if (lres == DW_DLV_ERROR) {
00594 return;
00595 }
00596 if (lres == DW_DLV_OK) {
00597 p = buf_out;
00598
00599
00600 }
00601 if ((llent + 1) < no_of_elements) {
00602
00603
00604 if (!dense) {
00605 sprintf(p, "\n\t\t\t\t\t");
00606 p += strlen(p);
00607 }
00608 }
00609 }
00610 for (i = 0; i < no_of_elements; ++i) {
00611 dwarf_dealloc(dbg, llbufarray[i]->ld_s, DW_DLA_LOC_BLOCK);
00612 dwarf_dealloc(dbg, llbufarray[i], DW_DLA_LOCDESC);
00613 }
00614 dwarf_dealloc(dbg, llbufarray, DW_DLA_LIST);
00615 }
00616
00617
00618
00619
00620 static void
00621 get_attr_value(Dwarf_Debug dbg, Dwarf_Half tag, Dwarf_Attribute attrib,
00622 char **srcfiles, Dwarf_Signed cnt)
00623 {
00624 Dwarf_Half theform;
00625 string temps;
00626 Dwarf_Block *tempb;
00627 Dwarf_Signed tempsd = 0;
00628 Dwarf_Unsigned tempud = 0;
00629 int i;
00630 string p;
00631 Dwarf_Half attr;
00632 Dwarf_Off off;
00633 Dwarf_Die die_for_check;
00634 Dwarf_Half tag_for_check;
00635 Dwarf_Bool tempbool;
00636 Dwarf_Addr addr = 0;
00637 int fres;
00638 int bres;
00639 int wres;
00640 int dres;
00641 Dwarf_Half direct_form = 0;
00642
00643 fres = dwarf_whatform(attrib, &theform, &err);
00644
00645 if (fres == DW_DLV_ERROR) {
00646 print_error(dbg, "dwarf_whatform cannot find attr form", fres,
00647 err);
00648 } else if (fres == DW_DLV_NO_ENTRY) {
00649 return;
00650 }
00651
00652 dwarf_whatform_direct(attrib, &direct_form, &err);
00653
00654
00655
00656 switch (theform) {
00657 case DW_FORM_addr:
00658 bres = dwarf_formaddr(attrib, &addr, &err);
00659 if (bres == DW_DLV_OK) {
00660 sprintf(attrib_buf, "%#llx", (unsigned long long) addr);
00661 } else {
00662 print_error(dbg, "addr formwith no addr?!", bres, err);
00663 }
00664 break;
00665 case DW_FORM_ref_addr:
00666
00667
00668
00669 bres = dwarf_global_formref(attrib, &off, &err);
00670 if (bres == DW_DLV_OK) {
00671 sprintf(attrib_buf, "<global die offset %llu>",
00672 (unsigned long long) off);
00673 } else {
00674 print_error(dbg,
00675 "DW_FORM_ref_addr form with no reference?!",
00676 bres, err);
00677 }
00678 break;
00679 case DW_FORM_ref1:
00680 case DW_FORM_ref2:
00681 case DW_FORM_ref4:
00682 case DW_FORM_ref8:
00683 case DW_FORM_ref_udata:
00684 bres = dwarf_formref(attrib, &off, &err);
00685 if (bres != DW_DLV_OK) {
00686 print_error(dbg, "ref formwith no ref?!", bres, err);
00687 }
00688
00689
00690
00691 sprintf(attrib_buf, "<%llu>", off);
00692 if (check_type_offset) {
00693 wres = dwarf_whatattr(attrib, &attr, &err);
00694 if (wres == DW_DLV_ERROR) {
00695
00696 } else if (wres == DW_DLV_NO_ENTRY) {
00697 }
00698 if (attr == DW_AT_type) {
00699 dres = dwarf_offdie(dbg, cu_offset + off,
00700 &die_for_check, &err);
00701 type_offset_result.checks++;
00702 if (dres != DW_DLV_OK) {
00703 type_offset_result.errors++;
00704 DWARF_CHECK_ERROR
00705 ("DW_AT_type offset does not point to type info")
00706 } else {
00707 int tres2;
00708
00709 tres2 =
00710 dwarf_tag(die_for_check, &tag_for_check, &err);
00711 if (tres2 == DW_DLV_OK) {
00712 switch (tag_for_check) {
00713 case DW_TAG_array_type:
00714 case DW_TAG_class_type:
00715 case DW_TAG_enumeration_type:
00716 case DW_TAG_pointer_type:
00717 case DW_TAG_reference_type:
00718 case DW_TAG_string_type:
00719 case DW_TAG_structure_type:
00720 case DW_TAG_subroutine_type:
00721 case DW_TAG_typedef:
00722 case DW_TAG_union_type:
00723 case DW_TAG_ptr_to_member_type:
00724 case DW_TAG_set_type:
00725 case DW_TAG_subrange_type:
00726 case DW_TAG_base_type:
00727 case DW_TAG_const_type:
00728 case DW_TAG_file_type:
00729 case DW_TAG_packed_type:
00730 case DW_TAG_thrown_type:
00731 case DW_TAG_volatile_type:
00732
00733 break;
00734 default:
00735 type_offset_result.errors++;
00736 DWARF_CHECK_ERROR
00737 ("DW_AT_type offset does not point to type info")
00738 break;
00739 }
00740 dwarf_dealloc(dbg, die_for_check, DW_DLA_DIE);
00741 } else {
00742 type_offset_result.errors++;
00743 DWARF_CHECK_ERROR
00744 ("DW_AT_type offset does not exist")
00745 }
00746 }
00747 }
00748 }
00749 break;
00750 case DW_FORM_block:
00751 case DW_FORM_block1:
00752 case DW_FORM_block2:
00753 case DW_FORM_block4:
00754 fres = dwarf_formblock(attrib, &tempb, &err);
00755 if (fres == DW_DLV_OK) {
00756 if (tempb->bl_len >= attrib_bufsiz) {
00757 attrib_buf =
00758 (string) realloc(attrib_buf, tempb->bl_len);
00759 if (attrib_buf == NULL) {
00760 fprintf(stderr,
00761 "ERROR: out of memory for attribute buffer\n");
00762 exit(1);
00763 }
00764 attrib_bufsiz = tempb->bl_len;
00765 }
00766 for (i = 0, p = attrib_buf; i < tempb->bl_len; i++, p += 2) {
00767 sprintf(p, "%02x",
00768 *(i + (unsigned char *) tempb->bl_data));
00769 }
00770 dwarf_dealloc(dbg, tempb, DW_DLA_BLOCK);
00771 } else {
00772 print_error(dbg, "DW_FORM_blockn cannot get block\n", fres,
00773 err);
00774 }
00775 break;
00776 case DW_FORM_data1:
00777 case DW_FORM_data2:
00778 case DW_FORM_data4:
00779 case DW_FORM_data8:
00780 fres = dwarf_whatattr(attrib, &attr, &err);
00781 if (fres == DW_DLV_ERROR) {
00782 print_error(dbg, "FORM_datan cannot get attr", fres, err);
00783 } else if (fres == DW_DLV_NO_ENTRY) {
00784 print_error(dbg, "FORM_datan cannot get attr", fres, err);
00785 } else {
00786 switch (attr) {
00787 case DW_AT_ordering:
00788 case DW_AT_byte_size:
00789 case DW_AT_bit_offset:
00790 case DW_AT_bit_size:
00791 case DW_AT_inline:
00792 case DW_AT_language:
00793 case DW_AT_visibility:
00794 case DW_AT_virtuality:
00795 case DW_AT_accessibility:
00796 case DW_AT_address_class:
00797 case DW_AT_calling_convention:
00798 case DW_AT_encoding:
00799 case DW_AT_identifier_case:
00800 case DW_AT_MIPS_loop_unroll_factor:
00801 case DW_AT_MIPS_software_pipeline_depth:
00802 case DW_AT_decl_column:
00803 case DW_AT_decl_file:
00804 case DW_AT_decl_line:
00805 case DW_AT_start_scope:
00806 case DW_AT_stride_size:
00807 case DW_AT_count:
00808 case DW_AT_stmt_list:
00809 case DW_AT_MIPS_fde:
00810 wres = dwarf_formudata(attrib, &tempud, &err);
00811 if (wres == DW_DLV_OK) {
00812
00813
00814 sprintf(attrib_buf, "%llu", tempud);
00815 if (attr == DW_AT_decl_file) {
00816 if (srcfiles && tempud > 0 && tempud <= cnt) {
00817
00818
00819
00820
00821
00822
00823 char *fname = srcfiles[tempud - 1];
00824 size_t used_so_far = strlen(attrib_buf);
00825 char *targ = attrib_buf + used_so_far;
00826 size_t bytes_left = attrib_bufsiz - (used_so_far + 1
00827
00828
00829
00830
00831
00832 + 1
00833
00834
00835
00836
00837
00838
00839 );
00840 size_t namelen = strlen(fname) + 1;
00841
00842 if (namelen > bytes_left) {
00843
00844
00845
00846
00847
00848
00849 fname += (namelen - bytes_left) + 10;
00850 strcpy(targ, " ");
00851 ++targ;
00852 strcat(targ, "...");
00853 strcat(targ, fname);
00854
00855 } else {
00856
00857 strcpy(targ, " ");
00858 ++targ;
00859 strcpy(targ, fname);
00860 }
00861 }
00862 }
00863 } else if (wres == DW_DLV_NO_ENTRY) {
00864
00865 } else {
00866 print_error(dbg, "Cannot get formudata..", wres,
00867 err);
00868 }
00869 break;
00870 case DW_AT_const_value:
00871 wres = dwarf_formudata(attrib, &tempud, &err);
00872 if (wres == DW_DLV_OK) {
00873 if (tag == DW_TAG_enumerator) {
00874
00875
00876
00877
00878
00879
00880
00881 int i = (int) tempud;
00882
00883 tempsd = i;
00884 sprintf(attrib_buf, "%lld", tempsd);
00885 } else {
00886 sprintf(attrib_buf, "%llu", tempud);
00887 }
00888 } else if (wres == DW_DLV_NO_ENTRY) {
00889
00890 } else {
00891 if (tag == DW_TAG_enumerator) {
00892 wres = dwarf_formsdata(attrib, &tempsd, &err);
00893 if (wres == DW_DLV_OK) {
00894
00895
00896
00897 sprintf(attrib_buf, "%lld", tempsd);
00898 } else if (wres == DW_DLV_NO_ENTRY) {
00899
00900 } else {
00901 print_error(dbg,
00902 "Cannot get formudata or formsdata..",
00903 wres, err);
00904 }
00905 } else {
00906 print_error(dbg, "Cannot get formudata..", wres,
00907 err);
00908 }
00909 }
00910 break;
00911 case DW_AT_upper_bound:
00912 case DW_AT_lower_bound:
00913 default:
00914 wres = dwarf_formsdata(attrib, &tempsd, &err);
00915 if (wres == DW_DLV_OK) {
00916 sprintf(attrib_buf, "%lld", tempsd);
00917 } else if (wres == DW_DLV_NO_ENTRY) {
00918
00919 } else {
00920 print_error(dbg, "Cannot get formsdata..", wres,
00921 err);
00922 }
00923 break;
00924 }
00925 }
00926 if (cu_name_flag) {
00927 if (attr == DW_AT_MIPS_fde) {
00928 if (fde_offset_for_cu_low == DW_DLV_BADOFFSET) {
00929 fde_offset_for_cu_low
00930 = fde_offset_for_cu_high = tempud;
00931 } else if (tempud < fde_offset_for_cu_low) {
00932 fde_offset_for_cu_low = tempud;
00933 } else if (tempud > fde_offset_for_cu_high) {
00934 fde_offset_for_cu_high = tempud;
00935 }
00936 }
00937 }
00938 break;
00939 case DW_FORM_sdata:
00940 wres = dwarf_formsdata(attrib, &tempsd, &err);
00941 if (wres == DW_DLV_OK) {
00942 sprintf(attrib_buf, "%lld", tempsd);
00943 } else if (wres == DW_DLV_NO_ENTRY) {
00944
00945 } else {
00946 print_error(dbg, "Cannot get formsdata..", wres, err);
00947 }
00948 break;
00949 case DW_FORM_udata:
00950 wres = dwarf_formudata(attrib, &tempud, &err);
00951 if (wres == DW_DLV_OK) {
00952 sprintf(attrib_buf, "%llu", tempud);
00953 } else if (wres == DW_DLV_NO_ENTRY) {
00954
00955 } else {
00956 print_error(dbg, "Cannot get formudata....", wres, err);
00957 }
00958 break;
00959 case DW_FORM_string:
00960 case DW_FORM_strp:
00961 wres = dwarf_formstring(attrib, &temps, &err);
00962 if (wres == DW_DLV_OK) {
00963 if (strlen(temps) >= attrib_bufsiz) {
00964 attrib_buf =
00965 (string) realloc(attrib_buf, strlen(temps) + 1);
00966 if (attrib_buf == NULL) {
00967 fprintf(stderr,
00968 "ERROR: out of memory for attribute buffer\n");
00969 exit(1);
00970 }
00971 attrib_bufsiz = strlen(temps) + 1;
00972 }
00973 sprintf(attrib_buf, "%s", temps);
00974 dwarf_dealloc(dbg, temps, DW_DLA_STRING);
00975 } else if (wres == DW_DLV_NO_ENTRY) {
00976
00977 } else {
00978 print_error(dbg, "Cannot get formstr/p....", wres, err);
00979 }
00980
00981 break;
00982 case DW_FORM_flag:
00983 wres = dwarf_formflag(attrib, &tempbool, &err);
00984 if (wres == DW_DLV_OK) {
00985 if (tempbool) {
00986 sprintf(attrib_buf, "yes(%d)", tempbool);
00987 } else {
00988 sprintf(attrib_buf, "no");
00989 }
00990 } else if (wres == DW_DLV_NO_ENTRY) {
00991
00992 } else {
00993 print_error(dbg, "Cannot get formflag/p....", wres, err);
00994 }
00995 break;
00996 case DW_FORM_indirect:
00997
00998
00999
01000 sprintf(attrib_buf, get_FORM_name(dbg, theform));
01001 break;
01002 default:
01003 print_error(dbg, "dwarf_whatform unexpected value", DW_DLV_OK,
01004 err);
01005 }
01006 if (verbose && direct_form && direct_form == DW_FORM_indirect) {
01007 strcat(attrib_buf, " (used DW_FORM_indirect) ");
01008 }
01009 }
01010
01011 #include "_tag_attr_table.c"
01012
01013 static int
01014 tag_attr_combination(Dwarf_Half tag, Dwarf_Half attr)
01015 {
01016 if (attr > 0 && attr < 0x60) {
01017 return ((tag_attr_combination_table[tag][attr / 0x20]
01018 & (1 << (attr % 0x20))) > 0 ? TRUE : FALSE);
01019 } else if (attr == DW_AT_MIPS_fde) {
01020
01021 return (TRUE);
01022 } else
01023 return (FALSE);
01024 }