1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
|
/*
Copyright (C) 2006 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright (C) 2011 SN Systems Ltd. All Rights Reserved.
Portions Copyright (C) 2007-2011 David Anderson. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street - Fifth Floor, Boston MA 02110-1301, USA.
Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
Mountain View, CA 94043, or:
http://www.sgi.com
For further information regarding this notice, see:
http://oss.sgi.com/projects/GenInfo/NoticeExplan
$Header: /plroot/cmplrs.src/v7.4.5m/.RCS/PL/dwarfdump/RCS/print_frames.c,v 1.5 2006/06/14 20:34:02 davea Exp $ */
/* The address of the Free Software Foundation is
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
SGI has moved from the Crittenden Lane address.
*/
/* From 199x through 2010 print_frames relied on
the order of the fdes matching the order of the functions
in the CUs when it came to printing a function name with
an FDE. This sometimes worked for SGI/IRIX because of
the way the compiler often emitted things. It always worked poorly
for gcc and other compilers.
As of 2010 the addrmap.h addrmap.h code provides help
in doing a better job when the tsearch functions (part of
POSIX) are available. */
#include "globals.h"
#include "print_frames.h"
#include "dwconf.h"
#include "esb.h"
#include "addrmap.h"
static void
print_one_frame_reg_col(Dwarf_Debug dbg,
Dwarf_Unsigned rule_id,
Dwarf_Small value_type,
Dwarf_Unsigned reg_used,
Dwarf_Half addr_size,
struct dwconf_s *config_data,
Dwarf_Signed offset_relevant,
Dwarf_Signed offset, Dwarf_Ptr block_ptr);
/* A strcpy which ensures NUL terminated string
and never overruns the output.
*/
void
safe_strcpy(char *out, long outlen, const char *in, long inlen)
{
if (inlen >= (outlen - 1)) {
strncpy(out, in, outlen - 1);
out[outlen - 1] = 0;
} else {
strcpy(out, in);
}
}
/* For inlined functions, try to find name */
static int
get_abstract_origin_funcname(Dwarf_Debug dbg,Dwarf_Attribute attr,
char *name_out, unsigned maxlen)
{
Dwarf_Off off = 0;
Dwarf_Die origin_die = 0;
Dwarf_Attribute *atlist = NULL;
Dwarf_Signed atcnt = 0;
Dwarf_Signed i = 0;
int dres = 0;
int atres;
int name_found = 0;
int res = dwarf_global_formref(attr,&off,&err);
if(res != DW_DLV_OK) {
return DW_DLV_NO_ENTRY;
}
dres = dwarf_offdie(dbg,off,&origin_die,&err);
if(dres != DW_DLV_OK) {
return DW_DLV_NO_ENTRY;
}
atres = dwarf_attrlist(origin_die, &atlist, &atcnt, &err);
if (atres != DW_DLV_OK) {
dwarf_dealloc(dbg,origin_die,DW_DLA_DIE);
return DW_DLV_NO_ENTRY;
}
for (i = 0; i < atcnt; i++) {
Dwarf_Half lattr;
int ares;
ares = dwarf_whatattr(atlist[i], &lattr, &err);
if (ares == DW_DLV_ERROR) {
break;
} else if (ares == DW_DLV_OK) {
if(lattr == DW_AT_name) {
int sres = 0;
char* temps = 0;
sres = dwarf_formstring(atlist[i], &temps, &err);
if (sres == DW_DLV_OK) {
long len = (long) strlen(temps);
safe_strcpy(name_out, maxlen, temps, len);
name_found = 1;
break;
}
}
}
}
for (i = 0; i < atcnt; i++) {
dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
}
dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
dwarf_dealloc(dbg,origin_die,DW_DLA_DIE);
if(!name_found) {
return DW_DLV_NO_ENTRY;
}
return DW_DLV_OK;
}
/*
Returns 1 if a proc with this low_pc found.
Else returns 0.
From print_die.c this has no pcMap passed in,
we do not really have a sensible context, so this
really just looks at the current attributes for a name.
*/
int
get_proc_name(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Addr low_pc,
char *proc_name_buf, int proc_name_buf_len, void **pcMap)
{
Dwarf_Signed atcnt = 0;
Dwarf_Signed i = 0;
Dwarf_Attribute *atlist = NULL;
Dwarf_Addr low_pc_die = 0;
int atres = 0;
int funcres = 1;
int funcpcfound = 0;
int funcnamefound = 0;
proc_name_buf[0] = 0; /* always set to something */
if(pcMap) {
struct Addr_Map_Entry *ame = 0;
ame = addr_map_find(low_pc,pcMap);
if(ame && ame->mp_name) {
/* mp_name is NULL only if we ran out of heap space. */
safe_strcpy(proc_name_buf, proc_name_buf_len,
ame->mp_name,(long) strlen(ame->mp_name));
return 1;
}
}
atres = dwarf_attrlist(die, &atlist, &atcnt, &err);
if (atres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_attrlist", atres, err);
return 0;
}
if (atres == DW_DLV_NO_ENTRY) {
return 0;
}
for (i = 0; i < atcnt; i++) {
Dwarf_Half attr = 0;
int ares = 0;
string temps = 0;
int sres = 0;
int dres = 0;
if (funcnamefound == 1 && funcpcfound == 1) {
/* stop as soon as both found */
break;
}
ares = dwarf_whatattr(atlist[i], &attr, &err);
if (ares == DW_DLV_ERROR) {
print_error(dbg, "get_proc_name whatattr error", ares, err);
} else if (ares == DW_DLV_OK) {
switch (attr) {
case DW_AT_specification:
case DW_AT_abstract_origin:
{
if(!funcnamefound) {
/* Only use this if we have not seen DW_AT_name
yet .*/
int aores = get_abstract_origin_funcname(dbg,
atlist[i], proc_name_buf,proc_name_buf_len);
if(aores == DW_DLV_OK) {
/* FOUND THE NAME */
funcnamefound = 1;
}
}
}
break;
case DW_AT_name:
/* Even if we saw DW_AT_abstract_origin, go ahead
and take DW_AT_name. */
sres = dwarf_formstring(atlist[i], &temps, &err);
if (sres == DW_DLV_ERROR) {
print_error(dbg,
"formstring in get_proc_name failed",
sres, err);
/* 50 is safe wrong length since is bigger than the
actual string */
safe_strcpy(proc_name_buf, proc_name_buf_len,
"ERROR in dwarf_formstring!", 50);
} else if (sres == DW_DLV_NO_ENTRY) {
/* 50 is safe wrong length since is bigger than the
actual string */
safe_strcpy(proc_name_buf, proc_name_buf_len,
"NO ENTRY on dwarf_formstring?!", 50);
} else {
long len = (long) strlen(temps);
safe_strcpy(proc_name_buf, proc_name_buf_len, temps,
len);
}
funcnamefound = 1; /* FOUND THE NAME */
break;
case DW_AT_low_pc:
dres = dwarf_formaddr(atlist[i], &low_pc_die, &err);
if (dres == DW_DLV_ERROR) {
print_error(dbg, "formaddr in get_proc_name failed",
dres, err);
low_pc_die = ~low_pc;
/* ensure no match */
}
funcpcfound = 1;
break;
default:
break;
}
}
}
for (i = 0; i < atcnt; i++) {
dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
}
dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
if(funcnamefound && funcpcfound && pcMap ) {
/* Insert every name to map, not just the one
we are looking for.
This version does extra work in that
early symbols in a CU will be inserted
multiple times (the extra times have no
effect), the dwarfdump2
version of this does less work. */
addr_map_insert(low_pc_die,proc_name_buf,pcMap);
}
if (funcnamefound == 0 || funcpcfound == 0 || low_pc != low_pc_die) {
funcres = 0;
}
return (funcres);
}
/* Modified Depth First Search looking for the procedure:
a) only looks for children of subprogram.
b) With subprogram looks at current die *before* looking
for a child.
Needed since some languages, including SGI MP Fortran,
have nested functions.
Return 0 on failure, 1 on success.
*/
static int
load_nested_proc_name(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Addr low_pc,
char *ret_name_buf, int ret_name_buf_len,
void **pcMap)
{
char name_buf[BUFSIZ];
Dwarf_Die curdie = die;
int die_locally_gotten = 0;
Dwarf_Die prev_child = 0;
Dwarf_Die newchild = 0;
Dwarf_Die newsibling = 0;
Dwarf_Half tag;
Dwarf_Error err = 0;
int chres = DW_DLV_OK;
ret_name_buf[0] = 0;
name_buf[0] = 0;
while (chres == DW_DLV_OK) {
int tres;
tres = dwarf_tag(curdie, &tag, &err);
newchild = 0;
err = 0;
if (tres == DW_DLV_OK) {
int lchres;
if (tag == DW_TAG_subprogram) {
int proc_name_v = get_proc_name(dbg, curdie, low_pc,
name_buf, BUFSIZ,pcMap);
if (proc_name_v) {
safe_strcpy(ret_name_buf, ret_name_buf_len,
name_buf, (long) strlen(name_buf));
if (die_locally_gotten) {
/* If we got this die from the parent, we do
not want to dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
return 1;
}
/* Check children of subprograms recursively should
this really be check children of anything,
or just children of subprograms? */
lchres = dwarf_child(curdie, &newchild, &err);
if (lchres == DW_DLV_OK) {
/* look for inner subprogram */
int newprog =
load_nested_proc_name(dbg, newchild, low_pc,
name_buf, BUFSIZ,
pcMap);
dwarf_dealloc(dbg, newchild, DW_DLA_DIE);
if (newprog) {
/* Found it. We could just take this name or
we could concatenate names together For now,
just take name */
if (die_locally_gotten) {
/* If we got this die from the parent, we
do not want to dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
safe_strcpy(ret_name_buf, ret_name_buf_len,
name_buf, (long) strlen(name_buf));
return 1;
}
} else if (lchres == DW_DLV_NO_ENTRY) {
/* nothing to do */
} else {
print_error(dbg,
"load_nested_proc_name dwarf_child() failed ",
chres, err);
if (die_locally_gotten) {
/* If we got this die from the parent, we do
not want to dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
return 0;
}
} /* end if TAG_subprogram */
} else {
print_error(dbg, "no tag on child read ", tres, err);
if (die_locally_gotten) {
/* If we got this die from the parent, we do not want
to dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
return 0;
}
/* try next sibling */
prev_child = curdie;
chres = dwarf_siblingof(dbg, curdie, &newsibling, &err);
if (chres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_cu_header On Child read ", chres,
err);
if (die_locally_gotten) {
/* If we got this die from the parent, we do not want
to dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
return 0;
} else if (chres == DW_DLV_NO_ENTRY) {
if (die_locally_gotten) {
/* If we got this die from the parent, we do not want
to dealloc here! */
dwarf_dealloc(dbg, prev_child, DW_DLA_DIE);
}
return 0;/* proc name not at this level */
} else {
/* DW_DLV_OK */
curdie = newsibling;
if (die_locally_gotten) {
/* If we got this die from the parent, we do not want
to dealloc here! */
dwarf_dealloc(dbg, prev_child, DW_DLA_DIE);
}
prev_child = 0;
die_locally_gotten = 1;
}
}
if (die_locally_gotten) {
/* If we got this die from the parent, we do not want to
dealloc here! */
dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
}
return 0;
}
/* For SGI MP Fortran and other languages, functions
nest! As a result, we must dig thru all functions,
not just the top level.
This remembers the CU die and restarts each search at the start
of the current cu.
*/
static string
get_fde_proc_name(Dwarf_Debug dbg, Dwarf_Addr low_pc,
void **pcMap,
int *all_cus_seen)
{
static char proc_name[BUFSIZ];
Dwarf_Unsigned cu_header_length = 0;
Dwarf_Unsigned abbrev_offset = 0;
Dwarf_Half version_stamp = 0;
Dwarf_Half address_size = 0;
Dwarf_Unsigned next_cu_offset = 0;
int cures = DW_DLV_OK;
int dres = DW_DLV_OK;
int chres = DW_DLV_OK;
int looping = 0;
proc_name[0] = 0;
{
struct Addr_Map_Entry *ame = 0;
ame = addr_map_find(low_pc,pcMap);
if(ame && ame->mp_name) {
/* mp_name is only NULL here if we just ran out of heap memory! */
safe_strcpy(proc_name, sizeof(proc_name),
ame->mp_name,(long) strlen(ame->mp_name));
return proc_name;
}
if (*all_cus_seen) {
return "";
}
}
if (current_cu_die_for_print_frames == NULL) {
/* Call depends on dbg->cu_context to know what to do. */
cures = dwarf_next_cu_header(dbg, &cu_header_length,
&version_stamp, &abbrev_offset,
&address_size, &next_cu_offset,
&err);
if (cures == DW_DLV_ERROR) {
return NULL;
} else if (cures == DW_DLV_NO_ENTRY) {
/* loop thru the list again */
current_cu_die_for_print_frames = 0;
++looping;
} else { /* DW_DLV_OK */
dres = dwarf_siblingof(dbg, NULL,
¤t_cu_die_for_print_frames,
&err);
if (dres == DW_DLV_ERROR) {
return NULL;
}
}
}
if (dres == DW_DLV_OK) {
Dwarf_Die child = 0;
if (current_cu_die_for_print_frames == 0) {
/* no information. Possibly a stripped file */
return NULL;
}
chres =
dwarf_child(current_cu_die_for_print_frames, &child, &err);
if (chres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_cu_header on child read ", chres,
err);
} else if (chres == DW_DLV_NO_ENTRY) {
} else { /* DW_DLV_OK */
int gotname =
load_nested_proc_name(dbg, child, low_pc, proc_name,
BUFSIZ,pcMap);
dwarf_dealloc(dbg, child, DW_DLA_DIE);
if (gotname) {
return (proc_name);
}
child = 0;
}
}
for (;;) {
Dwarf_Die ldie = 0;
cures = dwarf_next_cu_header(dbg, &cu_header_length,
&version_stamp, &abbrev_offset,
&address_size, &next_cu_offset,
&err);
if (cures != DW_DLV_OK) {
*all_cus_seen = 1;
break;
}
dres = dwarf_siblingof(dbg, NULL, &ldie, &err);
if (current_cu_die_for_print_frames) {
dwarf_dealloc(dbg, current_cu_die_for_print_frames,
DW_DLA_DIE);
}
current_cu_die_for_print_frames = 0;
if (dres == DW_DLV_ERROR) {
print_error(dbg,
"dwarf_cu_header Child Read finding proc name for .debug_frame",
chres, err);
continue;
} else if (dres == DW_DLV_NO_ENTRY) {
++looping;
if (looping > 1) {
print_error(dbg, "looping on cu headers!", dres, err);
return NULL;
}
continue;
}
/* DW_DLV_OK */
current_cu_die_for_print_frames = ldie;
{
int chres = 0;
Dwarf_Die child = 0;
chres =
dwarf_child(current_cu_die_for_print_frames, &child,
&err);
if (chres == DW_DLV_ERROR) {
print_error(dbg, "dwarf Child Read ", chres, err);
} else if (chres == DW_DLV_NO_ENTRY) {
;/* do nothing, loop on cu */
} else {
/* DW_DLV_OK) */
int gotname =
load_nested_proc_name(dbg, child, low_pc, proc_name,
BUFSIZ,pcMap);
dwarf_dealloc(dbg, child, DW_DLA_DIE);
if (gotname) {
return (proc_name);
}
}
}
}
return (NULL);
}
/* Gather the fde print logic here so the control logic
determining what FDE to print is clearer. */
static int
print_one_fde(Dwarf_Debug dbg, Dwarf_Fde fde,
Dwarf_Unsigned fde_index,
Dwarf_Cie * cie_data,
Dwarf_Signed cie_element_count,
Dwarf_Half address_size, int is_eh,
struct dwconf_s *config_data,
void **pcMap,
void **lowpcSet,
int * all_cus_seen)
{
Dwarf_Addr j = 0;
Dwarf_Addr low_pc = 0;
Dwarf_Unsigned func_length = 0;
Dwarf_Ptr fde_bytes = NULL;
Dwarf_Unsigned fde_bytes_length = 0;
Dwarf_Off cie_offset = 0;
Dwarf_Signed cie_index = 0;
Dwarf_Off fde_offset = 0;
Dwarf_Signed eh_table_offset = 0;
int fres = 0;
int offres = 0;
string temps = 0;
Dwarf_Error err = 0;
int printed_intro_addr = 0;
fres = dwarf_get_fde_range(fde,
&low_pc, &func_length,
&fde_bytes,
&fde_bytes_length,
&cie_offset, &cie_index,
&fde_offset, &err);
if (fres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_get_fde_range", fres, err);
}
if (fres == DW_DLV_NO_ENTRY) {
return DW_DLV_NO_ENTRY;
}
if (cu_name_flag &&
fde_offset_for_cu_low != DW_DLV_BADOFFSET &&
(fde_offset < fde_offset_for_cu_low ||
fde_offset > fde_offset_for_cu_high)) {
return DW_DLV_NO_ENTRY;
}
/* eh_table_offset is IRIX ONLY. */
fres = dwarf_get_fde_exception_info(fde, &eh_table_offset, &err);
if (fres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_get_fde_exception_info", fres, err);
}
if(suppress_nested_name_search) {
temps = 0;
} else {
#ifdef HAVE_TSEARCH
struct Addr_Map_Entry *mp = 0;
temps = get_fde_proc_name(dbg, low_pc,pcMap,all_cus_seen);
mp = addr_map_find(low_pc,lowpcSet);
if (check_frames || check_frames_extended) {
DWARF_CHECK_COUNT(fde_duplication,1);
}
if (mp) {
if (check_frames || check_frames_extended) {
char msg[400];
if(temps && (strlen(temps) > 0)) {
snprintf(msg,sizeof(msg),"An fde low pc of 0x%"
DW_PR_DUx
" is not the first fde with that pc. "
"The first is named \"%s\"",
(Dwarf_Unsigned)low_pc,
temps);
} else {
snprintf(msg,sizeof(msg),"An fde low pc of 0x%"
DW_PR_DUx
" is not the first fde with that pc. "
"The first is not named.",
(Dwarf_Unsigned)low_pc);
}
DWARF_CHECK_ERROR(fde_duplication,msg);
}
} else {
addr_map_insert(low_pc,0,lowpcSet);
}
#endif
}
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("<%5" DW_PR_DSd "><0x%" DW_PR_XZEROS DW_PR_DUx
":0x%" DW_PR_XZEROS DW_PR_DUx
"><%s><fde offset 0x%" DW_PR_XZEROS DW_PR_DUx
" length: 0x%" DW_PR_XZEROS DW_PR_DUx ">",
cie_index, (Dwarf_Unsigned)low_pc,
(Dwarf_Unsigned)(low_pc + func_length),
temps ? temps : "", (Dwarf_Unsigned)fde_offset, fde_bytes_length);
}
if (!is_eh) {
/* IRIX uses eh_table_offset. */
/* Do not print if in check mode */
if (!check_frames_extended) {
if (eh_table_offset == DW_DLX_NO_EH_OFFSET) {
printf("<eh offset %s>\n", "none");
} else if (eh_table_offset == DW_DLX_EH_OFFSET_UNAVAILABLE) {
printf("<eh offset %s>\n", "unknown");
} else {
printf("<eh offset 0x%" DW_PR_XZEROS DW_PR_DUx
">\n", eh_table_offset);
}
}
} else {
int ares = 0;
Dwarf_Small *data = 0;
Dwarf_Unsigned len = 0;
ares = dwarf_get_fde_augmentation_data(fde, &data, &len, &err);
if (ares == DW_DLV_NO_ENTRY) {
/* do nothing. */
} else if (ares == DW_DLV_OK) {
/* Do not print if in check mode */
if (!check_frames_extended) {
int k2 = 0;
printf("<eh aug data len 0x%" DW_PR_DUx , len);
for (k2 = 0; k2 < len; ++k2) {
if (k2 == 0) {
printf(" bytes 0x");
}
printf("%02x ", (unsigned char) data[k2]);
}
printf(">");
}
} /* else DW_DLV_ERROR, do nothing */
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("\n");
}
}
for (j = low_pc; j < low_pc + func_length; j++) {
Dwarf_Half k = 0;
if (config_data->cf_interface_number == 3) {
Dwarf_Signed reg = 0;
Dwarf_Signed offset_relevant = 0;
Dwarf_Small value_type = 0;
Dwarf_Signed offset_or_block_len = 0;
Dwarf_Signed offset = 0;
Dwarf_Ptr block_ptr = 0;
Dwarf_Addr row_pc = 0;
int fires = dwarf_get_fde_info_for_cfa_reg3(fde,
j,
&value_type,
&offset_relevant,
®,
&offset_or_block_len,
&block_ptr,
&row_pc,
&err);
offset = offset_or_block_len;
if (fires == DW_DLV_ERROR) {
print_error(dbg,
"dwarf_get_fde_info_for_reg", fires, err);
}
if (fires == DW_DLV_NO_ENTRY) {
continue;
}
if (row_pc != j) {
/* duplicate row */
continue;
}
/* Do not print if in check mode */
if (!printed_intro_addr && !check_frames_extended) {
printf(" 0x%" DW_PR_XZEROS DW_PR_DUx
": ", (Dwarf_Unsigned)j);
printed_intro_addr = 1;
}
print_one_frame_reg_col(dbg, config_data->cf_cfa_reg,
value_type,
reg,
address_size,
config_data,
offset_relevant, offset, block_ptr);
}
for (k = 0; k < config_data->cf_table_entry_count; k++) {
Dwarf_Signed reg = 0;
Dwarf_Signed offset_relevant = 0;
int fires = 0;
Dwarf_Small value_type = 0;
Dwarf_Ptr block_ptr = 0;
Dwarf_Signed offset_or_block_len = 0;
Dwarf_Signed offset = 0;
Dwarf_Addr row_pc = 0;
if (config_data->cf_interface_number == 3) {
fires = dwarf_get_fde_info_for_reg3(fde,
k,
j,
&value_type,
&offset_relevant,
®,
&offset_or_block_len,
&block_ptr,
&row_pc, &err);
offset = offset_or_block_len;
} else {
/* This interface is deprecated. Is the old
MIPS/DWARF2 interface. */
/* ASSERT: config_data->cf_interface_number == 2 */
value_type = DW_EXPR_OFFSET;
fires = dwarf_get_fde_info_for_reg(fde,
k,
j,
&offset_relevant,
®,
&offset, &row_pc,
&err);
}
if (fires == DW_DLV_ERROR) {
printf("\n");
print_error(dbg,
"dwarf_get_fde_info_for_reg", fires, err);
}
if (fires == DW_DLV_NO_ENTRY) {
continue;
}
if (row_pc != j) {
/* duplicate row */
break;
}
/* Do not print if in check mode */
if (!printed_intro_addr && !check_frames_extended) {
printf(" 0x%" DW_PR_XZEROS DW_PR_DUx ": ",
(Dwarf_Unsigned)j);
printed_intro_addr = 1;
}
print_one_frame_reg_col(dbg,k,
value_type,
reg,
address_size,
config_data,
offset_relevant, offset, block_ptr);
}
if (printed_intro_addr) {
printf("\n");
printed_intro_addr = 0;
}
}
if (verbose > 1) {
Dwarf_Off fde_off = 0;
Dwarf_Off cie_off = 0;
/* Get the fde instructions and print them in raw form, just
like cie instructions */
Dwarf_Ptr instrs = 0;
Dwarf_Unsigned ilen = 0;
int res = 0;
res = dwarf_get_fde_instr_bytes(fde, &instrs, &ilen, &err);
offres =
dwarf_fde_section_offset(dbg, fde, &fde_off, &cie_off,
&err);
if (offres == DW_DLV_OK) {
/* Do not print if in check mode */
if (!check_frames_extended) {
printf(" fde section offset %" DW_PR_DUu
" 0x%" DW_PR_XZEROS DW_PR_DUx
" cie offset for fde: %" DW_PR_DUu
" 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
(Dwarf_Unsigned) fde_off,
(Dwarf_Unsigned) fde_off,
(Dwarf_Unsigned) cie_off,
(Dwarf_Unsigned) cie_off);
}
}
if (res == DW_DLV_OK) {
int cires = 0;
Dwarf_Unsigned cie_length = 0;
Dwarf_Small version = 0;
string augmenter = 0;
Dwarf_Unsigned code_alignment_factor = 0;
Dwarf_Signed data_alignment_factor = 0;
Dwarf_Half return_address_register_rule = 0;
Dwarf_Ptr initial_instructions = 0;
Dwarf_Unsigned initial_instructions_length = 0;
if (cie_index >= cie_element_count) {
printf("Bad cie index %" DW_PR_DSd
" with fde index %" DW_PR_DUu "! "
"(table entry max %" DW_PR_DSd ")\n",
cie_index, fde_index,
cie_element_count);
exit(1);
}
cires = dwarf_get_cie_info(cie_data[cie_index],
&cie_length,
&version,
&augmenter,
&code_alignment_factor,
&data_alignment_factor,
&return_address_register_rule,
&initial_instructions,
&initial_instructions_length,
&err);
if (cires == DW_DLV_ERROR) {
printf
("Bad cie index %" DW_PR_DSd
" with fde index %" DW_PR_DUu "!\n",
cie_index, fde_index);
print_error(dbg, "dwarf_get_cie_info", cires, err);
}
if (cires == DW_DLV_NO_ENTRY) {
; /* ? */
} else {
/* Do not print if in check mode */
if (!check_frames_extended) {
print_frame_inst_bytes(dbg, instrs,
(Dwarf_Signed) ilen,
data_alignment_factor,
(int) code_alignment_factor,
address_size, config_data);
}
}
} else if (res == DW_DLV_NO_ENTRY) {
printf("Impossible: no instr bytes for fde index %"
DW_PR_DUu "?\n",
fde_index);
} else {
/* DW_DLV_ERROR */
printf("Error: on gettinginstr bytes for fde index %"
DW_PR_DUu "?\n",
fde_index);
print_error(dbg, "dwarf_get_fde_instr_bytes", res, err);
}
}
return DW_DLV_OK;
}
/* Print a cie. Gather the print logic here so the
control logic deciding what to print
is clearer.
*/
int
print_one_cie(Dwarf_Debug dbg, Dwarf_Cie cie,
Dwarf_Unsigned cie_index, Dwarf_Half address_size,
struct dwconf_s *config_data)
{
int cires = 0;
Dwarf_Unsigned cie_length = 0;
Dwarf_Small version = 0;
string augmenter = "";
Dwarf_Unsigned code_alignment_factor = 0;
Dwarf_Signed data_alignment_factor = 0;
Dwarf_Half return_address_register_rule = 0;
Dwarf_Ptr initial_instructions = 0;
Dwarf_Unsigned initial_instructions_length = 0;
Dwarf_Off cie_off = 0;
Dwarf_Error err = 0;
cires = dwarf_get_cie_info(cie,
&cie_length,
&version,
&augmenter,
&code_alignment_factor,
&data_alignment_factor,
&return_address_register_rule,
&initial_instructions,
&initial_instructions_length, &err);
if (cires == DW_DLV_ERROR) {
print_error(dbg, "dwarf_get_cie_info", cires, err);
}
if (cires == DW_DLV_NO_ENTRY) {
printf("Impossible DW_DLV_NO_ENTRY on cie %" DW_PR_DUu "\n",
cie_index);
return DW_DLV_NO_ENTRY;
}
{
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("<%5" DW_PR_DUu ">\tversion\t\t\t\t%d\n",
cie_index, version);
cires = dwarf_cie_section_offset(dbg, cie, &cie_off, &err);
if (cires == DW_DLV_OK) {
printf("\tcie section offset\t\t%" DW_PR_DUu
" 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
(Dwarf_Unsigned) cie_off,
(Dwarf_Unsigned) cie_off);
}
printf("\taugmentation\t\t\t%s\n", augmenter);
printf("\tcode_alignment_factor\t\t%" DW_PR_DUu "\n",
code_alignment_factor);
printf("\tdata_alignment_factor\t\t%" DW_PR_DSd "\n",
data_alignment_factor);
printf("\treturn_address_register\t\t%d\n",
return_address_register_rule);
}
{
int ares = 0;
Dwarf_Small *data = 0;
Dwarf_Unsigned len = 0;
ares =
dwarf_get_cie_augmentation_data(cie, &data, &len, &err);
if (ares == DW_DLV_NO_ENTRY) {
/* do nothing. */
} else if (ares == DW_DLV_OK && len > 0) {
/* Do not print if in check mode */
if (!check_frames_extended) {
int k2 = 0;
printf(" eh aug data len 0x%" DW_PR_DUx , len);
for (k2 = 0; data && k2 < len; ++k2) {
if (k2 == 0) {
printf(" bytes 0x");
}
printf("%02x ", (unsigned char) data[k2]);
}
printf("\n");
}
} /* else DW_DLV_ERROR or no data, do nothing */
}
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("\tbytes of initial instructions\t%" DW_PR_DUu "\n",
initial_instructions_length);
printf("\tcie length\t\t\t%" DW_PR_DUu "\n", cie_length);
/* For better layout */
printf("\tinitial instructions\n");
print_frame_inst_bytes(dbg, initial_instructions,
(Dwarf_Signed) initial_instructions_length,
data_alignment_factor,
(int) code_alignment_factor,
address_size, config_data);
}
}
return DW_DLV_OK;
}
void
get_string_from_locs(Dwarf_Debug dbg,
Dwarf_Ptr bytes_in,
Dwarf_Unsigned block_len,
Dwarf_Half addr_size,
struct esb_s *out_string)
{
Dwarf_Locdesc *locdescarray = 0;
Dwarf_Signed listlen = 0;
Dwarf_Error err2 =0;
int skip_locdesc_header=1;
int res = 0;
int res2 = dwarf_loclist_from_expr_a(dbg,
bytes_in,block_len,
addr_size,
&locdescarray,
&listlen,&err2);
if (res2 == DW_DLV_ERROR) {
print_error(dbg, "dwarf_get_loclist_from_expr_a",
res2, err2);
}
if(res2==DW_DLV_NO_ENTRY) {
return;
}
/* lcnt is always 1 */
/* Use locdescarray here.*/
res = dwarfdump_print_one_locdesc(dbg,
locdescarray,
skip_locdesc_header,
out_string);
if(res != DW_DLV_OK) {
printf("Bad status from _dwarf_print_one_locdesc %d\n",res);
exit(1);
}
dwarf_dealloc(dbg, locdescarray->ld_s, DW_DLA_LOC_BLOCK);
dwarf_dealloc(dbg, locdescarray, DW_DLA_LOCDESC);
return ;
}
/* Print the frame instructions in detail for a glob of instructions.
*/
/*ARGSUSED*/ void
print_frame_inst_bytes(Dwarf_Debug dbg,
Dwarf_Ptr cie_init_inst, Dwarf_Signed len,
Dwarf_Signed data_alignment_factor,
int code_alignment_factor, Dwarf_Half addr_size,
struct dwconf_s *config_data)
{
unsigned char *instp = (unsigned char *) cie_init_inst;
Dwarf_Unsigned uval = 0;
Dwarf_Unsigned uval2 = 0;
unsigned int uleblen = 0;
unsigned int off = 0;
unsigned int loff = 0;
unsigned short u16 = 0;
unsigned int u32 = 0;
unsigned long long u64;
for (; len > 0;) {
unsigned char ibyte = *instp;
int top = ibyte & 0xc0;
int bottom = ibyte & 0x3f;
int delta = 0;
int reg = 0;
switch (top) {
case DW_CFA_advance_loc:
delta = ibyte & 0x3f;
printf("\t%2u DW_CFA_advance_loc %d", off,
(int) (delta * code_alignment_factor));
if (verbose) {
printf(" (%d * %d)", (int) delta,
(int) code_alignment_factor);
}
printf("\n");
break;
case DW_CFA_offset:
loff = off;
reg = ibyte & 0x3f;
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_offset ", loff);
printreg((Dwarf_Signed) reg, config_data);
printf(" %" DW_PR_DSd , (Dwarf_Signed)
(((Dwarf_Signed) uval) * data_alignment_factor));
if (verbose) {
printf(" (%" DW_PR_DUu " * %" DW_PR_DSd ")", uval,
data_alignment_factor);
}
printf("\n");
break;
case DW_CFA_restore:
reg = ibyte & 0x3f;
printf("\t%2u DW_CFA_restore ", off);
printreg((Dwarf_Signed) reg, config_data);
printf("\n");
break;
default:
loff = off;
switch (bottom) {
case DW_CFA_set_loc:
/* operand is address, so need address size */
/* which will be 4 or 8. */
switch (addr_size) {
case 4:
{
__uint32_t v32 = 0;
memcpy(&v32, instp + 1, addr_size);
uval = v32;
}
break;
case 8:
{
__uint64_t v64 = 0;
memcpy(&v64, instp + 1, addr_size);
uval = v64;
}
break;
default:
printf
("Error: Unexpected address size %d in DW_CFA_set_loc!\n",
addr_size);
uval = 0;
}
instp += addr_size;
len -= (Dwarf_Signed) addr_size;
off += addr_size;
printf("\t%2u DW_CFA_set_loc %" DW_PR_DUu "\n",
loff, uval);
break;
case DW_CFA_advance_loc1:
delta = (unsigned char) *(instp + 1);
uval2 = delta;
instp += 1;
len -= 1;
off += 1;
printf("\t%2u DW_CFA_advance_loc1 %" DW_PR_DUu "\n",
loff, uval2);
break;
case DW_CFA_advance_loc2:
memcpy(&u16, instp + 1, 2);
uval2 = u16;
instp += 2;
len -= 2;
off += 2;
printf("\t%2u DW_CFA_advance_loc2 %" DW_PR_DUu "\n",
loff, uval2);
break;
case DW_CFA_advance_loc4:
memcpy(&u32, instp + 1, 4);
uval2 = u32;
instp += 4;
len -= 4;
off += 4;
printf("\t%2u DW_CFA_advance_loc4 %" DW_PR_DUu "\n",
loff, uval2);
break;
case DW_CFA_MIPS_advance_loc8:
memcpy(&u64, instp + 1, 8);
uval2 = u64;
instp += 8;
len -= 8;
off += 8;
printf("\t%2u DW_CFA_MIPS_advance_loc8 %" DW_PR_DUu "\n",
loff, uval2);
break;
case DW_CFA_offset_extended:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
uval2 =
local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_offset_extended ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" %" DW_PR_DSd ,
(Dwarf_Signed) (((Dwarf_Signed) uval2) *
data_alignment_factor));
if (verbose) {
printf(" (%" DW_PR_DUu " * %d)", uval2,
(int) data_alignment_factor);
}
printf("\n");
break;
case DW_CFA_restore_extended:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_restore_extended ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf("\n");
break;
case DW_CFA_undefined:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_undefined ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf("\n");
break;
case DW_CFA_same_value:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_same_value ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf("\n");
break;
case DW_CFA_register:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
uval2 =
local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_register ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" = ");
printreg((Dwarf_Signed) uval2, config_data);
printf("\n");
break;
case DW_CFA_remember_state:
printf("\t%2u DW_CFA_remember_state\n", loff);
break;
case DW_CFA_restore_state:
printf("\t%2u DW_CFA_restore_state\n", loff);
break;
case DW_CFA_def_cfa:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
uval2 =
local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_def_cfa ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" %" DW_PR_DUu , (unsigned long long) uval2);
printf("\n");
break;
case DW_CFA_def_cfa_register:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_def_cfa_register ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf("\n");
break;
case DW_CFA_def_cfa_offset:
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_def_cfa_offset %" DW_PR_DUu "\n",
loff, uval);
break;
case DW_CFA_nop:
printf("\t%2u DW_CFA_nop\n", loff);
break;
case DW_CFA_def_cfa_expression: /* DWARF3 */
{
Dwarf_Unsigned block_len =
local_dwarf_decode_u_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf
("\t%2u DW_CFA_def_cfa_expression expr block len %"
DW_PR_DUu "\n",
loff,
block_len);
dump_block("\t\t", (char *) instp+1,
(Dwarf_Signed) block_len);
printf("\n");
if(verbose) {
struct esb_s exprstring;
esb_constructor(&exprstring);
get_string_from_locs(dbg,
instp+1,block_len,addr_size,&exprstring);
printf("\t\t%s\n",esb_get_string(&exprstring));
esb_destructor(&exprstring);
}
instp += block_len;
len -= block_len;
off += block_len;
}
break;
case DW_CFA_expression: /* DWARF3 */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
Dwarf_Unsigned block_len =
local_dwarf_decode_u_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf
("\t%2u DW_CFA_expression %" DW_PR_DUu
" expr block len %" DW_PR_DUu "\n",
loff, uval,
block_len);
dump_block("\t\t", (char *) instp+1,
(Dwarf_Signed) block_len);
printf("\n");
if(verbose) {
struct esb_s exprstring;
esb_constructor(&exprstring);
get_string_from_locs(dbg,
instp+1,block_len,addr_size,&exprstring);
printf("\t\t%s\n",esb_get_string(&exprstring));
esb_destructor(&exprstring);
}
instp += block_len;
len -= block_len;
off += block_len;
}
break;
case DW_CFA_offset_extended_sf: /* DWARF3 */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
Dwarf_Signed sval2 =
local_dwarf_decode_s_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_offset_extended_sf ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" %" DW_PR_DSd , (Dwarf_Signed)
((sval2) * data_alignment_factor));
if (verbose) {
printf(" (%" DW_PR_DSd " * %d)", sval2,
(int) data_alignment_factor);
}
}
printf("\n");
break;
case DW_CFA_def_cfa_sf: /* DWARF3 */
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
Dwarf_Signed sval2 =
local_dwarf_decode_s_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_def_cfa_sf ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" %" DW_PR_DSd , (long long) sval2);
printf(" (*data alignment factor=>%" DW_PR_DSd ")",
(Dwarf_Signed)(sval2*data_alignment_factor));
}
printf("\n");
break;
case DW_CFA_def_cfa_offset_sf: /* DWARF3 */
{
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
Dwarf_Signed sval =
local_dwarf_decode_s_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_def_cfa_offset_sf %"
DW_PR_DSd " (*data alignment factor=> %"
DW_PR_DSd ")\n",
loff, sval,
(Dwarf_Signed)(data_alignment_factor*sval));
}
break;
case DW_CFA_val_offset: /* DWARF3 */
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
Dwarf_Signed sval2 =
local_dwarf_decode_s_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_val_offset ", loff);
printreg((Dwarf_Signed)uval, config_data);
printf(" %" DW_PR_DSd ,
(Dwarf_Signed) (sval2 *
data_alignment_factor));
if (verbose) {
printf(" (%" DW_PR_DSd " * %d)",
(Dwarf_Signed) sval2,
(int) data_alignment_factor);
}
}
printf("\n");
break;
case DW_CFA_val_offset_sf: /* DWARF3 */
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
Dwarf_Signed sval2 =
local_dwarf_decode_s_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf("\t%2u DW_CFA_val_offset_sf ", loff);
printreg((Dwarf_Signed) uval, config_data);
printf(" %" DW_PR_DSd , (signed long long)
((sval2) * data_alignment_factor));
if (verbose) {
printf(" (%" DW_PR_DSd " * %d)", sval2,
(int) data_alignment_factor);
}
}
printf("\n");
break;
case DW_CFA_val_expression: /* DWARF3 */
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
uval = local_dwarf_decode_u_leb128(instp + 1, &uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
{
Dwarf_Unsigned block_len =
local_dwarf_decode_u_leb128(instp + 1,
&uleblen);
instp += uleblen;
len -= uleblen;
off += uleblen;
printf
("\t%2u DW_CFA_val_expression %" DW_PR_DUu
" expr block len %" DW_PR_DUu "\n",
loff, uval,
block_len);
dump_block("\t\t", (char *) instp+1,
(Dwarf_Signed) block_len);
printf("\n");
if(verbose) {
struct esb_s exprstring;
esb_constructor(&exprstring);
get_string_from_locs(dbg,
instp+1,block_len,addr_size,&exprstring);
printf("\t\t%s\n",esb_get_string(&exprstring));
esb_destructor(&exprstring);
}
instp += block_len;
len -= block_len;
off += block_len;
}
break;
#ifdef DW_CFA_GNU_window_save
case DW_CFA_GNU_window_save:{
/* no information: this just tells unwinder to
restore the window registers from the previous
frame's window save area */
printf("\t%2u DW_CFA_GNU_window_save \n", loff);
}
break;
#endif
#ifdef DW_CFA_GNU_negative_offset_extended
case DW_CFA_GNU_negative_offset_extended:{
printf("\t%2u DW_CFA_GNU_negative_offset_extended \n",
loff);
}
break;
#endif
#ifdef DW_CFA_GNU_args_size
/* single uleb128 is the current arg area size in
bytes. no register exists yet to save this in */
case DW_CFA_GNU_args_size:{
Dwarf_Unsigned lreg = 0;
/* instp is always 1 byte back, so we need +1
when we use it. See the final increment
of this for loop. */
lreg = local_dwarf_decode_u_leb128(instp + 1,
&uleblen);
printf("\t%2u DW_CFA_GNU_args_size arg size: %"
DW_PR_DUu "\n",
loff, lreg);
instp += uleblen;
len -= uleblen;
off += uleblen;
}
break;
#endif
default:
printf(" %u Unexpected op 0x%x: \n",
loff, (unsigned int) bottom);
len = 0;
break;
}
}
instp++;
len--;
off++;
}
}
/* Print our register names for the cases we have a name.
Delegate to the configure code to actually do the print.
*/
void
printreg(Dwarf_Signed reg, struct dwconf_s *config_data)
{
print_reg_from_config_data(reg, config_data);
}
/* Actually does the printing of a rule in the table.
This may print something or may print nothing! */
static void
print_one_frame_reg_col(Dwarf_Debug dbg,
Dwarf_Unsigned rule_id,
Dwarf_Small value_type,
Dwarf_Unsigned reg_used,
Dwarf_Half addr_size,
struct dwconf_s *config_data,
Dwarf_Signed offset_relevant,
Dwarf_Signed offset,
Dwarf_Ptr block_ptr)
{
char *type_title = "";
int print_type_title = 1;
if (check_frames_extended) {
return;
}
if (config_data->cf_interface_number == 2)
print_type_title = 0;
switch (value_type) {
case DW_EXPR_OFFSET:
type_title = "off";
goto preg2;
case DW_EXPR_VAL_OFFSET:
type_title = "valoff";
preg2:
if (reg_used == config_data->cf_initial_rule_value) {
break;
}
if (print_type_title)
printf("<%s ", type_title);
printreg((Dwarf_Signed) rule_id, config_data);
printf("=");
if (offset_relevant == 0) {
printreg((Dwarf_Signed) reg_used, config_data);
printf(" ");
} else {
printf("%02" DW_PR_DSd , offset);
printf("(");
printreg((Dwarf_Signed) reg_used, config_data);
printf(") ");
}
if (print_type_title)
printf("%s", "> ");
break;
case DW_EXPR_EXPRESSION:
type_title = "expr";
goto pexp2;
case DW_EXPR_VAL_EXPRESSION:
type_title = "valexpr";
pexp2:
if (print_type_title)
printf("<%s ", type_title);
printreg((Dwarf_Signed) rule_id, config_data);
printf("=");
printf("expr-block-len=%" DW_PR_DSd , offset);
if (print_type_title)
printf("%s", "> ");
if (verbose) {
char pref[40];
strcpy(pref, "<");
strcat(pref, type_title);
strcat(pref, "bytes:");
dump_block(pref, block_ptr, offset);
printf("%s", "> ");
if(verbose) {
struct esb_s exprstring;
esb_constructor(&exprstring);
get_string_from_locs(dbg,
block_ptr,offset,addr_size,&exprstring);
printf("<expr:%s>",esb_get_string(&exprstring));
esb_destructor(&exprstring);
}
}
break;
default:
printf("Internal error in libdwarf, value type %d\n",
value_type);
exit(1);
}
return;
}
/* get all the data in .debug_frame (or .eh_frame).
The '3' versions mean print using the dwarf3 new interfaces.
The non-3 mean use the old interfaces.
All combinations of requests are possible. */
extern void
print_frames(Dwarf_Debug dbg, int print_debug_frame, int print_eh_frame,
struct dwconf_s *config_data)
{
Dwarf_Signed i;
int fres = 0;
Dwarf_Half address_size = 0;
int framed = 0;
void * map_lowpc_to_name = 0;
current_section_id = DEBUG_FRAME;
/* The address size here will not be right for all frames.
Only in DWARF4 is there a real address size known
in the frame data itself. If any DIE
is known then a real address size can be gotten from
dwarf_get_die_address_size(). */
fres = dwarf_get_address_size(dbg, &address_size, &err);
if (fres != DW_DLV_OK) {
print_error(dbg, "dwarf_get_address_size", fres, err);
}
for (framed = 0; framed < 2; ++framed) {
Dwarf_Cie *cie_data = NULL;
Dwarf_Signed cie_element_count = 0;
Dwarf_Fde *fde_data = NULL;
Dwarf_Signed fde_element_count = 0;
int frame_count = 0;
int cie_count = 0;
int all_cus_seen = 0;
void * lowpcSet = 0;
char *framename = 0;
int silent_if_missing = 0;
int is_eh = 0;
if (framed == 0) {
if (!print_debug_frame) {
continue;
}
framename = ".debug_frame";
/* Big question here is how to print all the info?
Can print the logical matrix, but that is huge,
though could skip lines that don't change.
Either that, or print the instruction statement program
that describes the changes. */
fres = dwarf_get_fde_list(dbg, &cie_data, &cie_element_count,
&fde_data, &fde_element_count, &err);
if(check_harmless) {
print_any_harmless_errors(dbg);
}
} else {
if (!print_eh_frame) {
continue;
}
is_eh = 1;
/* This is gnu g++ exceptions in a .eh_frame section. Which
is just like .debug_frame except that the empty, or
'special' CIE_id is 0, not -1 (to distinguish fde from
cie). And the augmentation is "eh". As of egcs-1.1.2
anyway. A non-zero cie_id is in a fde and is the
difference between the fde address and the beginning of
the cie it belongs to. This makes sense as this is
intended to be referenced at run time, and is part of
the running image. For more on augmentation strings, see
libdwarf/dwarf_frame.c. */
/* Big question here is how to print all the info?
Can print the logical matrix, but that is huge,
though could skip lines that don't change.
Either that, or print the instruction statement program
that describes the changes. */
silent_if_missing = 1;
framename = ".eh_frame";
fres = dwarf_get_fde_list_eh(dbg, &cie_data,
&cie_element_count, &fde_data,
&fde_element_count, &err);
if(check_harmless) {
print_any_harmless_errors(dbg);
}
}
/* Do not print any frame info if in check mode */
if (check_frames) {
addr_map_destroy(lowpcSet);
lowpcSet = 0;
continue;
}
if (fres == DW_DLV_ERROR) {
printf("\n%s\n", framename);
print_error(dbg, "dwarf_get_fde_list", fres, err);
} else if (fres == DW_DLV_NO_ENTRY) {
if (!silent_if_missing) {
printf("\n%s\n", framename);
}
/* no frame information */
} else { /* DW_DLV_OK */
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("\n%s\n", framename);
printf("\nfde:\n");
}
for (i = 0; i < fde_element_count; i++) {
print_one_fde(dbg, fde_data[i],
i, cie_data, cie_element_count,
address_size, is_eh, config_data,
&map_lowpc_to_name,
&lowpcSet,
&all_cus_seen);
++frame_count;
if(frame_count >= break_after_n_units) {
break;
}
}
/* Print the cie set. */
if (verbose) {
/* Do not print if in check mode */
if (!check_frames_extended) {
printf("\ncie:\n");
}
for (i = 0; i < cie_element_count; i++) {
print_one_cie(dbg, cie_data[i], i, address_size,
config_data);
++cie_count;
if(cie_count >= break_after_n_units) {
break;
}
}
}
dwarf_fde_cie_list_dealloc(dbg, cie_data, cie_element_count,
fde_data, fde_element_count);
}
addr_map_destroy(lowpcSet);
lowpcSet = 0;
}
if (current_cu_die_for_print_frames) {
dwarf_dealloc(dbg, current_cu_die_for_print_frames, DW_DLA_DIE);
current_cu_die_for_print_frames = 0;
}
addr_map_destroy(map_lowpc_to_name);
}
|