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 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465
|
/*
Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2.1 of the GNU Lesser 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 Lesser General Public
License along with this program; if not, write the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
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
*/
#include "config.h"
#include "dwarf_incl.h"
#include <stdio.h>
#include <stdlib.h>
#include "dwarf_frame.h"
#include "dwarf_arange.h" /* using Arange as a way to build a
list */
static int
__dwarf_get_fde_list_internal(Dwarf_Debug dbg,
Dwarf_Cie ** cie_data,
Dwarf_Signed * cie_element_count,
Dwarf_Fde ** fde_data,
Dwarf_Signed * fde_element_count,
Dwarf_Small * section_ptr,
Dwarf_Unsigned section_length,
Dwarf_Unsigned section_index,
Dwarf_Unsigned cie_id_value,
int use_gnu_cie_calc,
Dwarf_Error * error);
/*
This function is the heart of the debug_frame stuff. Don't even
think of reading this without reading both the Libdwarf and
consumer API carefully first. This function basically executes
frame instructions contained in a Cie or an Fde, but does in a
number of different ways depending on the information sought.
Start_instr_ptr points to the first byte of the frame instruction
stream, and final_instr_ptr to the to the first byte after the
last.
The offsets returned in the frame instructions are factored. That
is they need to be multiplied by either the code_alignment_factor
or the data_alignment_factor, as appropriate to obtain the actual
offset. This makes it possible to expand an instruction stream
without the corresponding Cie. However, when an Fde frame instr
sequence is being expanded there must be a valid Cie with a pointer
to an initial table row.
If successful, returns DW_DLV_OK
And sets returned_count thru the pointer
if make_instr is true.
If make_instr is false returned_count
should NOT be used by the caller (returned_count
is set to 0 thru the pointer by this routine...)
If unsuccessful, returns DW_DLV_ERROR
and sets returned_error to the error code
It does not do a whole lot of input validation being a private
function. Please make sure inputs are valid.
(1) If make_instr is true, it makes a list of pointers to
Dwarf_Frame_Op structures containing the frame instructions
executed. A pointer to this list is returned in ret_frame_instr.
Make_instr is true only when a list of frame instructions is to be
returned. In this case since we are not interested in the contents
of the table, the input Cie can be NULL. This is the only case
where the inpute Cie can be NULL.
(2) If search_pc is true, frame instructions are executed till
either a location is reached that is greater than the search_pc_val
provided, or all instructions are executed. At this point the
last row of the table generated is returned in a structure.
A pointer to this structure is supplied in table.
(3) This function is also used to create the initial table row
defined by a Cie. In this case, the Dwarf_Cie pointer cie, is
NULL. For an FDE, however, cie points to the associated Cie.
*/
static int
_dwarf_exec_frame_instr(Dwarf_Bool make_instr, /* Make list of frame
instr? */
Dwarf_Frame_Op ** ret_frame_instr, /* Ptr
to
list
of
ptrs
to
fr
instrs
*/
Dwarf_Bool search_pc, /* Search for a pc
value? */
Dwarf_Addr search_pc_val, /* Search for
this pc
value */
Dwarf_Addr loc, /* initial location value */
Dwarf_Small * start_instr_ptr, /* Ptr to start
of frame
instrs. */
Dwarf_Small * final_instr_ptr, /* Ptr just
past frame
instrs. */
Dwarf_Frame table, /* Ptr to struct with
last row. */
Dwarf_Cie cie, /* Ptr to Cie used by the Fde.
*/
Dwarf_Debug dbg, /* Associated
Dwarf_Debug */
Dwarf_Sword * returned_count,
int *returned_error)
{
/* Sweeps the frame instructions. */
Dwarf_Small *instr_ptr;
/* Obvious from the documents. */
Dwarf_Small instr, opcode;
Dwarf_Small reg_no, reg_noA, reg_noB;
Dwarf_Unsigned factored_N_value;
Dwarf_Addr new_loc; /* must be min de_pointer_size bytes */
Dwarf_Unsigned adv_loc; /* must be min de_pointer_size bytes
and must be at least sizeof
Dwarf_ufixed */
struct Dwarf_Reg_Rule_s reg[DW_FRAME_LAST_REG_NUM];
/* This is used to end executing frame instructions. */
/* Becomes true when search_pc is true and loc */
/* is greater than search_pc_val. */
Dwarf_Bool search_over = false;
/* Used by the DW_FRAME_advance_loc instr */
/* to hold the increment in pc value. */
Dwarf_Addr adv_pc;
/* Contains the length in bytes of */
/* an leb128 encoded number. */
Dwarf_Word leb128_length;
/* Counts the number of frame instructions executed. */
Dwarf_Word instr_count = 0;
/*
These contain the current fields of the current frame
instruction. */
Dwarf_Small fp_base_op = 0;
Dwarf_Small fp_extended_op;
Dwarf_Half fp_register;
Dwarf_Unsigned fp_offset;
Dwarf_Off fp_instr_offset;
/*
Stack_table points to the row (Dwarf_Frame ie) being pushed or
popped by a remember or restore instruction. Top_stack points to
the top of the stack of rows. */
Dwarf_Frame stack_table;
Dwarf_Frame top_stack = NULL;
/*
These are used only when make_instr is true. Curr_instr is a
pointer to the current frame instruction executed.
Curr_instr_ptr, head_instr_list, and curr_instr_list are used
to form a chain of Dwarf_Frame_Op structs. Dealloc_instr_ptr
is used to deallocate the structs used to form the chain.
Head_instr_block points to a contiguous list of pointers to the
Dwarf_Frame_Op structs executed. */
Dwarf_Frame_Op *curr_instr;
Dwarf_Chain curr_instr_item, dealloc_instr_item;
Dwarf_Chain head_instr_chain = NULL;
Dwarf_Chain tail_instr_chain = NULL;
Dwarf_Frame_Op *head_instr_block;
/*
These are the alignment_factors taken from the Cie provided.
When no input Cie is provided they are set to 1, because only
factored offsets are required. */
Dwarf_Sword code_alignment_factor = 1;
Dwarf_Sword data_alignment_factor = 1;
/*
This flag indicates when an actual alignment factor is needed.
So if a frame instruction that computes an offset using an
alignment factor is encountered when this flag is set, an error
is returned because the Cie did not have a valid augmentation. */
Dwarf_Bool need_augmentation = false;
Dwarf_Word i;
/* Initialize first row from associated Cie. Using temp regs
explicity */
struct Dwarf_Reg_Rule_s *t1reg;
struct Dwarf_Reg_Rule_s *t1end;
struct Dwarf_Reg_Rule_s *t2reg;
t1reg = reg;
t1end = t1reg + DW_FRAME_LAST_REG_NUM;
if (cie != NULL && cie->ci_initial_table != NULL) {
t2reg = cie->ci_initial_table->fr_reg;
for (; t1reg < t1end; t1reg++, t2reg++) {
*t1reg = *t2reg;
}
} else { /* initialize with same_value */
for (; t1reg < t1end; t1reg++) {
t1reg->ru_is_off = 0;
t1reg->ru_register = DW_FRAME_SAME_VAL;
t1reg->ru_offset = 0;
}
}
/*
The idea here is that the code_alignment_factor and
data_alignment_factor which are needed for certain instructions
are valid only when the Cie has a proper augmentation string.
So if the augmentation is not right, only Frame instruction can
be read. */
if (cie != NULL && cie->ci_augmentation != NULL) {
code_alignment_factor = cie->ci_code_alignment_factor;
data_alignment_factor = cie->ci_data_alignment_factor;
} else
need_augmentation = !make_instr;
instr_ptr = start_instr_ptr;
while ((instr_ptr < final_instr_ptr) && (!search_over)) {
fp_instr_offset = instr_ptr - start_instr_ptr;
instr = *(Dwarf_Small *) instr_ptr;
instr_ptr += sizeof(Dwarf_Small);
fp_base_op = (instr & 0xc0) >> 6;
if ((instr & 0xc0) == 0x00) {
opcode = instr; /* is really extended op */
fp_extended_op = (instr & (~(0xc0))) & 0xff;
} else {
opcode = instr & 0xc0; /* is base op */
fp_extended_op = 0;
}
fp_register = 0;
fp_offset = 0;
switch (opcode) {
case DW_CFA_advance_loc:{
/* base op */
fp_offset = adv_pc = instr & DW_FRAME_INSTR_OFFSET_MASK;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
adv_pc = adv_pc * code_alignment_factor;
search_over = search_pc &&
(loc + adv_pc > search_pc_val);
/* If gone past pc needed, retain old pc. */
if (!search_over)
loc = loc + adv_pc;
break;
}
case DW_CFA_offset:{ /* base op */
reg_no = (instr & DW_FRAME_INSTR_OFFSET_MASK);
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = DW_DLE_DF_REG_NUM_TOO_HIGH;
return DW_DLV_ERROR;
}
factored_N_value =
_dwarf_decode_u_leb128(instr_ptr, &leb128_length);
instr_ptr = instr_ptr + leb128_length;
fp_register = reg_no;
fp_offset = factored_N_value;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
reg[reg_no].ru_is_off = 1;
reg[reg_no].ru_register = DW_FRAME_CFA_COL;
reg[reg_no].ru_offset = factored_N_value *
data_alignment_factor;
break;
}
case DW_CFA_restore:{ /* base op */
reg_no = (instr & DW_FRAME_INSTR_OFFSET_MASK);
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
fp_register = reg_no;
if (cie != NULL && cie->ci_initial_table != NULL)
reg[reg_no] = cie->ci_initial_table->fr_reg[reg_no];
else if (!make_instr) {
*returned_error = (DW_DLE_DF_MAKE_INSTR_NO_INIT);
return DW_DLV_ERROR;
}
break;
}
case DW_CFA_set_loc:{
READ_UNALIGNED(dbg, new_loc, Dwarf_Addr,
instr_ptr, dbg->de_pointer_size);
instr_ptr += dbg->de_pointer_size;
if (new_loc <= loc) {
*returned_error = (DW_DLE_DF_NEW_LOC_LESS_OLD_LOC);
return DW_DLV_ERROR;
}
search_over = search_pc && (new_loc > search_pc_val);
/* If gone past pc needed, retain old pc. */
if (!search_over)
loc = new_loc;
fp_offset = new_loc;
break;
}
case DW_CFA_advance_loc1:{
fp_offset = adv_loc = *(Dwarf_Small *) instr_ptr;
instr_ptr += sizeof(Dwarf_Small);
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
adv_loc *= code_alignment_factor;
search_over = search_pc &&
(loc + adv_loc > search_pc_val);
/* If gone past pc needed, retain old pc. */
if (!search_over)
loc = loc + adv_loc;
break;
}
case DW_CFA_advance_loc2:{
READ_UNALIGNED(dbg, adv_loc, Dwarf_Unsigned,
instr_ptr, sizeof(Dwarf_Half));
instr_ptr += sizeof(Dwarf_Half);
fp_offset = adv_loc;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
adv_loc *= code_alignment_factor;
search_over = search_pc &&
(loc + adv_loc > search_pc_val);
/* If gone past pc needed, retain old pc. */
if (!search_over)
loc = loc + adv_loc;
break;
}
case DW_CFA_advance_loc4:{
READ_UNALIGNED(dbg, adv_loc, Dwarf_Unsigned,
instr_ptr, sizeof(Dwarf_ufixed));
instr_ptr += sizeof(Dwarf_ufixed);
fp_offset = adv_loc;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
adv_loc *= code_alignment_factor;
search_over = search_pc &&
(loc + adv_loc > search_pc_val);
/* If gone past pc needed, retain old pc. */
if (!search_over)
loc = loc + adv_loc;
break;
}
case DW_CFA_offset_extended:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
factored_N_value =
_dwarf_decode_u_leb128(instr_ptr, &leb128_length);
instr_ptr += leb128_length;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
reg[reg_no].ru_is_off = 1;
reg[reg_no].ru_register = DW_FRAME_CFA_COL;
reg[reg_no].ru_offset = factored_N_value *
data_alignment_factor;
fp_register = reg_no;
fp_offset = factored_N_value;
break;
}
case DW_CFA_restore_extended:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
if (cie != NULL && cie->ci_initial_table != NULL) {
reg[reg_no] = cie->ci_initial_table->fr_reg[reg_no];
} else {
if (!make_instr) {
*returned_error =
(DW_DLE_DF_MAKE_INSTR_NO_INIT);
return DW_DLV_ERROR;
}
}
fp_register = reg_no;
break;
}
case DW_CFA_undefined:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
reg[reg_no].ru_is_off = 0;
reg[reg_no].ru_register = DW_FRAME_UNDEFINED_VAL;
reg[reg_no].ru_offset = 0;
fp_register = reg_no;
break;
}
case DW_CFA_same_value:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
reg[reg_no].ru_is_off = 0;
reg[reg_no].ru_register = DW_FRAME_SAME_VAL;
reg[reg_no].ru_offset = 0;
fp_register = reg_no;
break;
}
case DW_CFA_register:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_noA = (Dwarf_Small) lreg;
if (reg_noA > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_noB = (Dwarf_Small) lreg;
if (reg_noB > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
reg[reg_noA].ru_is_off = 0;
reg[reg_noA].ru_register = reg_noB;
reg[reg_noA].ru_offset = 0;
fp_register = reg_noA;
fp_offset = reg_noB;
break;
}
case DW_CFA_remember_state:{
stack_table = (Dwarf_Frame)
_dwarf_get_alloc(dbg, DW_DLA_FRAME, 1);
if (stack_table == NULL) {
*returned_error = (DW_DLE_DF_ALLOC_FAIL);
return DW_DLV_ERROR;
}
for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++)
stack_table->fr_reg[i] = reg[i];
if (top_stack != NULL)
stack_table->fr_next = top_stack;
top_stack = stack_table;
break;
}
case DW_CFA_restore_state:{
if (top_stack == NULL) {
*returned_error = (DW_DLE_DF_POP_EMPTY_STACK);
return DW_DLV_ERROR;
}
stack_table = top_stack;
top_stack = stack_table->fr_next;
for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++)
reg[i] = stack_table->fr_reg[i];
dwarf_dealloc(dbg, stack_table, DW_DLA_FRAME);
break;
}
case DW_CFA_def_cfa:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return (DW_DLV_ERROR);
}
factored_N_value =
_dwarf_decode_u_leb128(instr_ptr, &leb128_length);
instr_ptr += leb128_length;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
reg[DW_FRAME_CFA_COL].ru_is_off = 1;
reg[DW_FRAME_CFA_COL].ru_register = reg_no;
reg[DW_FRAME_CFA_COL].ru_offset = factored_N_value;
fp_register = reg_no;
fp_offset = factored_N_value;
break;
}
case DW_CFA_def_cfa_register:{
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
if (reg_no > DW_FRAME_LAST_REG_NUM) {
*returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH);
return DW_DLV_ERROR;
}
reg[DW_FRAME_CFA_COL].ru_register = reg_no;
/* Do NOT set ru_offset or ru_is_off here.
See dwarf2/3 spec. */
fp_register = reg_no;
break;
}
case DW_CFA_def_cfa_offset:{
factored_N_value =
_dwarf_decode_u_leb128(instr_ptr, &leb128_length);
instr_ptr += leb128_length;
if (need_augmentation) {
*returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION);
return DW_DLV_ERROR;
}
/* Do set ru_is_off here, as here
factored_N_value counts. */
reg[DW_FRAME_CFA_COL].ru_is_off = 1;
reg[DW_FRAME_CFA_COL].ru_offset = factored_N_value;
fp_offset = factored_N_value;
break;
}
case DW_CFA_nop:{
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 */
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;
DECODE_LEB128_UWORD(instr_ptr, lreg)
reg_no = (Dwarf_Small) lreg;
break;
}
#endif
}
if (make_instr) {
instr_count++;
curr_instr = (Dwarf_Frame_Op *)
_dwarf_get_alloc(dbg, DW_DLA_FRAME_OP, 1);
if (curr_instr == NULL) {
*returned_error = (DW_DLE_DF_ALLOC_FAIL);
return DW_DLV_ERROR;
}
curr_instr->fp_base_op = fp_base_op;
curr_instr->fp_extended_op = fp_extended_op;
curr_instr->fp_register = fp_register;
curr_instr->fp_offset = fp_offset;
curr_instr->fp_instr_offset = fp_instr_offset;
curr_instr_item = (Dwarf_Chain)
_dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
if (curr_instr_item == NULL) {
*returned_error = (DW_DLE_DF_ALLOC_FAIL);
return DW_DLV_ERROR;
}
curr_instr_item->ch_item = curr_instr;
if (head_instr_chain == NULL)
head_instr_chain = tail_instr_chain = curr_instr_item;
else {
tail_instr_chain->ch_next = curr_instr_item;
tail_instr_chain = curr_instr_item;
}
}
}
/*
If frame instruction decoding was right we would stop exactly
at final_instr_ptr. */
if (instr_ptr > final_instr_ptr) {
*returned_error = (DW_DLE_DF_FRAME_DECODING_ERROR);
return DW_DLV_ERROR;
}
/* Create the last row generated. */
if (table != NULL) {
t1reg = reg;
t1end = t1reg + DW_FRAME_LAST_REG_NUM;
table->fr_loc = loc;
t2reg = table->fr_reg;
for (; t1reg < t1end; t1reg++, t2reg++) {
*t2reg = *t1reg;
}
}
/* Dealloc anything remaining on stack. */
for (; top_stack != NULL;) {
stack_table = top_stack;
top_stack = top_stack->fr_next;
dwarf_dealloc(dbg, stack_table, DW_DLA_FRAME);
}
if (make_instr) {
/* Allocate list of pointers to Dwarf_Frame_Op's. */
head_instr_block = (Dwarf_Frame_Op *)
_dwarf_get_alloc(dbg, DW_DLA_FRAME_BLOCK, instr_count);
if (head_instr_block == NULL) {
*returned_error = DW_DLE_DF_ALLOC_FAIL;
return DW_DLV_ERROR;
}
/*
Store pointers to Dwarf_Frame_Op's in this list and
deallocate the structs that chain the Dwarf_Frame_Op's. */
curr_instr_item = head_instr_chain;
for (i = 0; i < instr_count; i++) {
*(head_instr_block + i) =
*(Dwarf_Frame_Op *) curr_instr_item->ch_item;
dealloc_instr_item = curr_instr_item;
curr_instr_item = curr_instr_item->ch_next;
dwarf_dealloc(dbg, dealloc_instr_item->ch_item,
DW_DLA_FRAME_OP);
dwarf_dealloc(dbg, dealloc_instr_item, DW_DLA_CHAIN);
}
*ret_frame_instr = head_instr_block;
*returned_count = (Dwarf_Sword) instr_count;
} else {
*returned_count = 0;
}
return DW_DLV_OK;
}
static int
qsort_compare(const void *elem1, const void *elem2)
{
Dwarf_Fde fde1 = *(Dwarf_Fde *) elem1;
Dwarf_Fde fde2 = *(Dwarf_Fde *) elem2;
Dwarf_Addr addr1 = fde1->fd_initial_location;
Dwarf_Addr addr2 = fde2->fd_initial_location;
if (addr1 < addr2) {
return -1;
} else if (addr1 > addr2) {
return 1;
}
return 0;
}
/*
* This function expects as input a pointer to Dwarf_Debug (dbg) and a
* a pointer to Cie. It finds the augmentation string and returns after
* setting *augmentation to point to it.
*/
static int
get_augmentation_string(Dwarf_Debug dbg,
Dwarf_Small * cie_ptr,
Dwarf_Unsigned cie_id_value,
Dwarf_Small ** augmentation,
Dwarf_Error * error)
{
Dwarf_Unsigned cie_id; /* must be min de_length_size bytes in
size */
Dwarf_Small version;
int local_length_size;
Dwarf_Unsigned length;
/*REFERENCED*/ /* Not used in this instance of the macro */
int local_extension_size;
/* READ_AREA_LENGTH updates cie_ptr for consumed bytes */
READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
cie_ptr, local_length_size, local_extension_size);
/* Read the Cie Id field. */
READ_UNALIGNED(dbg, cie_id, Dwarf_Unsigned,
cie_ptr, local_length_size);
SIGN_EXTEND(cie_id, local_length_size);
if (cie_id != cie_id_value) {
/* egcs-1.1.2 .eh_frame uses 0 as the distinguishing id. sgi
uses -1 in .debug_frame. .eh_frame not quite identical to
.debug_frame */
_dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD);
return (DW_DLV_ERROR);
}
cie_ptr += local_length_size;
/* Read the version. */
version = *(Dwarf_Small *) cie_ptr;
cie_ptr++;
if (version != DW_CIE_VERSION &&
version != DW_CIE_VERSION3) {
_dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD);
return (DW_DLV_ERROR);
}
/* At this point, cie_ptr is pointing at the augmentation string. */
*augmentation = cie_ptr;
return DW_DLV_OK;
}
int
dwarf_get_cie_of_fde(Dwarf_Fde fde,
Dwarf_Cie * cie_returned, Dwarf_Error * error)
{
if (fde == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
*cie_returned = fde->fd_cie;
return DW_DLV_OK;
}
/*
For g++ .eh_frame fde and cie.
the cie id is different as the
definition of the cie_id in an fde
is the distance back from the address of the
value to the cie.
Or 0 if this is a true cie.
Non standard dwarf, designed this way to be
convenient at run time for an allocated
(mapped into memory as part of the running image) section.
*/
int
dwarf_get_fde_list_eh(Dwarf_Debug dbg,
Dwarf_Cie ** cie_data,
Dwarf_Signed * cie_element_count,
Dwarf_Fde ** fde_data,
Dwarf_Signed * fde_element_count,
Dwarf_Error * error)
{
int res;
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_eh_gnu_index,
&dbg->de_debug_frame_eh_gnu,
error);
if (res != DW_DLV_OK) {
return res;
}
res =
__dwarf_get_fde_list_internal(dbg,
cie_data,
cie_element_count,
fde_data,
fde_element_count,
dbg->de_debug_frame_eh_gnu,
dbg->de_debug_frame_size_eh_gnu,
dbg->de_debug_frame_eh_gnu_index,
/* cie_id_value */ 0,
/* use_gnu_cie_calc= */ 1,
error);
return res;
}
/*
For standard dwarf .debug_frame
cie_id is -1 in a cie, and
is the section offset in the .debug_frame section
of the cie otherwise. Standard dwarf
*/
int
dwarf_get_fde_list(Dwarf_Debug dbg,
Dwarf_Cie ** cie_data,
Dwarf_Signed * cie_element_count,
Dwarf_Fde ** fde_data,
Dwarf_Signed * fde_element_count,
Dwarf_Error * error)
{
int res;
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_index,
&dbg->de_debug_frame,
error);
if (res != DW_DLV_OK) {
return res;
}
res =
__dwarf_get_fde_list_internal(dbg, cie_data,
cie_element_count,
fde_data,
fde_element_count,
dbg->de_debug_frame,
dbg->de_debug_frame_size,
dbg->de_debug_frame_index,
DW_CIE_ID,
/* use_gnu_cie_calc= */ 0,
error);
return res;
}
static int
__dwarf_get_fde_list_internal(Dwarf_Debug dbg,
Dwarf_Cie ** cie_data,
Dwarf_Signed * cie_element_count,
Dwarf_Fde ** fde_data,
Dwarf_Signed * fde_element_count,
Dwarf_Small * section_ptr,
Dwarf_Unsigned section_length,
Dwarf_Unsigned section_index,
Dwarf_Unsigned cie_id_value,
int use_gnu_cie_calc,
Dwarf_Error * error)
{
/* Scans the debug_frame section. */
Dwarf_Small *frame_ptr = 0;
/* Points to the start of the current Fde or Cie. */
Dwarf_Small *start_frame_ptr = 0;
/* Points to the start of the augmented entries of Fde or Cie. */
Dwarf_Small *saved_frame_ptr = 0;
/* Fields for the current Cie being read. */
Dwarf_Unsigned length = 0; /* READ_UNALIGNED needs min
de_length_size byte dest */
Dwarf_Unsigned cie_base_offset = 0; /* needs to be min
de_length_size byte dest */
Dwarf_Unsigned cie_id;
Dwarf_Small version = 0;
Dwarf_Small *augmentation = 0;
Dwarf_Word code_alignment_factor = 4;
Dwarf_Sword data_alignment_factor = -1;
Dwarf_Small return_address_register = 31;
Dwarf_Word length_of_augmented_fields = 0;
/*
New_cie points to the Cie being read, and head_cie_ptr and
cur_cie_ptr are used for chaining them up in sequence. */
Dwarf_Cie new_cie;
Dwarf_Cie head_cie_ptr = NULL;
Dwarf_Cie cur_cie_ptr;
Dwarf_Word cie_count = 0;
/*
Points to a list of contiguous pointers to Dwarf_Cie
structures. */
Dwarf_Cie *cie_list_ptr;
/* Fields for the current Fde being read. */
Dwarf_Addr initial_location; /* must be min de_pointer_size
bytes in size */
Dwarf_Addr address_range; /* must be min de_pointer_size bytes in
size */
/*
New_fde points to the current Fde being read, and head_fde_ptr
and cur_fde_ptr are used to chain them up. */
Dwarf_Fde new_fde;
Dwarf_Fde head_fde_ptr = NULL;
Dwarf_Fde cur_fde_ptr;
Dwarf_Word fde_count = 0;
/*
Points to a list of contiguous pointers to Dwarf_Fde
structures. */
Dwarf_Fde *fde_list_ptr;
/*
Is used to check the offset field in the Fde by checking for a
Cie at this address. */
Dwarf_Small *fde_cie_ptr;
Dwarf_Word leb128_length;
Dwarf_Word i, j;
int res;
Dwarf_Word last_cie_index;
Dwarf_Small *prev_augmentation_cie_ptr = 0;
Dwarf_Small *prev_augmentation_ptr = 0;
frame_ptr = section_ptr;
if (frame_ptr == 0) {
return DW_DLV_NO_ENTRY;
}
while (frame_ptr < section_ptr + section_length) {
Dwarf_Small *cie_ptr_addr = 0;
int local_extension_size = 0;
int local_length_size = 0;
start_frame_ptr = frame_ptr;
/* READ_AREA_LENGTH updates frame_ptr for consumed bytes */
READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
frame_ptr, local_length_size,
local_extension_size);
if (length % local_length_size != 0) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
return (DW_DLV_ERROR);
}
if (length == 0) {
/* nul bytes at end of section, seen at end of egcs
eh_frame sections (in a.out). Take this as meaning no
more CIE/FDE data. We should be very close to end of
section. */
break;
}
cie_ptr_addr = frame_ptr;
READ_UNALIGNED(dbg, cie_id, Dwarf_Unsigned,
frame_ptr, local_length_size);
SIGN_EXTEND(cie_id, local_length_size);
cie_base_offset = cie_id; /* if this is a CIE, this is
ignored. If it is an FDE,
this is the section offset
that allows us to get to the
cie of this fde. Save it for
the fde part of the 'if'
below */
frame_ptr += local_length_size;
if (cie_id == cie_id_value) {
/* egcs-1.1.2 .eh_frame uses 0 as the distinguishing id.
sgi uses -1 (in .debug_frame). .eh_frame not quite
identical to .debug_frame */
/* this is a CIE, Common Information Entry: See the dwarf
spec, section 6.4.1 */
version = *(Dwarf_Small *) frame_ptr;
frame_ptr++;
if (version != DW_CIE_VERSION &&
version != DW_CIE_VERSION3) {
_dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD);
return (DW_DLV_ERROR);
}
augmentation = frame_ptr;
frame_ptr = frame_ptr + strlen((char *) frame_ptr) + 1;
if ((strcmp((char *) augmentation,
DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) ||
(strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) {
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(frame_ptr, lreg)
code_alignment_factor = (Dwarf_Word) lreg;
data_alignment_factor =
(Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr,
&leb128_length);
frame_ptr = frame_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) frame_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error,
DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
frame_ptr++;
} else if (augmentation[0] == 'z') {
/* The augmentation starts with a known prefix. See the
dwarf_frame.h for details on the layout. */
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(frame_ptr, lreg)
code_alignment_factor = (Dwarf_Word) lreg;
data_alignment_factor =
(Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr,
&leb128_length);
frame_ptr = frame_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) frame_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error,
DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
frame_ptr++;
/* Decode the length of augmented fields. */
DECODE_LEB128_UWORD(frame_ptr, lreg)
length_of_augmented_fields = (Dwarf_Word) lreg;
/* set the frame_ptr to point at the instruction start.
*/
frame_ptr += length_of_augmented_fields;
} else if (0 == strcmp((const char *) augmentation, "eh")) {
/*REFERENCED*/ /* Not used in this instance of the macro */
Dwarf_Unsigned exception_table_addr;
/* this is per egcs-1.1.2 as on RH 6.0 */
READ_UNALIGNED(dbg, exception_table_addr,
Dwarf_Unsigned, frame_ptr,
local_length_size);
frame_ptr += local_length_size;
code_alignment_factor =
(Dwarf_Word) _dwarf_decode_s_leb128(frame_ptr,
&leb128_length);
frame_ptr = frame_ptr + leb128_length;
data_alignment_factor =
(Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr,
&leb128_length);
frame_ptr = frame_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) frame_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error,
DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
frame_ptr++;
} else {
/* We do not understand the augmentation string. No
assumption can be made about any fields other than
what we have already read. */
frame_ptr = start_frame_ptr + length + local_length_size
+ local_extension_size;
/* FIX -- What are the values of data_alignment_factor,
code_alignement_factor, return_address_register and
instruction start? They were clearly uninitalized in
the previous version and I am leaving them the same
way. */
}
new_cie = (Dwarf_Cie) _dwarf_get_alloc(dbg, DW_DLA_CIE, 1);
if (new_cie == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
new_cie->ci_cie_version_number = version;
new_cie->ci_initial_table = NULL;
new_cie->ci_length = (Dwarf_Word) length;
new_cie->ci_length_size = local_length_size;
new_cie->ci_extension_size = local_extension_size;
new_cie->ci_augmentation = (char *) augmentation;
new_cie->ci_data_alignment_factor =
(Dwarf_Sbyte) data_alignment_factor;
new_cie->ci_code_alignment_factor =
(Dwarf_Small) code_alignment_factor;
new_cie->ci_return_address_register =
return_address_register;
new_cie->ci_cie_start = start_frame_ptr;
new_cie->ci_cie_instr_start = frame_ptr;
new_cie->ci_dbg = dbg;
cie_count++;
if (head_cie_ptr == NULL)
head_cie_ptr = cur_cie_ptr = new_cie;
else {
cur_cie_ptr->ci_next = new_cie;
cur_cie_ptr = new_cie;
}
} else {
/* this is an FDE, Frame Description Entry, see the Dwarf
Spec, section 6.4.1 */
Dwarf_Small *cieptr;
Dwarf_Small *initloc = frame_ptr;
Dwarf_Signed offset_into_exception_tables
/* must be min dwarf_sfixed in size */
= (Dwarf_Signed) DW_DLX_NO_EH_OFFSET;
READ_UNALIGNED(dbg, initial_location, Dwarf_Addr,
frame_ptr, dbg->de_pointer_size);
frame_ptr += dbg->de_pointer_size;
READ_UNALIGNED(dbg, address_range, Dwarf_Addr,
frame_ptr, dbg->de_pointer_size);
frame_ptr += dbg->de_pointer_size;
/* Get the augmentation string from Cie to identify the
layout of this Fde. */
if (use_gnu_cie_calc) {
/* cie_id value is offset, in section, of the cie_id
itself, to use vm ptr of the value, less the value,
to get to the cie itself. In addition, munge
cie_base_offset to look *as if* it was from real
dwarf. */
cieptr = cie_ptr_addr - cie_base_offset;
cie_base_offset = cieptr - section_ptr;
} else {
/* Traditional dwarf section offset is in cie_id */
cieptr =
(Dwarf_Small *) (section_ptr + cie_base_offset);
}
if (prev_augmentation_cie_ptr == cieptr &&
prev_augmentation_ptr != NULL) {
augmentation = prev_augmentation_ptr;
} else {
res = get_augmentation_string(dbg,
cieptr,
cie_id_value,
&augmentation, error);
if (res != DW_DLV_OK) {
return res;
}
prev_augmentation_cie_ptr = cieptr;
prev_augmentation_ptr = augmentation;
}
if ((strcmp((char *) augmentation,
DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) ||
(strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) {
/* We are pointing at the start of instructions. Do
nothing. */
} else if (augmentation[0] == 'z') {
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(frame_ptr, lreg)
length_of_augmented_fields = (Dwarf_Word) lreg;
saved_frame_ptr = frame_ptr;
if (strcmp((char *) augmentation,
DW_CIE_AUGMENTER_STRING_V0) == 0) {
/* The first word is an offset into execption
tables. */
/* ?? THis presumes that the offset is always 32
bits */
READ_UNALIGNED(dbg, offset_into_exception_tables,
Dwarf_Addr, frame_ptr,
sizeof(Dwarf_sfixed));
SIGN_EXTEND(offset_into_exception_tables,
sizeof(Dwarf_sfixed));
frame_ptr += local_length_size;
}
frame_ptr =
saved_frame_ptr + length_of_augmented_fields;
} else if (strcmp((const char *) augmentation, "eh") == 0) {
/* gnu eh fde case. we do not need to do anything */
/*REFERENCED*/ /* Not used in this instance of the macro */
Dwarf_Unsigned exception_table_addr;
READ_UNALIGNED(dbg, exception_table_addr,
Dwarf_Unsigned, frame_ptr,
dbg->de_pointer_size);
frame_ptr += dbg->de_pointer_size;
} else {
/* We do not understand the augmentation string. No
assumption can be made about if the instructions is
present. */
/* FIX -- The old code assumed that the instruction
table starts at the location pointed to by
frame_ptr, clearly incorrect. */
}
new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1);
if (new_fde == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
new_fde->fd_length = (Dwarf_Word) length;
new_fde->fd_length_size = local_length_size;
new_fde->fd_extension_size = local_extension_size;
new_fde->fd_cie_offset = cie_base_offset;
new_fde->fd_initial_location = initial_location;
new_fde->fd_initial_loc_pos = initloc;
new_fde->fd_address_range = address_range;
new_fde->fd_fde_start = start_frame_ptr;
new_fde->fd_fde_instr_start = frame_ptr;
new_fde->fd_dbg = dbg;
new_fde->fd_offset_into_exception_tables =
offset_into_exception_tables;
new_fde->fd_section_ptr = section_ptr;
new_fde->fd_section_length = section_length;
new_fde->fd_section_index = section_index;
fde_count++;
if (head_fde_ptr == NULL)
head_fde_ptr = cur_fde_ptr = new_fde;
else {
cur_fde_ptr->fd_next = new_fde;
cur_fde_ptr = new_fde;
}
}
/* Skip over instructions to start of next frame. */
frame_ptr = start_frame_ptr + length + local_length_size +
local_extension_size;
}
if (cie_count > 0) {
cie_list_ptr = (Dwarf_Cie *)
_dwarf_get_alloc(dbg, DW_DLA_LIST, cie_count);
} else {
return (DW_DLV_NO_ENTRY);
}
if (cie_list_ptr == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
/* Return arguments. */
*cie_data = cie_list_ptr;
*cie_element_count = cie_count;
dbg->de_cie_data = cie_list_ptr;
dbg->de_cie_count = cie_count;
cur_cie_ptr = head_cie_ptr;
for (i = 0; i < cie_count; i++) {
*(cie_list_ptr + i) = cur_cie_ptr;
cur_cie_ptr = cur_cie_ptr->ci_next;
}
if (fde_count > 0) {
fde_list_ptr = (Dwarf_Fde *)
_dwarf_get_alloc(dbg, DW_DLA_LIST, fde_count);
} else {
return (DW_DLV_NO_ENTRY);
}
if (fde_list_ptr == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
/* Return arguments. */
*fde_data = fde_list_ptr;
*fde_element_count = fde_count;
dbg->de_fde_data = fde_list_ptr;
dbg->de_fde_count = fde_count;
last_cie_index = 0;
cur_fde_ptr = head_fde_ptr;
for (i = 0; i < fde_count; i++) {
Dwarf_Sword new_cie_index = (Dwarf_Sword) cie_count;
*(fde_list_ptr + i) = cur_fde_ptr;
fde_cie_ptr = (Dwarf_Small *) (section_ptr +
cur_fde_ptr->fd_cie_offset);
/* we assume that the next fde has the same cie as the ** last
fde and resume the search where we left off */
for (j = last_cie_index; j < cie_count; j++) {
Dwarf_Cie ciep = (Dwarf_Cie) * (cie_list_ptr + j);
if (ciep->ci_cie_start == fde_cie_ptr) {
new_cie_index = (Dwarf_Sword) j;
break;
}
}
/* did not find it above, start from 0 and try again */
if (new_cie_index == cie_count) {
for (j = 0; j < last_cie_index; ++j) {
Dwarf_Cie ciep = (Dwarf_Cie) * (cie_list_ptr + j);
if (ciep->ci_cie_start == fde_cie_ptr) {
new_cie_index = (Dwarf_Sword) j;
break;
}
}
}
j = new_cie_index;
last_cie_index = new_cie_index;
if (j == cie_count) {
_dwarf_error(dbg, error, DW_DLE_NO_CIE_FOR_FDE);
return (DW_DLV_ERROR);
} else {
cur_fde_ptr->fd_cie_index = (Dwarf_Sword) j;
cur_fde_ptr->fd_cie = *(cie_list_ptr + j);
}
cur_fde_ptr = cur_fde_ptr->fd_next;
}
/* sort the list by the address, so that dwarf_get_fde_at_pc() can
binary search this list. */
qsort((void *) fde_list_ptr, fde_count, sizeof(Dwarf_Ptr),
qsort_compare);
return (DW_DLV_OK);
}
/*
Only works on dwarf sections, not eh_frame
*/
int
dwarf_get_fde_for_die(Dwarf_Debug dbg,
Dwarf_Die die,
Dwarf_Fde * ret_fde, Dwarf_Error * error)
{
Dwarf_Attribute attr;
Dwarf_Unsigned fde_offset;
Dwarf_Signed signdval;
Dwarf_Unsigned length; /* must be min de_length_size bytes */
Dwarf_Signed signed_offset; /* must be min de_length_size bytes */
Dwarf_Addr initial_location; /* must be min de_pointer_size
bytes */
Dwarf_Addr address_range; /* must be min de_pointer_size bytes */
Dwarf_Fde new_fde;
unsigned char *fde_ptr;
Dwarf_Small *saved_fde_ptr;
unsigned char *cie_ptr;
unsigned char *start_cie_ptr;
Dwarf_Cie new_cie;
/* Fields for the current Cie being read. */
Dwarf_Small version;
Dwarf_Small *augmentation;
Dwarf_Word code_alignment_factor;
Dwarf_Sword data_alignment_factor;
Dwarf_Small return_address_register;
Dwarf_Word length_of_augmented_fields;
Dwarf_Signed offset_into_exception_tables =
(Dwarf_Signed) DW_DLX_NO_EH_OFFSET;
int res;
int resattr;
int sdatares;
int fde_local_extension_size = 0;
int fde_local_length_size = 0;
int cie_local_extension_size = 0;
int cie_local_length_size = 0;
Dwarf_Word leb128_length;
if (die == NULL) {
_dwarf_error(NULL, error, DW_DLE_DIE_NULL);
return (DW_DLV_ERROR);
}
resattr = dwarf_attr(die, DW_AT_MIPS_fde, &attr, error);
if (resattr != DW_DLV_OK) {
return resattr;
}
/* why is this formsdata? FIX */
sdatares = dwarf_formsdata(attr, &signdval, error);
if (sdatares != DW_DLV_OK) {
return sdatares;
}
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_index,
&dbg->de_debug_frame,
error);
if (res != DW_DLV_OK) {
return res;
}
fde_offset = signdval;
fde_ptr = (dbg->de_debug_frame + fde_offset);
/* READ_AREA_LENGTH updates fde_ptr for consumed bytes */
READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
fde_ptr, fde_local_length_size,
fde_local_extension_size);
if (length % fde_local_length_size != 0) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
return (DW_DLV_ERROR);
}
READ_UNALIGNED(dbg, signed_offset, Dwarf_Signed,
fde_ptr, fde_local_length_size);
SIGN_EXTEND(signed_offset, fde_local_length_size);
fde_ptr += fde_local_length_size;
READ_UNALIGNED(dbg, initial_location, Dwarf_Addr,
fde_ptr, dbg->de_pointer_size);
fde_ptr += dbg->de_pointer_size;
READ_UNALIGNED(dbg, address_range, Dwarf_Addr,
fde_ptr, dbg->de_pointer_size);
fde_ptr += dbg->de_pointer_size;
res = get_augmentation_string(dbg,
(Dwarf_Small *) (dbg->de_debug_frame +
signed_offset),
DW_CIE_ID, &augmentation, error);
if (res != DW_DLV_OK) {
return res;
}
if ((strcmp((char *) augmentation, DW_DEBUG_FRAME_AUGMENTER_STRING)
== 0) ||
(strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) {
/* Do nothing. The fde_ptr is pointing at start of
instructions. */
} else if (augmentation[0] == 'z') {
/* The augmentation starts with a known prefix. See the
dwarf_frame.h for details on the layout. */
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(fde_ptr, lreg)
length_of_augmented_fields = (Dwarf_Word) lreg;
saved_fde_ptr = fde_ptr;
if (strcmp((char *) augmentation, DW_CIE_AUGMENTER_STRING_V0) ==
0) {
/* The first word is an offset into execption tables. */
READ_UNALIGNED(dbg, offset_into_exception_tables,
Dwarf_Signed, fde_ptr, sizeof(Dwarf_sfixed));
SIGN_EXTEND(offset_into_exception_tables,
sizeof(Dwarf_sfixed));
fde_ptr += sizeof(Dwarf_sfixed);
}
fde_ptr = saved_fde_ptr + length_of_augmented_fields;
} else {
/* We do not understand the augmentation string. No assumption
can be made about if the instructions is present. */
/* FIX -- The old code assumed that the instruction table
starts at location pointed to by fde_ptr, clearly incorrect.
*/
}
new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1);
if (new_fde == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
new_fde->fd_length = (Dwarf_Word) length;
new_fde->fd_length_size = fde_local_length_size;
new_fde->fd_extension_size = fde_local_extension_size;
new_fde->fd_cie_offset = signed_offset;
new_fde->fd_initial_location = initial_location;
new_fde->fd_address_range = address_range;
new_fde->fd_fde_start = dbg->de_debug_frame + fde_offset;
new_fde->fd_fde_instr_start = (Dwarf_Small *) fde_ptr;
new_fde->fd_dbg = dbg;
new_fde->fd_offset_into_exception_tables =
offset_into_exception_tables;
new_fde->fd_section_ptr = dbg->de_debug_frame;
new_fde->fd_section_length = dbg->de_debug_frame_size;
new_fde->fd_section_index = dbg->de_debug_frame_index;
/* now read the cie corresponding to the fde */
cie_ptr = (dbg->de_debug_frame + signed_offset);
start_cie_ptr = cie_ptr;
/* READ_AREA_LENGTH updates cie_ptr for consumed bytes */
READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
cie_ptr, cie_local_length_size,
cie_local_extension_size);
if (length % cie_local_length_size != 0) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
return (DW_DLV_ERROR);
}
READ_UNALIGNED(dbg, signed_offset, Dwarf_Signed,
cie_ptr, cie_local_length_size);
SIGN_EXTEND(signed_offset, cie_local_length_size);
cie_ptr += cie_local_length_size;
if (signed_offset == DW_CIE_ID) {
version = *(Dwarf_Small *) cie_ptr;
cie_ptr++;
if (version != DW_CIE_VERSION &&
version != DW_CIE_VERSION3) {
_dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD);
return (DW_DLV_ERROR);
}
augmentation = cie_ptr;
cie_ptr = cie_ptr + strlen((char *) cie_ptr) + 1;
if ((strcmp((char *) augmentation,
DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) ||
(strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) {
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(cie_ptr, lreg)
code_alignment_factor = (Dwarf_Word) lreg;
data_alignment_factor = (Dwarf_Sword)
_dwarf_decode_s_leb128(cie_ptr, &leb128_length);
cie_ptr = cie_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) cie_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
cie_ptr++;
} else if (augmentation[0] == 'z') {
/* The augmentation starts with a known prefix. We can
asssume that the first field is the length of the
augmented fields. */
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(cie_ptr, lreg)
code_alignment_factor = (Dwarf_Word) lreg;
data_alignment_factor = (Dwarf_Sword)
_dwarf_decode_s_leb128(cie_ptr, &leb128_length);
cie_ptr = cie_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) cie_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
cie_ptr++;
/* Decode the length of augmented fields. */
DECODE_LEB128_UWORD(cie_ptr, lreg)
length_of_augmented_fields = (Dwarf_Word) lreg;
/* set the cie_ptr to point at the instruction start. */
cie_ptr += length_of_augmented_fields;
} else if (strcmp((const char *) augmentation, "eh") == 0) {
Dwarf_Unsigned lreg;
DECODE_LEB128_UWORD(cie_ptr, lreg)
code_alignment_factor = (Dwarf_Word) lreg;
data_alignment_factor = (Dwarf_Sword)
_dwarf_decode_s_leb128(cie_ptr, &leb128_length);
cie_ptr = cie_ptr + leb128_length;
return_address_register = *(Dwarf_Small *) cie_ptr;
if (return_address_register > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR);
return (DW_DLV_ERROR);
}
cie_ptr++;
} else {
/* We do not understand the augmentation string. No
assumption can be made about any fields other than what
we have already read. */
cie_ptr = start_cie_ptr + length + cie_local_length_size
+ cie_local_extension_size;
/* FIX -- What are the values of data_alignment_factor,
code_alignement_factor, return_address_register and
instruction start? They were clearly uninitalized in
the previous version and I am leaving them the same way.
*/
}
new_cie = (Dwarf_Cie) _dwarf_get_alloc(dbg, DW_DLA_CIE, 1);
if (new_cie == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
new_cie->ci_cie_version_number = version;
new_cie->ci_initial_table = NULL;
new_cie->ci_length = (Dwarf_Word) length;
new_cie->ci_length_size = cie_local_length_size;
new_cie->ci_extension_size = cie_local_extension_size;
new_cie->ci_augmentation = (char *) augmentation;
new_cie->ci_data_alignment_factor =
(Dwarf_Sbyte) data_alignment_factor;
new_cie->ci_code_alignment_factor =
(Dwarf_Small) code_alignment_factor;
new_cie->ci_return_address_register = return_address_register;
new_cie->ci_cie_start = start_cie_ptr;
new_cie->ci_cie_instr_start = cie_ptr;
new_cie->ci_dbg = dbg;
} else {
_dwarf_error(dbg, error, DW_DLE_NO_CIE_FOR_FDE);
return (DW_DLV_ERROR);
}
new_fde->fd_cie = new_cie;
*ret_fde = new_fde;
return DW_DLV_OK;
}
int
dwarf_get_fde_range(Dwarf_Fde fde,
Dwarf_Addr * low_pc,
Dwarf_Unsigned * func_length,
Dwarf_Ptr * fde_bytes,
Dwarf_Unsigned * fde_byte_length,
Dwarf_Off * cie_offset,
Dwarf_Signed * cie_index,
Dwarf_Off * fde_offset, Dwarf_Error * error)
{
Dwarf_Debug dbg;
if (fde == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
dbg = fde->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
/* We have always already done the section load here, so
no need to load the section.
We did the section load in order to create the Dwarf_Fde pointer
passed in here. */
if (low_pc != NULL)
*low_pc = fde->fd_initial_location;
if (func_length != NULL)
*func_length = fde->fd_address_range;
if (fde_bytes != NULL)
*fde_bytes = fde->fd_fde_start;
if (fde_byte_length != NULL)
*fde_byte_length = fde->fd_length;
if (cie_offset != NULL)
*cie_offset = fde->fd_cie_offset;
if (cie_index != NULL)
*cie_index = fde->fd_cie_index;
if (fde_offset != NULL)
*fde_offset = fde->fd_fde_start - fde->fd_section_ptr;
return DW_DLV_OK;
}
int
dwarf_get_fde_exception_info(Dwarf_Fde fde,
Dwarf_Signed *
offset_into_exception_tables,
Dwarf_Error * error)
{
Dwarf_Debug dbg;
dbg = fde->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
*offset_into_exception_tables =
fde->fd_offset_into_exception_tables;
return DW_DLV_OK;
}
int
dwarf_get_cie_info(Dwarf_Cie cie,
Dwarf_Unsigned * bytes_in_cie,
Dwarf_Small * ptr_to_version,
char **augmenter,
Dwarf_Unsigned * code_alignment_factor,
Dwarf_Signed * data_alignment_factor,
Dwarf_Half * return_address_register,
Dwarf_Ptr * initial_instructions,
Dwarf_Unsigned * initial_instructions_length,
Dwarf_Error * error)
{
Dwarf_Debug dbg;
if (cie == NULL) {
_dwarf_error(NULL, error, DW_DLE_CIE_NULL);
return (DW_DLV_ERROR);
}
dbg = cie->ci_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_CIE_DBG_NULL);
return (DW_DLV_ERROR);
}
if (ptr_to_version != NULL)
*ptr_to_version = cie->ci_cie_version_number;
if (augmenter != NULL)
*augmenter = cie->ci_augmentation;
if (code_alignment_factor != NULL)
*code_alignment_factor = cie->ci_code_alignment_factor;
if (data_alignment_factor != NULL)
*data_alignment_factor = cie->ci_data_alignment_factor;
if (return_address_register != NULL)
*return_address_register = cie->ci_return_address_register;
if (initial_instructions != NULL)
*initial_instructions = cie->ci_cie_instr_start;
if (initial_instructions_length != NULL) {
*initial_instructions_length = cie->ci_length +
cie->ci_length_size +
cie->ci_extension_size -
(cie->ci_cie_instr_start - cie->ci_cie_start);
}
*bytes_in_cie = (cie->ci_length);
return (DW_DLV_OK);
}
static int
_dwarf_get_fde_info_for_a_pc_row(Dwarf_Fde fde,
Dwarf_Addr pc_requested,
Dwarf_Frame table, Dwarf_Error * error)
/* Return the register rules for all registers at a given pc. */
{
Dwarf_Debug dbg;
Dwarf_Cie cie;
Dwarf_Sword i;
int dw_err;
Dwarf_Sword icount;
int res;
if (fde == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
dbg = fde->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
if (pc_requested < fde->fd_initial_location ||
pc_requested >=
fde->fd_initial_location + fde->fd_address_range) {
_dwarf_error(dbg, error, DW_DLE_PC_NOT_IN_FDE_RANGE);
return (DW_DLV_ERROR);
}
cie = fde->fd_cie;
if (cie->ci_initial_table == NULL) {
cie->ci_initial_table = _dwarf_get_alloc(dbg, DW_DLA_FRAME, 1);
if (cie->ci_initial_table == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++) {
cie->ci_initial_table->fr_reg[i].ru_is_off = 0;
cie->ci_initial_table->fr_reg[i].ru_register =
DW_FRAME_SAME_VAL;
cie->ci_initial_table->fr_reg[i].ru_offset = 0;
}
res = _dwarf_exec_frame_instr( /* make_instr= */ false,
/* ret_frame_instr= */ NULL,
/* search_pc */ false,
/* search_pc_val */ 0,
/* location */ 0,
cie->ci_cie_instr_start,
cie->ci_cie_instr_start +
(cie->ci_length +
cie->ci_length_size +
cie->ci_extension_size -
(cie->ci_cie_instr_start -
cie->ci_cie_start)),
cie->ci_initial_table, cie, dbg,
&icount, &dw_err);
if (res == DW_DLV_ERROR) {
_dwarf_error(dbg, error, dw_err);
return (res);
} else if (res == DW_DLV_NO_ENTRY) {
return res;
}
}
res = _dwarf_exec_frame_instr( /* make_instr= */ false,
/* ret_frame_instr= */ NULL,
/* search_pc */ true,
/* search_pc_val */ pc_requested,
fde->fd_initial_location,
fde->fd_fde_instr_start,
fde->fd_fde_start + fde->fd_length +
fde->fd_length_size +
fde->fd_extension_size,
table, cie, dbg, &icount, &dw_err);
if (res == DW_DLV_ERROR) {
_dwarf_error(dbg, error, dw_err);
return (res);
} else if (res == DW_DLV_NO_ENTRY) {
return res;
}
return DW_DLV_OK;
}
int
dwarf_get_fde_info_for_all_regs(Dwarf_Fde fde,
Dwarf_Addr pc_requested,
Dwarf_Regtable * reg_table,
Dwarf_Addr * row_pc,
Dwarf_Error * error)
{
struct Dwarf_Frame_s fde_table;
Dwarf_Sword i;
int res;
/* _dwarf_get_fde_info_for_a_pc_row will perform more sanity checks
*/
res = _dwarf_get_fde_info_for_a_pc_row(fde, pc_requested,
&fde_table, error);
if (res != DW_DLV_OK) {
return res;
}
for (i = 0; i < DW_REG_TABLE_SIZE; i++) {
reg_table->rules[i].dw_offset_relevant =
fde_table.fr_reg[i].ru_is_off;
reg_table->rules[i].dw_regnum = fde_table.fr_reg[i].ru_register;
reg_table->rules[i].dw_offset = fde_table.fr_reg[i].ru_offset;
}
if (row_pc != NULL)
*row_pc = fde_table.fr_loc;
return DW_DLV_OK;
}
int
dwarf_get_fde_info_for_reg(Dwarf_Fde fde,
Dwarf_Half table_column,
Dwarf_Addr pc_requested,
Dwarf_Signed * offset_relevant,
Dwarf_Signed * register_num,
Dwarf_Signed * offset,
Dwarf_Addr * row_pc, Dwarf_Error * error)
{
struct Dwarf_Frame_s fde_table;
int res;
if (table_column > DW_FRAME_LAST_REG_NUM) {
_dwarf_error(NULL, error, DW_DLE_FRAME_TABLE_COL_BAD);
return (DW_DLV_ERROR);
}
/* _dwarf_get_fde_info_for_a_pc_row will perform more sanity checks
*/
res =
_dwarf_get_fde_info_for_a_pc_row(fde, pc_requested, &fde_table,
error);
if (res != DW_DLV_OK) {
return res;
}
if (register_num != NULL)
*register_num = fde_table.fr_reg[table_column].ru_register;
if (offset != NULL)
*offset = fde_table.fr_reg[table_column].ru_offset;
if (row_pc != NULL)
*row_pc = fde_table.fr_loc;
*offset_relevant = (fde_table.fr_reg[table_column].ru_is_off);
return DW_DLV_OK;
}
/*
Return pointer to the instructions in the dwarf
fde.
*/
int
dwarf_get_fde_instr_bytes(Dwarf_Fde inFde, Dwarf_Ptr * outinstraddr,
Dwarf_Unsigned * outaddrlen,
Dwarf_Error * error)
{
Dwarf_Unsigned len;
unsigned char *instrs;
Dwarf_Debug dbg;
if (inFde == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
dbg = inFde->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
instrs = inFde->fd_fde_instr_start,
len = (inFde->fd_fde_start + inFde->fd_length +
inFde->fd_length_size + inFde->fd_extension_size)
- instrs;
*outinstraddr = instrs;
*outaddrlen = len;
return DW_DLV_OK;
}
int
dwarf_get_fde_n(Dwarf_Fde * fde_data,
Dwarf_Unsigned fde_index,
Dwarf_Fde * returned_fde, Dwarf_Error * error)
{
Dwarf_Debug dbg;
if (fde_data == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_PTR_NULL);
return (DW_DLV_ERROR);
}
if (*fde_data == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
dbg = (*fde_data)->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
if (fde_index >= dbg->de_fde_count) {
return (DW_DLV_NO_ENTRY);
}
*returned_fde = (*(fde_data + fde_index));
return DW_DLV_OK;
}
/*
Lopc and hipc are extensions to the interface to
return the range of addresses that are described
by the returned fde.
*/
int
dwarf_get_fde_at_pc(Dwarf_Fde * fde_data,
Dwarf_Addr pc_of_interest,
Dwarf_Fde * returned_fde,
Dwarf_Addr * lopc,
Dwarf_Addr * hipc, Dwarf_Error * error)
{
Dwarf_Debug dbg;
Dwarf_Fde fde = NULL;
if (fde_data == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_PTR_NULL);
return (DW_DLV_ERROR);
}
if (*fde_data == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_NULL);
return (DW_DLV_ERROR);
}
dbg = (*fde_data)->fd_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL);
return (DW_DLV_ERROR);
}
{
/* The fde's are sorted by their addresses. Binary search to
find correct fde. */
int low = 0;
int high = dbg->de_fde_count - 1;
int middle = 0;
Dwarf_Fde cur_fde;
while (low <= high) {
middle = (low + high) / 2;
cur_fde = fde_data[middle];
if (pc_of_interest < cur_fde->fd_initial_location) {
high = middle - 1;
} else if (pc_of_interest >=
(cur_fde->fd_initial_location +
cur_fde->fd_address_range)) {
low = middle + 1;
} else {
fde = fde_data[middle];
break;
}
}
}
if (fde) {
if (lopc != NULL)
*lopc = fde->fd_initial_location;
if (hipc != NULL)
*hipc = fde->fd_initial_location +
fde->fd_address_range - 1;
*returned_fde = fde;
return (DW_DLV_OK);
}
return (DW_DLV_NO_ENTRY);
}
int
dwarf_expand_frame_instructions(Dwarf_Debug dbg,
Dwarf_Ptr instruction,
Dwarf_Unsigned i_length,
Dwarf_Frame_Op ** returned_op_list,
Dwarf_Signed * returned_op_count,
Dwarf_Error * error)
{
Dwarf_Sword instr_count;
int res;
int dw_err;
if (dbg == 0) {
_dwarf_error(NULL, error, DW_DLE_DBG_NULL);
return (DW_DLV_ERROR);
}
if (returned_op_list == 0 || returned_op_count == 0) {
_dwarf_error(dbg, error, DW_DLE_RET_OP_LIST_NULL);
return (DW_DLV_ERROR);
}
/* The cast to Dwarf_Ptr may get a compiler warning, but it is safe
as it is just an i_length offset from 'instruction' itself. A
caller has made a big mistake if the result is not a valid
pointer. */
res = _dwarf_exec_frame_instr( /* make_instr= */ true,
returned_op_list,
/* search_pc */ false,
/* search_pc_val */ 0,
/* location */ 0,
instruction,
(Dwarf_Ptr) ((Dwarf_Unsigned)
instruction + i_length),
/* Dwarf_Frame */ NULL,
/* cie_ptr */ NULL,
dbg, &instr_count, &dw_err);
if (res != DW_DLV_OK) {
if (res == DW_DLV_ERROR) {
_dwarf_error(dbg, error, dw_err);
}
return (res);
}
*returned_op_count = instr_count;
return DW_DLV_OK;
}
/*
Used by rqs. Returns DW_DLV_OK if returns the arrays.
Returns DW_DLV_NO_ENTRY if no section. ?? (How do I tell?)
Returns DW_DLV_ERROR if there is an error.
*/
int
_dwarf_frame_address_offsets(Dwarf_Debug dbg, Dwarf_Addr ** addrlist,
Dwarf_Off ** offsetlist,
Dwarf_Signed * returncount,
Dwarf_Error * err)
{
int retval = DW_DLV_OK;
int res;
Dwarf_Cie *cie_data;
Dwarf_Signed cie_count;
Dwarf_Fde *fde_data;
Dwarf_Signed fde_count;
Dwarf_Signed i;
Dwarf_Frame_Op *frame_inst;
Dwarf_Fde fdep;
Dwarf_Cie ciep;
Dwarf_Chain curr_chain = 0;
Dwarf_Chain head_chain = 0;
Dwarf_Chain prev_chain = 0;
Dwarf_Arange arange;
Dwarf_Unsigned arange_count = 0;
Dwarf_Addr *arange_addrs = 0;
Dwarf_Off *arange_offsets = 0;
res = dwarf_get_fde_list(dbg, &cie_data, &cie_count,
&fde_data, &fde_count, err);
if (res != DW_DLV_OK) {
return res;
}
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_index,
&dbg->de_debug_frame,
err);
if (res != DW_DLV_OK) {
return res;
}
for (i = 0; i < cie_count; i++) {
Dwarf_Off instoff = 0;
Dwarf_Signed initial_instructions_length = 0;
Dwarf_Small *instr_end = 0;
Dwarf_Sword icount = 0;
int j;
int dw_err;
ciep = cie_data[i];
instoff = ciep->ci_cie_instr_start - dbg->de_debug_frame;
initial_instructions_length = ciep->ci_length +
ciep->ci_length_size + ciep->ci_extension_size -
(ciep->ci_cie_instr_start - ciep->ci_cie_start);
instr_end = ciep->ci_cie_instr_start +
initial_instructions_length;
res = _dwarf_exec_frame_instr( /* make_instr */ true,
&frame_inst,
/* search_pc= */ false,
/* search_pc_val= */ 0,
/* location */ 0,
ciep->ci_cie_instr_start,
instr_end,
/* Dwarf_frame= */ 0,
/* cie= */ 0,
dbg, &icount, &dw_err);
if (res == DW_DLV_ERROR) {
_dwarf_error(dbg, err, dw_err);
return (res);
} else if (res == DW_DLV_NO_ENTRY) {
continue;
}
for (j = 0; j < icount; ++j) {
Dwarf_Frame_Op *finst = frame_inst + j;
if (finst->fp_base_op == 0 && finst->fp_extended_op == 1) {
/* is DW_CFA_set_loc */
Dwarf_Addr add = (Dwarf_Addr) finst->fp_offset;
Dwarf_Off off = finst->fp_instr_offset + instoff;
arange = (Dwarf_Arange)
_dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
if (arange == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
arange->ar_address = add;
arange->ar_info_offset = off;
arange_count++;
curr_chain = (Dwarf_Chain)
_dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
if (curr_chain == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
curr_chain->ch_item = arange;
if (head_chain == NULL)
head_chain = prev_chain = curr_chain;
else {
prev_chain->ch_next = curr_chain;
prev_chain = curr_chain;
}
}
}
dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK);
}
for (i = 0; i < fde_count; i++) {
Dwarf_Small *instr_end = 0;
Dwarf_Sword icount = 0;
Dwarf_Signed instructions_length = 0;
Dwarf_Off instoff = 0;
Dwarf_Off off = 0;
Dwarf_Addr addr = 0;
int j;
int dw_err;
fdep = fde_data[i];
off = fdep->fd_initial_loc_pos - dbg->de_debug_frame;
addr = fdep->fd_initial_location;
arange = (Dwarf_Arange)
_dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
if (arange == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
arange->ar_address = addr;
arange->ar_info_offset = off;
arange_count++;
curr_chain = (Dwarf_Chain)
_dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
if (curr_chain == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
curr_chain->ch_item = arange;
if (head_chain == NULL)
head_chain = prev_chain = curr_chain;
else {
prev_chain->ch_next = curr_chain;
prev_chain = curr_chain;
}
instoff = fdep->fd_fde_instr_start - dbg->de_debug_frame;
instructions_length = fdep->fd_length +
fdep->fd_length_size + fdep->fd_extension_size -
(fdep->fd_fde_instr_start - fdep->fd_fde_start);
instr_end = fdep->fd_fde_instr_start + instructions_length;
res = _dwarf_exec_frame_instr( /* make_instr */ true,
&frame_inst,
/* search_pc= */ false,
/* search_pc_val= */ 0,
/* location */ 0,
fdep->fd_fde_instr_start,
instr_end,
/* Dwarf_frame= */ 0,
/* cie= */ 0,
dbg, &icount, &dw_err);
if (res == DW_DLV_ERROR) {
_dwarf_error(dbg, err, dw_err);
return (res);
} else if (res == DW_DLV_NO_ENTRY) {
continue;
}
for (j = 0; j < icount; ++j) {
Dwarf_Frame_Op *finst2 = frame_inst + j;
if (finst2->fp_base_op == 0 && finst2->fp_extended_op == 1) {
/* is DW_CFA_set_loc */
Dwarf_Addr add = (Dwarf_Addr) finst2->fp_offset;
Dwarf_Off off = finst2->fp_instr_offset + instoff;
arange = (Dwarf_Arange)
_dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
if (arange == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
arange->ar_address = add;
arange->ar_info_offset = off;
arange_count++;
curr_chain = (Dwarf_Chain)
_dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
if (curr_chain == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
curr_chain->ch_item = arange;
if (head_chain == NULL)
head_chain = prev_chain = curr_chain;
else {
prev_chain->ch_next = curr_chain;
prev_chain = curr_chain;
}
}
}
dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK);
}
dwarf_dealloc(dbg, fde_data, DW_DLA_LIST);
dwarf_dealloc(dbg, cie_data, DW_DLA_LIST);
arange_addrs = (Dwarf_Addr *)
_dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
if (arange_addrs == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
arange_offsets = (Dwarf_Off *)
_dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
if (arange_offsets == NULL) {
_dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
curr_chain = head_chain;
for (i = 0; i < arange_count; i++) {
Dwarf_Arange ar = curr_chain->ch_item;
arange_addrs[i] = ar->ar_address;
arange_offsets[i] = ar->ar_info_offset;
prev_chain = curr_chain;
curr_chain = curr_chain->ch_next;
dwarf_dealloc(dbg, ar, DW_DLA_ARANGE);
dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN);
}
*returncount = arange_count;
*offsetlist = arange_offsets;
*addrlist = arange_addrs;
return retval;
}
/* Used by dwarfdump -v to print offsets, for debugging
dwarf info
*/
/* ARGSUSED 4 */
int
_dwarf_fde_section_offset(Dwarf_Debug dbg, Dwarf_Fde in_fde,
Dwarf_Off * fde_off, Dwarf_Off * cie_off,
Dwarf_Error * err)
{
int res;
char *start;
char *loc;
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_index,
&dbg->de_debug_frame,
err);
if (res != DW_DLV_OK) {
return res;
}
start = (char *) dbg->de_debug_frame;
loc = (char *) in_fde->fd_fde_start;
*fde_off = (loc - start);
*cie_off = in_fde->fd_cie_offset;
return DW_DLV_OK;
}
/* Used by dwarfdump -v to print offsets, for debugging
dwarf info
*/
/* ARGSUSED 4 */
int
_dwarf_cie_section_offset(Dwarf_Debug dbg, Dwarf_Cie in_cie,
Dwarf_Off * cie_off, Dwarf_Error * err)
{
int res;
char *start;
char *loc;
res =
_dwarf_load_section(dbg,
dbg->de_debug_frame_index,
&dbg->de_debug_frame,
err);
if (res != DW_DLV_OK) {
return res;
}
start = (char *) dbg->de_debug_frame;
loc = (char *) in_cie->ci_cie_start;
*cie_off = (loc - start);
return DW_DLV_OK;
}
|