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 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685
|
/*
Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright (C) 2007-2018 David Anderson. All Rights Reserved.
Portions Copyright (C) 2010-2012 SN Systems Ltd. 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., 51 Franklin Street - Fifth
Floor, Boston MA 02110-1301, USA.
*/
#include "config.h"
#include <stdio.h> /* for debugging only. */
#ifdef HAVE_STDINT_H
#include <stdint.h> /* For uintptr_t */
#endif /* HAVE_STDINT_H */
#ifdef HAVE_STDLIB_H
#include <stdlib.h> /* For uintptr_t */
#endif /* HAVE_STDLIB_H */
#include "dwarf_incl.h"
#include "dwarf_alloc.h"
#include "dwarf_error.h"
#include "dwarf_util.h"
#include "dwarf_loc.h"
#include "dwarfstring.h"
#define TRUE 1
#define FALSE 0
static int _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
Dwarf_Block_c * return_block,
Dwarf_Addr * lowpc,
Dwarf_Addr * highpc,
Dwarf_Bool * at_end,
Dwarf_Half * lle_op,
Dwarf_Off sec_offset,
Dwarf_Half address_size,
Dwarf_Half lkind,
Dwarf_Error *error);
/* Used to enable sanity checking of these data items before we return
to caller. */
int
_dwarf_locdesc_c_constructor(Dwarf_Debug dbg, void *locd)
{
Dwarf_Locdesc_c ldp = (Dwarf_Locdesc_c)locd;
if (!dbg) {
return DW_DLV_ERROR;
}
ldp->ld_lle_value = DW_LLE_VALUE_BOGUS;
ldp->ld_kind = DW_LKIND_unknown;
return DW_DLV_OK;
}
static void
_dwarf_lkind_name(unsigned lkind, dwarfstring *m)
{
switch(lkind) {
case DW_LKIND_expression:
dwarfstring_append(m,"DW_LKIND_expression");
return;
case DW_LKIND_loclist:
dwarfstring_append(m,"DW_LKIND_loclist");
return;
case DW_LKIND_GNU_exp_list:
dwarfstring_append(m,"DW_LKIND_GNU_exp_list");
return;
case DW_LKIND_loclists:
dwarfstring_append(m,"DW_LKIND_loclists");
return;
case DW_LKIND_unknown:
dwarfstring_append(m,"DW_LKIND_unknown");
return;
}
dwarfstring_append_printf_u(m,
"<DW_LKIND location kind is unknown and has value %u>.",
lkind);
}
static int
determine_location_lkind(unsigned int version,
unsigned int form,
UNUSEDARG unsigned int attribute,
Dwarf_Bool is_dwo)
{
switch(form) {
case DW_FORM_exprloc: /* only defined for
DW_CFA_def_cfa_expression */
case DW_FORM_block:
case DW_FORM_block1:
case DW_FORM_block2:
case DW_FORM_block4:
return DW_LKIND_expression;
break;
case DW_FORM_data4:
case DW_FORM_data8:
if (version > 1 && version < 4) {
return DW_LKIND_loclist;
}
break;
case DW_FORM_sec_offset:
if (version == 5 ) {
return DW_LKIND_loclists;
}
if (version == 4 && is_dwo ) {
return DW_LKIND_GNU_exp_list;
}
return DW_LKIND_loclist;
break;
case DW_FORM_loclistx:
if (version == 5 ) {
return DW_LKIND_loclists;
}
break;
default:
break;
}
return DW_LKIND_unknown;
}
static void
_dwarf_free_op_chain(Dwarf_Debug dbg,
Dwarf_Loc_Chain headloc)
{
Dwarf_Loc_Chain cur = headloc;
while (cur) {
Dwarf_Loc_Chain next = cur->lc_next;
dwarf_dealloc(dbg, cur, DW_DLA_LOC_CHAIN);
cur = next;
}
}
/* Given a Dwarf_Block that represents a location expression,
this function returns a pointer to a Dwarf_Locdesc struct
that has its ld_cents field set to the number of location
operators in the block, and its ld_s field pointing to a
contiguous block of Dwarf_Loc structs. However, the
ld_lopc and ld_hipc values are uninitialized. Returns
DW_DLV_ERROR on error.
Created for DWARF2 this really does not work well
as later DWARF needs the newer interface.
You want Dwarf_Locdesc_c opaque struct, not what this
function provides.
This function assumes that the length of
the block is greater than 0. Zero length location expressions
to represent variables that have been optimized away are
handled in the calling function.
address_size, offset_size, and version_stamp are
per-CU, not per-object or per dbg.
We cannot use dbg directly to get those values.
Use for DWARF 2,3,4 only to avoid updating to
later interfaces. Not for experimental
dwarf4 dwo either.
Better to switch to a newer interface.
*/
static int
_dwarf_get_locdesc(Dwarf_Debug dbg,
Dwarf_Block_c * loc_block,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small version_stamp,
Dwarf_Addr lowpc,
Dwarf_Addr highpc,
Dwarf_Small * section_end,
Dwarf_Locdesc ** locdesc_out,
Dwarf_Error * error)
{
/* Offset of current operator from start of block. */
Dwarf_Unsigned offset = 0;
/* Used to chain the Dwarf_Loc_Chain_s structs. */
Dwarf_Loc_Chain new_loc = NULL;
Dwarf_Loc_Chain prev_loc = NULL;
Dwarf_Loc_Chain head_loc = NULL;
/* Count of the number of location operators. */
Dwarf_Unsigned op_count = 0;
/* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
Dwarf_Loc *block_loc = 0;
/* Dwarf_Locdesc pointer to be returned. */
Dwarf_Locdesc *locdesc = 0;
Dwarf_Unsigned i = 0;
int res = 0;
/* ***** BEGIN CODE ***** */
offset = 0;
op_count = 0;
res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
if (res != DW_DLV_OK) {
return res;
}
/* OLD loop getting Loc operators. No DWARF5 */
while (offset <= loc_block->bl_len) {
Dwarf_Unsigned nextoffset = 0;
struct Dwarf_Loc_Expr_Op_s temp_loc;
res = _dwarf_read_loc_expr_op(dbg,loc_block,
op_count,
version_stamp,
offset_size,
address_size,
offset,
section_end,
&nextoffset,
&temp_loc,
error);
if (res == DW_DLV_ERROR) {
_dwarf_free_op_chain(dbg, head_loc);
return res;
}
if (res == DW_DLV_NO_ENTRY) {
/* Normal end. */
break;
}
op_count++;
new_loc =
(Dwarf_Loc_Chain) _dwarf_get_alloc(dbg,
DW_DLA_LOC_CHAIN, 1);
if (new_loc == NULL) {
dwarfstring m;
_dwarf_free_op_chain(dbg, head_loc);
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
" DW_DLE_ALLOC_FAIL: out of memory"
" allocating location"
" expression operator chain entry %u.",
op_count);
_dwarf_error_string(dbg, error, DW_DLE_ALLOC_FAIL,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
/* Copying only the fields needed by DWARF 2,3,4 */
new_loc->lc_atom = temp_loc.lr_atom;
new_loc->lc_opnumber= temp_loc.lr_opnumber;
new_loc->lc_number = temp_loc.lr_number;
new_loc->lc_number2 = temp_loc.lr_number2;
new_loc->lc_number3 = temp_loc.lr_number3;
new_loc->lc_raw1 = temp_loc.lr_raw1;
new_loc->lc_raw2 = temp_loc.lr_raw2;
new_loc->lc_raw3 = temp_loc.lr_raw3;
new_loc->lc_offset = temp_loc.lr_offset;
offset = nextoffset;
if (head_loc == NULL)
head_loc = prev_loc = new_loc;
else {
prev_loc->lc_next = new_loc;
prev_loc = new_loc;
}
}
block_loc =
(Dwarf_Loc *) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK,
op_count);
if (block_loc == NULL) {
_dwarf_free_op_chain(dbg, head_loc);
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return DW_DLV_ERROR;
}
new_loc = head_loc;
for (i = 0; i < op_count; i++) {
/* Copying only the fields needed by DWARF 2,3,4
the struct is public and must never be changed. */
(block_loc + i)->lr_atom = new_loc->lc_atom;
(block_loc + i)->lr_number = new_loc->lc_number;
(block_loc + i)->lr_number2 = new_loc->lc_number2;
(block_loc + i)->lr_offset = new_loc->lc_offset;
prev_loc = new_loc;
new_loc = prev_loc->lc_next;
dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
}
locdesc =
(Dwarf_Locdesc *) _dwarf_get_alloc(dbg, DW_DLA_LOCDESC, 1);
if (locdesc == NULL) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return DW_DLV_ERROR;
}
locdesc->ld_cents = op_count;
locdesc->ld_s = block_loc;
locdesc->ld_section_offset = loc_block->bl_section_offset;
locdesc->ld_lopc = lowpc;
locdesc->ld_hipc = highpc;
locdesc->ld_from_loclist = 1;
*locdesc_out = locdesc;
return DW_DLV_OK;
}
/* Using a loclist offset to get the in-memory
address of .debug_loc data to read, returns the loclist
'header' info in return_block.
*/
#define MAX_ADDR ((address_size == 8)?0xffffffffffffffffULL:0xffffffff)
static int
_dwarf_read_loc_section(Dwarf_Debug dbg,
Dwarf_Block_c * return_block,
Dwarf_Addr * lowpc,
Dwarf_Addr * hipc,
Dwarf_Half * lle_val,
Dwarf_Off sec_offset,
Dwarf_Half address_size,
UNUSEDARG unsigned lkind,
Dwarf_Error * error)
{
Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
Dwarf_Small *loc_section_end =
dbg->de_debug_loc.dss_data + dbg->de_debug_loc.dss_size;
/* start_addr and end_addr are actually offsets
of the applicable base address of the CU.
They are address-size. */
Dwarf_Addr start_addr = 0;
Dwarf_Addr end_addr = 0;
Dwarf_Half exprblock_size = 0;
Dwarf_Unsigned exprblock_off =
2 * address_size + DWARF_HALF_SIZE;
if (sec_offset >= dbg->de_debug_loc.dss_size) {
/* We're at the end. No more present. */
return DW_DLV_NO_ENTRY;
}
/* If it goes past end, error */
if (exprblock_off > dbg->de_debug_loc.dss_size) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
return DW_DLV_ERROR;
}
READ_UNALIGNED_CK(dbg, start_addr, Dwarf_Addr, beg, address_size,
error,loc_section_end);
READ_UNALIGNED_CK(dbg, end_addr, Dwarf_Addr,
beg + address_size, address_size,
error,loc_section_end);
if (start_addr == 0 && end_addr == 0) {
/* If start_addr and end_addr are 0, it's the end and no
exprblock_size field follows. */
exprblock_size = 0;
exprblock_off -= DWARF_HALF_SIZE;
*lle_val = DW_LLE_end_of_list;
} else if (start_addr == MAX_ADDR) {
/* End address is a base address, no exprblock_size field here
either */
exprblock_size = 0;
exprblock_off -= DWARF_HALF_SIZE;
*lle_val = DW_LLE_base_address;
} else {
/* Here we note the address and length of the
expression operators, DW_OP_reg0 etc */
READ_UNALIGNED_CK(dbg, exprblock_size, Dwarf_Half,
beg + 2 * address_size, DWARF_HALF_SIZE,
error,loc_section_end);
/* exprblock_size can be zero, means no expression */
if ( exprblock_size >= dbg->de_debug_loc.dss_size) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
return DW_DLV_ERROR;
}
if ((sec_offset +exprblock_off + exprblock_size) >
dbg->de_debug_loc.dss_size) {
_dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
return DW_DLV_ERROR;
}
*lle_val = DW_LLE_start_end;
}
*lowpc = start_addr;
*hipc = end_addr;
return_block->bl_len = exprblock_size;
return_block->bl_kind = DW_LKIND_loclist;
return_block->bl_data = beg + exprblock_off;
return_block->bl_section_offset =
((Dwarf_Small *) return_block->bl_data) -
dbg->de_debug_loc.dss_data;
return DW_DLV_OK;
}
static int
_dwarf_get_loclist_lle_count_dwo(Dwarf_Debug dbg,
Dwarf_Off loclist_offset,
Dwarf_Half address_size,
unsigned lkind,
int *loclist_count,
Dwarf_Error * error)
{
int count = 0;
Dwarf_Off offset = loclist_offset;
for (;;) {
Dwarf_Block_c b;
Dwarf_Bool at_end = FALSE;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = 0;
Dwarf_Half lle_op = 0;
int res = _dwarf_read_loc_section_dwo(dbg, &b,
&lowpc,
&highpc,
&at_end,
&lle_op,
offset,
address_size,
lkind,
error);
if (res != DW_DLV_OK) {
return res;
}
if (at_end) {
count++;
break;
}
offset = b.bl_len + b.bl_section_offset;
count++;
}
*loclist_count = count;
return DW_DLV_OK;
}
static int
_dwarf_get_loclist_lle_count(Dwarf_Debug dbg,
Dwarf_Off loclist_offset,
Dwarf_Half address_size,
unsigned lkind,
int *loclist_count,
Dwarf_Error * error)
{
int count = 0;
Dwarf_Off offset = loclist_offset;
for (;;) {
Dwarf_Block_c b;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = 0;
Dwarf_Half lle_val = DW_LLE_VALUE_BOGUS;
int res = _dwarf_read_loc_section(dbg, &b,
&lowpc, &highpc,
&lle_val,
offset, address_size,lkind,error);
if (res != DW_DLV_OK) {
return res;
}
offset = b.bl_len + b.bl_section_offset;
if (lowpc == 0 && highpc == 0) {
break;
}
count++;
}
*loclist_count = count;
return DW_DLV_OK;
}
/* Helper routine to avoid code duplication.
*/
static int
_dwarf_setup_loc(Dwarf_Attribute attr,
Dwarf_Debug * dbg_ret,
Dwarf_CU_Context *cucontext_ret,
Dwarf_Half *form_ret,
Dwarf_Error *error)
{
Dwarf_Debug dbg = 0;
Dwarf_Half form = 0;
int blkres = DW_DLV_ERROR;
/* Creating an error with NULL dbg is not a good thing.
These won't be freed if we later call dealloc
with a non-NULL dbg.
*/
if (!attr) {
_dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
return DW_DLV_ERROR;
}
if (attr->ar_cu_context == NULL) {
_dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
return DW_DLV_ERROR;
}
*cucontext_ret = attr->ar_cu_context;
dbg = attr->ar_cu_context->cc_dbg;
if (dbg == NULL) {
_dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
return DW_DLV_ERROR;
}
*dbg_ret = dbg;
blkres = dwarf_whatform(attr, &form, error);
if (blkres != DW_DLV_OK) {
return blkres;
}
*form_ret = form;
return DW_DLV_OK;
}
/* Helper routine to avoid code duplication.
*/
static int
_dwarf_get_loclist_header_start(Dwarf_Debug dbg,
Dwarf_Attribute attr,
Dwarf_Unsigned * loclist_offset_out,
Dwarf_Error * error)
{
Dwarf_Unsigned loc_sec_size = 0;
Dwarf_Unsigned loclist_offset = 0;
int blkres = dwarf_global_formref(attr, &loclist_offset, error);
if (blkres != DW_DLV_OK) {
return blkres;
}
if (!dbg->de_debug_loc.dss_data) {
int secload = _dwarf_load_section(dbg, &dbg->de_debug_loc,error);
if (secload != DW_DLV_OK) {
return secload;
}
if (!dbg->de_debug_loc.dss_size) {
return (DW_DLV_NO_ENTRY);
}
}
loc_sec_size = dbg->de_debug_loc.dss_size;
if (loclist_offset >= loc_sec_size) {
_dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
return DW_DLV_ERROR;
}
{
int fisres = 0;
Dwarf_Unsigned fissoff = 0;
Dwarf_Unsigned size = 0;
fisres = _dwarf_get_fission_addition_die(attr->ar_die,
DW_SECT_LOCLISTS,
&fissoff, &size,error);
if(fisres != DW_DLV_OK) {
return fisres;
}
if (fissoff >= loc_sec_size) {
_dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
return DW_DLV_ERROR;
}
loclist_offset += fissoff;
if (loclist_offset >= loc_sec_size) {
_dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
return DW_DLV_ERROR;
}
}
*loclist_offset_out = loclist_offset;
return DW_DLV_OK;
}
/* When llbuf (see dwarf_loclist_n) is partially set up
and an error is encountered, tear it down as it
won't be used.
*/
static void
_dwarf_cleanup_llbuf(Dwarf_Debug dbg, Dwarf_Locdesc ** llbuf, int count)
{
int i;
for (i = 0; i < count; ++i) {
dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
}
dwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
}
static int
context_is_cu_not_tu(Dwarf_CU_Context context,
Dwarf_Bool *r)
{
int ut = context->cc_unit_type;
if (ut == DW_UT_type || ut == DW_UT_split_type ) {
*r =FALSE;
return DW_DLV_OK;
}
*r = TRUE;
return DW_DLV_OK;
}
/* Handles simple location entries and loclists.
Returns all the Locdesc's thru llbuf.
Will not work properly for DWARF5 and may not
work for some recent versions of gcc or llvm emitting
DWARF4 with location extensions.
Does not work for .debug_loc.dwo
*/
int
dwarf_loclist_n(Dwarf_Attribute attr,
Dwarf_Locdesc *** llbuf_out,
Dwarf_Signed * listlen_out, Dwarf_Error * error)
{
Dwarf_Debug dbg = 0;
/* Dwarf_Attribute that describes the DW_AT_location in die, if
present. */
Dwarf_Attribute loc_attr = attr;
/* Dwarf_Block that describes a single location expression. */
Dwarf_Block_c loc_block;
/* A pointer to the current Dwarf_Locdesc read. */
Dwarf_Locdesc *locdesc = 0;
Dwarf_Half form = 0;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = 0;
Dwarf_Signed listlen = 0;
Dwarf_Locdesc **llbuf = 0;
Dwarf_CU_Context cucontext = 0;
unsigned address_size = 0;
int cuvstamp = 0;
Dwarf_Bool is_cu = FALSE;
Dwarf_Half attrnum = 0;
int is_dwo = FALSE;
unsigned lkind = 0;
int blkres = DW_DLV_ERROR;
int setup_res = DW_DLV_ERROR;
Dwarf_Small * info_section_end = 0;
/* ***** BEGIN CODE ***** */
setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
if (setup_res != DW_DLV_OK) {
return setup_res;
}
info_section_end = _dwarf_calculate_info_section_end_ptr(cucontext);
cuvstamp = cucontext->cc_version_stamp;
address_size = cucontext->cc_address_size;
/* If this is a form_block then it's a location expression. If it's
DW_FORM_data4 or DW_FORM_data8 in DWARF2 or DWARF3
(or in DWARF4 or 5 a DW_FORM_sec_offset) it's a loclist offset */
if (cuvstamp == DW_CU_VERSION5) {
/* Use a newer interface. */
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
return (DW_DLV_ERROR);
}
attrnum = attr->ar_attribute;
lkind = determine_location_lkind(cuvstamp,form, attrnum, is_dwo);
if (lkind == DW_LKIND_unknown ||
lkind == DW_LKIND_GNU_exp_list ||
lkind == DW_LKIND_loclists ) {
/* We cannot handle this here. */
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
return (DW_DLV_ERROR);
}
if (lkind == DW_LKIND_loclist ) {
/* A reference to .debug_loc, with an offset in .debug_loc of a
loclist */
Dwarf_Small *loc_section_end = 0;
Dwarf_Unsigned loclist_offset = 0;
int off_res = DW_DLV_ERROR;
int count_res = DW_DLV_ERROR;
int loclist_count = 0;
int lli = 0;
setup_res = context_is_cu_not_tu(cucontext,&is_cu);
if(setup_res != DW_DLV_OK) {
return setup_res;
}
off_res = _dwarf_get_loclist_header_start(dbg,
attr, &loclist_offset, error);
if (off_res != DW_DLV_OK) {
return off_res;
}
count_res = _dwarf_get_loclist_lle_count(dbg, loclist_offset,
address_size,lkind, &loclist_count, error);
listlen = loclist_count;
if (count_res != DW_DLV_OK) {
return count_res;
}
if (loclist_count == 0) {
return DW_DLV_NO_ENTRY;
}
llbuf = (Dwarf_Locdesc **)
_dwarf_get_alloc(dbg, DW_DLA_LIST, loclist_count);
if (!llbuf) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
for (lli = 0; lli < loclist_count; ++lli) {
int lres = 0;
Dwarf_Half ll_op = 0;
blkres = _dwarf_read_loc_section(dbg,
&loc_block,
&lowpc,
&highpc,
&ll_op,
loclist_offset,
address_size,lkind,
error);
if (blkres != DW_DLV_OK) {
_dwarf_cleanup_llbuf(dbg, llbuf, lli);
return (blkres);
}
loc_section_end = dbg->de_debug_loc.dss_data+
dbg->de_debug_loc.dss_size;
lres = _dwarf_get_locdesc(dbg,
&loc_block,
address_size,
cucontext->cc_length_size,
cucontext->cc_version_stamp,
lowpc, highpc,
loc_section_end,
&locdesc,
error);
if (lres != DW_DLV_OK) {
_dwarf_cleanup_llbuf(dbg, llbuf, lli);
/* low level error already set: let it be passed back */
return lres;
}
llbuf[lli] = locdesc;
/* Now get to next loclist entry offset. */
loclist_offset = loc_block.bl_section_offset +
loc_block.bl_len;
}
} else { /* DW_LKIND_expression */
if( form == DW_FORM_exprloc) {
blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
&loc_block.bl_data,error);
if(blkres != DW_DLV_OK) {
return blkres;
}
loc_block.bl_kind = lkind;
loc_block.bl_section_offset =
(char *)loc_block.bl_data -
(char *)dbg->de_debug_info.dss_data;
} else {
Dwarf_Block *tblock = 0;
blkres = dwarf_formblock(loc_attr, &tblock, error);
if (blkres != DW_DLV_OK) {
return (blkres);
}
loc_block.bl_len = tblock->bl_len;
loc_block.bl_data = tblock->bl_data;
loc_block.bl_kind = lkind;
loc_block.bl_section_offset = tblock->bl_section_offset;
loc_block.bl_locdesc_offset = 0; /* not relevent */
/* We copied tblock contents to the stack var,
so can dealloc
tblock now. Avoids leaks. */
dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
}
listlen = 1; /* One by definition of a location entry. */
lowpc = 0; /* HACK, but with bl_kind we do not need */
highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
/* An empty location description (block length 0) means the
code generator emitted no variable, the variable was not
generated, it was unused or perhaps never tested
after being set.
Dwarf2, section 2.4.1 In other words, it is not an
error, and we don't test for block length 0
specially here. */
blkres = _dwarf_get_locdesc(dbg, &loc_block,
address_size,
cucontext->cc_length_size,
cucontext->cc_version_stamp,
lowpc, highpc,
info_section_end,
&locdesc,
error);
if (blkres != DW_DLV_OK) {
/* low level error already set: let it be passed back */
return blkres;
}
llbuf = (Dwarf_Locdesc **)
_dwarf_get_alloc(dbg, DW_DLA_LIST, listlen);
if (!llbuf) {
/* Free the locdesc we allocated but won't use. */
dwarf_dealloc(dbg, locdesc, DW_DLA_LOCDESC);
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
llbuf[0] = locdesc;
}
*llbuf_out = llbuf;
*listlen_out = listlen;
return (DW_DLV_OK);
}
/* Handles only a location expression.
If called on a loclist, just returns one of those.
Cannot not handle a real loclist.
It returns the location expression as a loclist with
a single entry.
See dwarf_loclist_n() which handles any number
of location list entries.
This is the original definition, and it simply
does not work for loclists.
Nor does it work on DWARF4 nor on some
versions of gcc generating DWARF4.
Kept for compatibility.
*/
int
dwarf_loclist(Dwarf_Attribute attr,
Dwarf_Locdesc ** llbuf,
Dwarf_Signed * listlen, Dwarf_Error * error)
{
Dwarf_Debug dbg = 0;
/* Dwarf_Attribute that describes the DW_AT_location in die, if
present. */
Dwarf_Attribute loc_attr = attr;
/* Dwarf_Block that describes a single location expression. */
Dwarf_Block_c loc_block;
/* A pointer to the current Dwarf_Locdesc read. */
Dwarf_Locdesc *locdesc = 0;
int is_dwo = FALSE;
Dwarf_Small *info_section_end = 0;
Dwarf_Half form = 0;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = 0;
Dwarf_CU_Context cucontext = 0;
unsigned address_size = 0;
unsigned lkind = 0;
int blkres = DW_DLV_ERROR;
int setup_res = DW_DLV_ERROR;
int cuvstamp = 0;
unsigned attrnum = 0;
/* ***** BEGIN CODE ***** */
setup_res = _dwarf_setup_loc(attr, &dbg, &cucontext, &form, error);
if (setup_res != DW_DLV_OK) {
return setup_res;
}
info_section_end = _dwarf_calculate_info_section_end_ptr(cucontext);
memset(&loc_block,0,sizeof(loc_block));
cuvstamp = cucontext->cc_version_stamp;
address_size = cucontext->cc_address_size;
attrnum = attr->ar_attribute;
lkind = determine_location_lkind(cuvstamp,form, attrnum, is_dwo);
if (lkind == DW_LKIND_unknown ||
lkind == DW_LKIND_GNU_exp_list ||
lkind == DW_LKIND_loclists ) {
/* We cannot handle this here. */
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
return (DW_DLV_ERROR);
}
/* If this is a form_block then it's a location expression. If it's
DW_FORM_data4 or DW_FORM_data8 it's a loclist offset */
if (lkind == DW_LKIND_loclist) {
/* A reference to .debug_loc, with an offset in .debug_loc of a
loclist. */
Dwarf_Unsigned loclist_offset = 0;
int off_res = DW_DLV_ERROR;
Dwarf_Half ll_op = 0;
off_res = _dwarf_get_loclist_header_start(dbg,
attr, &loclist_offset,
error);
if (off_res != DW_DLV_OK) {
return off_res;
}
/* With dwarf_loclist, just read a single entry */
blkres = _dwarf_read_loc_section(dbg, &loc_block,
&lowpc,
&highpc,
&ll_op,
loclist_offset,
address_size,
lkind,
error);
if (blkres != DW_DLV_OK) {
return (blkres);
}
} else { /* DW_LKIND_expression */
if( form == DW_FORM_exprloc) {
blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
&loc_block.bl_data,error);
if(blkres != DW_DLV_OK) {
return blkres;
}
loc_block.bl_kind = lkind;
loc_block.bl_section_offset =
(char *)loc_block.bl_data -
(char *)dbg->de_debug_info.dss_data;
} else {
Dwarf_Block *tblock = 0;
/* If DWARF5 this will surely fail, get an error. */
blkres = dwarf_formblock(loc_attr, &tblock, error);
if (blkres != DW_DLV_OK) {
return (blkres);
}
loc_block.bl_len = tblock->bl_len;
loc_block.bl_data = tblock->bl_data;
loc_block.bl_kind = tblock->bl_from_loclist;
/* ASSERT: lkind == loc_block.bl_kind */
loc_block.bl_section_offset = tblock->bl_section_offset;
/* We copied tblock contents to the stack
var, so can dealloc tblock now.
Avoids leaks. */
dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
}
/* Because we set bl_kind we don't really
need this hack any more */
lowpc = 0; /* HACK */
highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
}
/* An empty location description (block length 0) means
the code
generator emitted no variable, the variable was not
generated, it was unused or perhaps never tested after
being set. Dwarf2, section 2.4.1 In other words,
it is not an error, and we don't test for block
length 0 specially here. See *dwarf_loclist_n()
which handles the general case, this case handles
only a single location expression. */
blkres = _dwarf_get_locdesc(dbg, &loc_block,
address_size, cucontext->cc_length_size,
cucontext->cc_version_stamp, lowpc, highpc,
info_section_end, &locdesc, error);
if (blkres != DW_DLV_OK) {
/* low level error already set: let it be passed back
*/ return blkres;
}
*llbuf = locdesc;
*listlen = 1;
return (DW_DLV_OK);
}
/* Handles only a location expression.
It returns the location expression as a loclist with
a single entry.
Usable to access dwarf expressions from any source, but
specifically from
DW_CFA_def_cfa_expression
DW_CFA_expression
DW_CFA_val_expression
expression_in must point to a valid dwarf expression
set of bytes of length expression_length. Not
a DW_FORM_block*, just the expression bytes.
If the address_size != de_pointer_size this will not work
right.
See dwarf_loclist_from_expr_b() for a better interface.
*/
int
dwarf_loclist_from_expr(Dwarf_Debug dbg,
Dwarf_Ptr expression_in,
Dwarf_Unsigned expression_length,
Dwarf_Locdesc ** llbuf,
Dwarf_Signed * listlen, Dwarf_Error * error)
{
int res = 0;
Dwarf_Half addr_size = dbg->de_pointer_size;
res = dwarf_loclist_from_expr_a(dbg,expression_in,
expression_length, addr_size,llbuf,listlen,error);
return res;
}
/* New April 27 2009. Adding addr_size argument for the rare
cases where an object has CUs with a different address_size.
As of 2012 we have yet another version, dwarf_loclist_from_expr_b()
with the version_stamp and offset size (length size) passed in.
And later, dwarf_loclist_from_expr_c()
*/
int
dwarf_loclist_from_expr_a(Dwarf_Debug dbg,
Dwarf_Ptr expression_in,
Dwarf_Unsigned expression_length,
Dwarf_Half addr_size,
Dwarf_Locdesc ** llbuf,
Dwarf_Signed * listlen,
Dwarf_Error * error)
{
int res;
Dwarf_Debug_InfoTypes info_reading = &dbg->de_info_reading;
Dwarf_CU_Context current_cu_context =
info_reading->de_cu_context;
Dwarf_Small version_stamp = DW_CU_VERSION2;
Dwarf_Half offset_size = dbg->de_length_size;
if (current_cu_context) {
/* This is ugly. It is not necessarily right. Due to
oddity in DW_OP_GNU_implicit_pointer, see its
implementation above.
For correctness, use dwarf_loclist_from_expr_b()
instead of dwarf_loclist_from_expr_a(). */
version_stamp = current_cu_context->cc_version_stamp;
offset_size = current_cu_context->cc_length_size;
if (version_stamp < 2) {
/* This is probably totally silly. */
version_stamp = DW_CU_VERSION2;
}
}
res = dwarf_loclist_from_expr_b(dbg,
expression_in,
expression_length,
addr_size,
offset_size,
version_stamp, /* CU context DWARF version */
llbuf,
listlen,
error);
return res;
}
/* New November 13 2012. Adding
DWARF version number argument.
*/
int
dwarf_loclist_from_expr_b(Dwarf_Debug dbg,
Dwarf_Ptr expression_in,
Dwarf_Unsigned expression_length,
Dwarf_Half addr_size,
Dwarf_Half offset_size,
Dwarf_Small dwarf_version,
Dwarf_Locdesc ** llbuf,
Dwarf_Signed * listlen,
Dwarf_Error * error)
{
/* Dwarf_Block that describes a single location expression. */
Dwarf_Block_c loc_block;
/* A pointer to the current Dwarf_Locdesc read. */
Dwarf_Locdesc *locdesc = 0;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = (Dwarf_Unsigned) (-1LL);
Dwarf_Small version_stamp = dwarf_version;
int res = 0;
/* We do not know what the end is in this interface. */
Dwarf_Small *section_start = 0;
Dwarf_Unsigned section_size = 0;
Dwarf_Small *section_end = 0;
const char *section_name = 0;
res = _dwarf_what_section_are_we(dbg,
expression_in,§ion_name,§ion_start,
§ion_size,§ion_end,error);
if (res != DW_DLV_OK) {
_dwarf_error(dbg, error,DW_DLE_POINTER_SECTION_UNKNOWN);
return DW_DLV_ERROR;
}
memset(&loc_block,0,sizeof(loc_block));
loc_block.bl_len = expression_length;
loc_block.bl_data = expression_in;
loc_block.bl_kind = DW_LKIND_expression;
loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
/* An empty location description (block length 0) means the code
generator emitted no variable, the variable was not generated,
it was unused or perhaps never tested after being set. Dwarf2,
section 2.4.1 In other words, it is not an error, and we don't
test for block length 0 specially here. */
/* We need the DWARF version to get a locdesc! */
res = _dwarf_get_locdesc(dbg, &loc_block,
addr_size,
offset_size,
version_stamp,
lowpc, highpc,
section_end,
&locdesc,
error);
if (res != DW_DLV_OK) {
/* low level error already set: let it be passed back */
return res;
}
*llbuf = locdesc;
*listlen = 1;
return DW_DLV_OK;
}
/* Usable to read a single loclist or to read a block of them
or to read an entire section's loclists.
It's BROKEN because it's not safe to read a loclist entry
when we do not know the address size (in any object where
address size can vary by compilation unit).
It also does not recognize split dwarf or DWARF4
or DWARF5 adequately.
Use get_locdesc_entry_c() instead.
*/
/*ARGSUSED*/ int
dwarf_get_loclist_entry(Dwarf_Debug dbg,
Dwarf_Unsigned offset,
Dwarf_Addr * hipc_offset,
Dwarf_Addr * lopc_offset,
Dwarf_Ptr * data,
Dwarf_Unsigned * entry_len,
Dwarf_Unsigned * next_entry,
Dwarf_Error * error)
{
Dwarf_Block_c b;
Dwarf_Addr lowpc = 0;
Dwarf_Addr highpc = 0;
Dwarf_Half address_size = 0;
int res = DW_DLV_ERROR;
Dwarf_Half ll_op = 0;
if (!dbg->de_debug_loc.dss_data) {
int secload = _dwarf_load_section(dbg,
&dbg->de_debug_loc,error);
if (secload != DW_DLV_OK) {
return secload;
}
}
/* FIXME: DO NOT USE the call. address_size is not necessarily
the same in every frame. */
address_size = dbg->de_pointer_size;
res = _dwarf_read_loc_section(dbg,
&b, &lowpc, &highpc,
&ll_op,offset,
address_size,DW_LKIND_loclist,error);
if (res != DW_DLV_OK) {
return res;
}
*hipc_offset = highpc;
*lopc_offset = lowpc;
*entry_len = b.bl_len;
*data = b.bl_data;
*next_entry = b.bl_len + b.bl_section_offset;
return DW_DLV_OK;
}
/* ============== the October 2015 interfaces. */
int
_dwarf_loc_block_sanity_check(Dwarf_Debug dbg,
Dwarf_Block_c *loc_block,Dwarf_Error* error)
{
unsigned lkind = loc_block->bl_kind;
if (lkind == DW_LKIND_loclist) {
Dwarf_Small *loc_ptr = 0;
Dwarf_Unsigned loc_len = 0;
Dwarf_Small *end_ptr = 0;
loc_ptr = loc_block->bl_data;
loc_len = loc_block->bl_len;
end_ptr = dbg->de_debug_loc.dss_size +
dbg->de_debug_loc.dss_data;
if ((loc_ptr +loc_len) > end_ptr) {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_DEBUG_LOC_SECTION_SHORT kind: ");
_dwarf_lkind_name(lkind, &m);
_dwarf_error_string(dbg,error,
DW_DLE_DEBUG_LOC_SECTION_SHORT,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
return DW_DLV_OK;
}
if (lkind == DW_LKIND_loclists) {
Dwarf_Small *loc_ptr = 0;
Dwarf_Unsigned loc_len = 0;
Dwarf_Small *end_ptr = 0;
loc_ptr = loc_block->bl_data;
loc_len = loc_block->bl_len;
end_ptr = dbg->de_debug_loclists.dss_size +
dbg->de_debug_loclists.dss_data;
if ((loc_ptr +loc_len) > end_ptr) {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_DEBUG_LOC_SECTION_SHORT "
"(the .debug_loclists section is short), kind: ");
_dwarf_lkind_name(lkind, &m);
_dwarf_error_string(dbg,error,
DW_DLE_DEBUG_LOC_SECTION_SHORT,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
return DW_DLV_OK;
}
/* ld_kind was checked before calling this, so we
know its value is an intended value. */
static const char *kindset[] = {
"DW_LKIND_expression",
"DW_LKIND_loclist",
"DW_LKIND_GNU_exp_list",
"DW_LKIND_unknown3",
"DW_LKIND_unknown4",
"DW_LKIND_loclists"
};
static const char *
get_loc_kind_str(Dwarf_Small lkind)
{
if (lkind <= DW_LKIND_loclists) {
return kindset[lkind];
}
if (lkind == DW_LKIND_unknown) {
return "DW_LKIND_unknown";
}
return "UNKNOWN DW_LKIND!";
}
static int
validate_lle_value(Dwarf_Debug dbg,
Dwarf_Locdesc_c locdesc,
Dwarf_Error *error)
{
dwarfstring m;
if (locdesc->ld_kind != DW_LKIND_GNU_exp_list) {
switch(locdesc->ld_lle_value) {
case DW_LLE_end_of_list:
case DW_LLE_base_addressx:
case DW_LLE_startx_endx:
case DW_LLE_startx_length:
case DW_LLE_offset_pair:
case DW_LLE_default_location:
case DW_LLE_base_address:
case DW_LLE_start_end:
case DW_LLE_start_length:
return DW_DLV_OK;
}
dwarfstring_constructor(&m);
dwarfstring_append_printf_s(&m,
"DW_DLE_LOCATION_ERROR: For location kind %s (",
(char *)get_loc_kind_str(locdesc->ld_kind));
dwarfstring_append_printf_u(&m,"%u) the DW_LLE value is "
"not properly set",
locdesc->ld_kind);
dwarfstring_append_printf_u(&m," but is %u "
" which is a libdwarf bug",
locdesc->ld_lle_value);
_dwarf_error_string(dbg,error,DW_DLE_LOCATION_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
switch(locdesc->ld_lle_value) {
case DW_LLEX_end_of_list_entry:
case DW_LLEX_base_address_selection_entry:
case DW_LLEX_start_end_entry:
case DW_LLEX_start_length_entry:
case DW_LLEX_offset_pair_entry:
return DW_DLV_OK;
}
{
dwarfstring_constructor(&m);
dwarfstring_append_printf_s(&m,
"DW_DLE_LOCATION_ERROR: For location kind %s (",
(char *)get_loc_kind_str(locdesc->ld_kind));
dwarfstring_append_printf_u(&m,"%u) the DW_LLEX value is "
"not properly set",
locdesc->ld_kind);
dwarfstring_append_printf_u(&m," but is %u "
" which is a libdwarf bug",
locdesc->ld_lle_value);
_dwarf_error_string(dbg,error,DW_DLE_LOCATION_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
}
return DW_DLV_ERROR;
}
/* Sets locdesc operator list information in locdesc.
Sets the locdesc values (rawlow, rawhigh etc).
This synthesizes the ld_lle_value of the locdesc
if it's not already provided.
Not passing in locdesc pointer, the locdesc_index suffices
to index to the relevant locdesc pointer.
See also dwarf_loclists.c: build_array_of_lle*/
int
_dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
Dwarf_Unsigned locdesc_index,
Dwarf_Loc_Head_c loc_head,
Dwarf_Block_c * loc_block,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small version_stamp,
Dwarf_Addr lowpc,
Dwarf_Addr highpc,
Dwarf_Half lle_op,
Dwarf_Error * error)
{
/* Offset of current operator from start of block. */
Dwarf_Unsigned offset = 0;
/* Chain the DW_OPerator structs. */
Dwarf_Loc_Chain new_loc = NULL;
Dwarf_Loc_Chain prev_loc = NULL;
Dwarf_Loc_Chain head_loc = NULL;
Dwarf_Unsigned op_count = 0;
/* Contiguous block of Dwarf_Loc_Expr_Op_s
for Dwarf_Locdesc. */
Dwarf_Loc_Expr_Op block_loc = 0;
Dwarf_Locdesc_c locdesc = loc_head->ll_locdesc + locdesc_index;
Dwarf_Unsigned i = 0;
int res = 0;
Dwarf_Small *section_start = 0;
Dwarf_Unsigned section_size = 0;
Dwarf_Small *section_end = 0;
const char *section_name = 0;
Dwarf_Small *blockdataptr = 0;
unsigned lkind = loc_head->ll_kind;
/* ***** BEGIN CODE ***** */
blockdataptr = loc_block->bl_data;
if (!blockdataptr || !loc_block->bl_len) {
/* an empty block has no operations so
no section or tests need be done.. */
} else {
res = _dwarf_what_section_are_we(dbg,
blockdataptr,§ion_name,§ion_start,
§ion_size,§ion_end,error);
if (res != DW_DLV_OK) {
_dwarf_error(dbg, error,DW_DLE_POINTER_SECTION_UNKNOWN);
return DW_DLV_ERROR;
}
res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
if (res != DW_DLV_OK) {
return res;
}
}
/* New loop getting Loc operators. Non DWO */
while (offset <= loc_block->bl_len) {
Dwarf_Unsigned nextoffset = 0;
struct Dwarf_Loc_Expr_Op_s temp_loc;
/* This call is ok even if bl_data NULL and bl_len 0 */
res = _dwarf_read_loc_expr_op(dbg,loc_block,
op_count,
version_stamp,
offset_size,
address_size,
offset,
section_end,
&nextoffset,
&temp_loc,
error);
if (res == DW_DLV_ERROR) {
return res;
}
if (res == DW_DLV_NO_ENTRY) {
/* Normal end.
Also the end for an empty loc_block. */
break;
}
op_count++;
new_loc =
(Dwarf_Loc_Chain) _dwarf_get_alloc(dbg, DW_DLA_LOC_CHAIN, 1);
if (new_loc == NULL) {
_dwarf_free_op_chain(dbg,head_loc);
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return DW_DLV_ERROR;
}
/* Copying all the fields. DWARF 2,3,4,5. */
new_loc->lc_atom = temp_loc.lr_atom;
new_loc->lc_opnumber= temp_loc.lr_opnumber;
new_loc->lc_raw1 = temp_loc.lr_number;
new_loc->lc_raw2 = temp_loc.lr_number2;
new_loc->lc_raw3 = temp_loc.lr_number3;
new_loc->lc_number = temp_loc.lr_number;
new_loc->lc_number2 = temp_loc.lr_number2;
new_loc->lc_number3 = temp_loc.lr_number3;
new_loc->lc_offset = temp_loc.lr_offset;
if (head_loc == NULL)
head_loc = prev_loc = new_loc;
else {
prev_loc->lc_next = new_loc;
prev_loc = new_loc;
}
offset = nextoffset;
}
block_loc =
(Dwarf_Loc_Expr_Op ) _dwarf_get_alloc(dbg,
DW_DLA_LOC_BLOCK_C, op_count);
new_loc = head_loc;
if (!block_loc) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
for (i = 0; i < op_count; i++) {
prev_loc = new_loc;
new_loc = prev_loc->lc_next;
dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
}
return DW_DLV_ERROR;
}
/* op_count could be zero. */
new_loc = head_loc;
for (i = 0; i < op_count; i++) {
/* Copying only the fields needed by DWARF 2,3,4 */
(block_loc + i)->lr_atom = new_loc->lc_atom;
(block_loc + i)->lr_raw1 = new_loc->lc_raw1;
(block_loc + i)->lr_raw2 = new_loc->lc_raw2;
(block_loc + i)->lr_raw3 = new_loc->lc_raw3;
(block_loc + i)->lr_number = new_loc->lc_number;
(block_loc + i)->lr_number2 = new_loc->lc_number2;
(block_loc + i)->lr_number3 = new_loc->lc_number3;
(block_loc + i)->lr_offset = new_loc->lc_offset;
(block_loc + i)->lr_opnumber = new_loc->lc_opnumber;
prev_loc = new_loc;
new_loc = prev_loc->lc_next;
dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
}
/* Synthesizing the DW_LLE values for the old loclist
versions. */
switch(loc_head->ll_kind) {
case DW_LKIND_loclist: {
if(highpc == 0 && lowpc == 0) {
locdesc->ld_lle_value = DW_LLE_end_of_list;
} else if(lowpc == MAX_ADDR) {
locdesc->ld_lle_value = DW_LLE_base_address;
} else {
locdesc->ld_lle_value = DW_LLE_offset_pair;
}
}
break;
case DW_LKIND_GNU_exp_list:
/* DW_LKIND_GNU_exp_list */
locdesc->ld_lle_value = lle_op;
break;
case DW_LKIND_expression:
/* This is a kind of fake, but better than 0 */
locdesc->ld_lle_value = DW_LLE_start_end;
break;
case DW_LKIND_loclists:
/* ld_lle_value already set */
break;
default: {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOCATION_ERROR: An impossible DW_LKIND"
" value of %u encountered, likely internal "
"libdwarf error or data corruption",
(unsigned)loc_head->ll_kind);
_dwarf_error_string(dbg,error,
DW_DLE_LOCATION_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
dwarf_dealloc(dbg,block_loc,DW_DLA_LOC_BLOCK_C);
return DW_DLV_ERROR;
}
}
locdesc->ld_cents = op_count;
locdesc->ld_s = block_loc;
locdesc->ld_kind = lkind;
locdesc->ld_section_offset = loc_block->bl_section_offset;
locdesc->ld_locdesc_offset = loc_block->bl_locdesc_offset;
locdesc->ld_rawlow = lowpc;
locdesc->ld_rawhigh = highpc;
res = validate_lle_value(dbg,locdesc,error);
if (res != DW_DLV_OK) {
dwarf_dealloc(dbg,block_loc,DW_DLA_LOC_BLOCK_C);
return res;
}
/* Leaving the cooked values zero. Filled in later. */
/* We have not yet looked for debug_addr, so we'll
set it as not-missing. */
locdesc->ld_index_failed = FALSE;
return DW_DLV_OK;
}
/* Non-standard DWARF4 dwo loclist */
static int
_dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
Dwarf_Block_c * return_block,
Dwarf_Addr * lowpc,
Dwarf_Addr * highpc,
Dwarf_Bool *at_end,
Dwarf_Half * lle_op,
Dwarf_Off sec_offset,
Dwarf_Half address_size,
Dwarf_Half lkind,
Dwarf_Error * error)
{
Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
Dwarf_Small *locptr = 0;
Dwarf_Small llecode = 0;
Dwarf_Unsigned expr_offset = sec_offset;
Dwarf_Byte_Ptr section_end = dbg->de_debug_loc.dss_data
+ dbg->de_debug_loc.dss_size;
if (sec_offset >= dbg->de_debug_loc.dss_size) {
/* We're at the end. No more present. */
return DW_DLV_NO_ENTRY;
}
memset(return_block,0,sizeof(*return_block));
/* not the same as non-split loclist, but still a list. */
return_block->bl_kind = lkind;
/* This is non-standard GNU Dwarf4 loclist */
return_block->bl_locdesc_offset = sec_offset;
llecode = *beg;
locptr = beg +1;
expr_offset++;
switch(llecode) {
case DW_LLEX_end_of_list_entry:
*at_end = TRUE;
return_block->bl_section_offset = expr_offset;
expr_offset++;
break;
case DW_LLEX_base_address_selection_entry: {
Dwarf_Unsigned addr_index = 0;
DECODE_LEB128_UWORD_CK(locptr,addr_index,
dbg,error,section_end);
return_block->bl_section_offset = expr_offset;
/* So this behaves much like non-dwo loclist */
*lowpc=MAX_ADDR;
*highpc=addr_index;
}
break;
case DW_LLEX_start_end_entry: {
Dwarf_Unsigned addr_indexs = 0;
Dwarf_Unsigned addr_indexe= 0;
Dwarf_Unsigned exprlen = 0;
Dwarf_Unsigned leb128_length = 0;
DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexs,
leb128_length,
dbg,error,section_end);
expr_offset += leb128_length;
DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexe,
leb128_length,
dbg,error,section_end);
expr_offset +=leb128_length;
*lowpc=addr_indexs;
*highpc=addr_indexe;
READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
DWARF_HALF_SIZE,
error,section_end);
locptr += DWARF_HALF_SIZE;
expr_offset += DWARF_HALF_SIZE;
return_block->bl_len = exprlen;
return_block->bl_data = locptr;
return_block->bl_section_offset = expr_offset;
expr_offset += exprlen;
if (expr_offset > dbg->de_debug_loc.dss_size) {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_DEBUG_LOC_SECTION_SHORT:");
dwarfstring_append_printf_u(&m,
" in DW_LLEX_start_end_entry "
"The expression offset is 0x%x",
expr_offset);
dwarfstring_append_printf_u(&m,
" which is greater than the section size"
" of 0x%x. Corrupt Dwarf.",
dbg->de_debug_loc.dss_size);
_dwarf_error_string(dbg,error,
DW_DLE_DEBUG_LOC_SECTION_SHORT,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
break;
case DW_LLEX_start_length_entry: {
Dwarf_Unsigned addr_index = 0;
Dwarf_Unsigned range_length = 0;
Dwarf_Unsigned exprlen = 0;
Dwarf_Unsigned leb128_length = 0;
DECODE_LEB128_UWORD_LEN_CK(locptr,addr_index,
leb128_length,
dbg,error,section_end);
expr_offset +=leb128_length;
READ_UNALIGNED_CK(dbg, range_length, Dwarf_Unsigned, locptr,
DWARF_32BIT_SIZE,
error,section_end);
locptr += DWARF_32BIT_SIZE;
expr_offset += DWARF_32BIT_SIZE;
READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
DWARF_HALF_SIZE,
error,section_end);
locptr += DWARF_HALF_SIZE;
expr_offset += DWARF_HALF_SIZE;
*lowpc = addr_index;
*highpc = range_length;
return_block->bl_len = exprlen;
return_block->bl_data = locptr;
return_block->bl_section_offset = expr_offset;
/* exprblock_size can be zero, means no expression */
expr_offset += exprlen;
if (expr_offset > dbg->de_debug_loc.dss_size) {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_DEBUG_LOC_SECTION_SHORT:");
dwarfstring_append_printf_u(&m,
" in DW_LLEX_start_length_entry "
"The expression offset is 0x%x",
expr_offset);
dwarfstring_append_printf_u(&m,
" which is greater than the section size"
" of 0x%x. Corrupt Dwarf.",
dbg->de_debug_loc.dss_size);
_dwarf_error_string(dbg,error,
DW_DLE_DEBUG_LOC_SECTION_SHORT,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
break;
case DW_LLEX_offset_pair_entry: {
Dwarf_Unsigned startoffset = 0;
Dwarf_Unsigned endoffset = 0;
Dwarf_Unsigned exprlen = 0;
READ_UNALIGNED_CK(dbg, startoffset,
Dwarf_Unsigned, locptr,
DWARF_32BIT_SIZE,
error,section_end);
locptr += DWARF_32BIT_SIZE;
expr_offset += DWARF_32BIT_SIZE;
READ_UNALIGNED_CK(dbg, endoffset,
Dwarf_Unsigned, locptr,
DWARF_32BIT_SIZE,
error,section_end);
locptr += DWARF_32BIT_SIZE;
expr_offset += DWARF_32BIT_SIZE;
*lowpc= startoffset;
*highpc = endoffset;
READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
DWARF_HALF_SIZE,
error,section_end);
locptr += DWARF_HALF_SIZE;
expr_offset += DWARF_HALF_SIZE;
return_block->bl_len = exprlen;
return_block->bl_data = locptr;
return_block->bl_section_offset = expr_offset;
expr_offset += exprlen;
if (expr_offset > dbg->de_debug_loc.dss_size) {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_DEBUG_LOC_SECTION_SHORT:");
dwarfstring_append_printf_u(&m,
" in DW_LLEX_offset_pair_entry "
"The expression offset is 0x%x",
expr_offset);
dwarfstring_append_printf_u(&m,
" which is greater than the section size"
" of 0x%x. Corrupt Dwarf.",
dbg->de_debug_loc.dss_size);
_dwarf_error_string(dbg,error,
DW_DLE_DEBUG_LOC_SECTION_SHORT,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
break;
default: {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append(&m,
"DW_DLE_LLE_CODE_UNKNOWN:");
dwarfstring_append_printf_u(&m,
" in DW_LLEX_ code value "
" is 0x%x ,not an expected value.",
llecode);
_dwarf_error_string(dbg,error,
DW_DLE_LLE_CODE_UNKNOWN,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
_dwarf_error(dbg,error,DW_DLE_LLE_CODE_UNKNOWN);
return DW_DLV_ERROR;
}
}
*lle_op = llecode;
return DW_DLV_OK;
}
int
dwarf_get_loclist_head_kind(Dwarf_Loc_Head_c ll_header,
unsigned int * kind,
UNUSEDARG Dwarf_Error * error)
{
*kind = ll_header->ll_kind;
return DW_DLV_OK;
}
static int
_dwarf_original_loclist_build(Dwarf_Debug dbg,
Dwarf_Loc_Head_c llhead,
Dwarf_Attribute attr,
Dwarf_Error *error)
{
Dwarf_Unsigned loclist_offset = 0;
Dwarf_Unsigned starting_loclist_offset = 0;
int off_res = DW_DLV_ERROR;
int count_res = DW_DLV_ERROR;
int loclist_count = 0;
Dwarf_Unsigned lli = 0;
unsigned lkind = llhead->ll_kind;
unsigned address_size = llhead->ll_address_size;
Dwarf_Unsigned listlen = 0;
Dwarf_Locdesc_c llbuf = 0;
Dwarf_CU_Context cucontext;
off_res = _dwarf_get_loclist_header_start(dbg,
attr, &loclist_offset, error);
if (off_res != DW_DLV_OK) {
return off_res;
}
starting_loclist_offset = loclist_offset;
if (lkind == DW_LKIND_GNU_exp_list) {
count_res = _dwarf_get_loclist_lle_count_dwo(dbg,
loclist_offset,
address_size,
llhead->ll_kind,
&loclist_count,
error);
} else {
count_res = _dwarf_get_loclist_lle_count(dbg,
loclist_offset, address_size,
llhead->ll_kind,
&loclist_count,
error);
}
if (count_res != DW_DLV_OK) {
return count_res;
}
if (loclist_count == 0) {
return DW_DLV_NO_ENTRY;
}
listlen = loclist_count;
llbuf = (Dwarf_Locdesc_c)
_dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
if (!llbuf) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
llhead->ll_locdesc = llbuf;
llhead->ll_locdesc_count = listlen;
cucontext = llhead->ll_context;
llhead->ll_llearea_offset = loclist_offset;
/* Now get loc ops */
for (lli = 0; lli < listlen; ++lli) {
int lres = 0;
Dwarf_Half lle_op = 0;
Dwarf_Bool at_end = 0;
Dwarf_Block_c loc_block;
Dwarf_Unsigned rawlowpc = 0;
Dwarf_Unsigned rawhighpc = 0;
int blkres = 0;
memset(&loc_block,0,sizeof(loc_block));
if( lkind == DW_LKIND_GNU_exp_list) {
blkres = _dwarf_read_loc_section_dwo(dbg,
&loc_block,
&rawlowpc, &rawhighpc,
&at_end, &lle_op,
loclist_offset,
address_size,
lkind,
error);
} else {
blkres = _dwarf_read_loc_section(dbg,
&loc_block,
&rawlowpc, &rawhighpc,
&lle_op,
loclist_offset,
address_size,
lkind,
error);
}
if (blkres != DW_DLV_OK) {
return blkres;
}
/* Fills in the locdesc and its operators list at index lli */
lres = _dwarf_fill_in_locdesc_op_c(dbg,
lli,
llhead,
&loc_block,
address_size,
cucontext->cc_length_size,
cucontext->cc_version_stamp,
rawlowpc,
rawhighpc,
lle_op,
error);
if (lres != DW_DLV_OK) {
return lres;
}
/* Now get to next loclist entry offset. */
loclist_offset = loc_block.bl_section_offset +
loc_block.bl_len;
}
/* We need to calculate the cooked values for
each locldesc entry, that will be done
in dwarf_get_loclist_c(). */
llhead->ll_bytes_total = loclist_offset -
starting_loclist_offset;
return DW_DLV_OK;
}
static int
_dwarf_original_expression_build(Dwarf_Debug dbg,
Dwarf_Loc_Head_c llhead,
Dwarf_Attribute attr,
Dwarf_Error *error)
{
Dwarf_Block_c loc_blockc;
Dwarf_Unsigned rawlowpc = 0;
Dwarf_Unsigned rawhighpc = 0;
unsigned form = llhead->ll_attrform;
int blkres = 0;
Dwarf_Locdesc_c llbuf = 0;
unsigned listlen = 1;
Dwarf_CU_Context cucontext = llhead->ll_context;
unsigned address_size = llhead->ll_address_size;
memset(&loc_blockc,0,sizeof(loc_blockc));
if( form == DW_FORM_exprloc) {
blkres = dwarf_formexprloc(attr,&loc_blockc.bl_len,
&loc_blockc.bl_data,error);
if(blkres != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return blkres;
}
loc_blockc.bl_kind = llhead->ll_kind;
loc_blockc.bl_section_offset =
(char *)loc_blockc.bl_data -
(char *)dbg->de_debug_info.dss_data;
loc_blockc.bl_locdesc_offset = 0; /* not relevant */
} else {
Dwarf_Block loc_block;
memset(&loc_block,0,sizeof(loc_block));
blkres = _dwarf_formblock_internal(dbg,attr,
llhead->ll_context,
&loc_block,
error);
if (blkres != DW_DLV_OK) {
return blkres;
}
loc_blockc.bl_len = loc_block.bl_len;
loc_blockc.bl_data = loc_block.bl_data;
loc_blockc.bl_kind = llhead->ll_kind;
loc_blockc.bl_section_offset =
loc_block.bl_section_offset;
loc_blockc.bl_locdesc_offset = 0; /* not relevant */
}
/* We will mark the Locdesc_c DW_LLE_start_end
shortly. Here we fake the address range
as 'all addresses'. */
rawlowpc = 0;
rawhighpc = MAX_ADDR;
llbuf = (Dwarf_Locdesc_c)
_dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
if (!llbuf) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
llhead->ll_locdesc = llbuf;
/* One by definition of a location entry. */
llhead->ll_locdesc_count = listlen;
/* An empty location description (block length 0)
means the code generator emitted no variable,
the variable was not generated, it was unused
or perhaps never tested after being set. Dwarf2,
section 2.4.1 In other words, it is not an error,
and we don't test for block length 0 specially here. */
/* Fills in the locdesc and its operators list
at index 0 */
blkres = _dwarf_fill_in_locdesc_op_c(dbg,
0, /* fake locdesc is index 0 */
llhead,
&loc_blockc,
llhead->ll_address_size,
cucontext->cc_length_size,
cucontext->cc_version_stamp,
rawlowpc, rawhighpc,
0,
error);
llhead->ll_bytes_total += loc_blockc.bl_len;
if (blkres != DW_DLV_OK) {
/* low level error already set: let it be passed back */
return blkres;
}
return DW_DLV_OK;
}
/* Following the original loclist definition the low
value is all one bits, the high value is the base
address. */
static int
cook_original_loclist_contents(Dwarf_Debug dbg,
Dwarf_Loc_Head_c llhead,
Dwarf_Error *error)
{
Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
Dwarf_Unsigned count = llhead->ll_locdesc_count;
Dwarf_Unsigned i = 0;
for ( i = 0 ; i < count; ++i) {
Dwarf_Locdesc_c llc = 0;
llc = llhead->ll_locdesc +i;
switch(llc->ld_lle_value) {
case DW_LLE_end_of_list: {
/* nothing to do */
break;
}
case DW_LLE_base_address: {
llc->ld_lopc = llc->ld_rawhigh;
llc->ld_highpc = llc->ld_rawhigh;
baseaddress = llc->ld_rawhigh;
break;
}
case DW_LLE_offset_pair: {
llc->ld_lopc = llc->ld_rawlow + baseaddress;
llc->ld_highpc = llc->ld_rawhigh + baseaddress;
break;
}
default: {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOCLISTS_ERROR: improper synthesized LLE code "
"of 0x%x is unknown. In standard DWARF3/4 loclist",
llc->ld_lle_value);
_dwarf_error_string(dbg,error,
DW_DLE_LOCLISTS_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
}
return DW_DLV_OK;
}
static int
cook_gnu_loclist_contents(Dwarf_Debug dbg,
Dwarf_Loc_Head_c llhead,
Dwarf_Error *error)
{
Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
Dwarf_Unsigned count = llhead->ll_locdesc_count;
Dwarf_Unsigned i = 0;
Dwarf_CU_Context cucontext = llhead->ll_context;
int res = 0;
for (i = 0 ; i < count ; ++i) {
Dwarf_Locdesc_c llc = 0;
llc = llhead->ll_locdesc +i;
switch(llc->ld_lle_value) {
case DW_LLEX_base_address_selection_entry:{
Dwarf_Addr targaddr = 0;
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawhigh,&targaddr,
error);
if (res != DW_DLV_OK) {
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
llc->ld_highpc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_lopc = targaddr;
llc->ld_highpc = targaddr;
}
break;
}
case DW_LLEX_end_of_list_entry:{
/* Nothing to do. */
break;
}
case DW_LLEX_start_length_entry:{
Dwarf_Addr targaddr = 0;
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
if (res != DW_DLV_OK) {
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_lopc = targaddr;
llc->ld_highpc = llc->ld_lopc +llc->ld_rawhigh;
}
break;
}
case DW_LLEX_offset_pair_entry:{
llc->ld_lopc = llc->ld_rawlow + baseaddress;
llc->ld_highpc = llc->ld_rawhigh + baseaddress;
break;
}
case DW_LLEX_start_end_entry:{
Dwarf_Addr targaddr = 0;
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
if (res != DW_DLV_OK) {
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_lopc = targaddr;
}
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
if (res != DW_DLV_OK) {
llc->ld_index_failed = TRUE;
llc->ld_highpc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_highpc = targaddr;
}
break;
}
default:{
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOCLISTS_ERROR: improper LLEX code "
"of 0x%x is unknown. GNU LLEX dwo loclists error",
llc->ld_lle_value);
_dwarf_error_string(dbg,error,
DW_DLE_LOCLISTS_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
break;
}
}
}
return DW_DLV_OK;
}
/* DWARF5 */
static int
cook_loclists_contents(Dwarf_Debug dbg,
Dwarf_Loc_Head_c llhead,
Dwarf_Error *error)
{
Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
Dwarf_Unsigned count = llhead->ll_locdesc_count;
Dwarf_Unsigned i = 0;
Dwarf_CU_Context cucontext = llhead->ll_context;
int res = 0;
Dwarf_Bool base_address_fail = FALSE;
Dwarf_Bool debug_addr_fail = FALSE;
if (!llhead->ll_cu_base_address_present) {
base_address_fail = TRUE;
}
for (i = 0 ; i < count ; ++i) {
Dwarf_Locdesc_c llc = 0;
llc = llhead->ll_locdesc +i;
switch(llc->ld_lle_value) {
case DW_LLE_base_addressx: {
Dwarf_Addr targaddr = 0;
if (debug_addr_fail) {
res = DW_DLV_NO_ENTRY;
} else {
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
}
if (res != DW_DLV_OK) {
debug_addr_fail = TRUE;
base_address_fail = TRUE;
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
base_address_fail = FALSE;
baseaddress = targaddr;
llc->ld_lopc = targaddr;
}
break;
}
case DW_LLE_startx_endx:{
/* two indexes into debug_addr */
Dwarf_Addr targaddr = 0;
if (debug_addr_fail) {
res = DW_DLV_NO_ENTRY;
} else {
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
}
if (res != DW_DLV_OK) {
debug_addr_fail = TRUE;
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_lopc = targaddr;
}
if (debug_addr_fail) {
res = DW_DLV_NO_ENTRY;
} else {
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawhigh,&targaddr,
error);
}
if (res != DW_DLV_OK) {
debug_addr_fail = TRUE;
llc->ld_index_failed = TRUE;
llc->ld_highpc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_highpc = targaddr;
}
break;
}
case DW_LLE_startx_length:{
/* one index to debug_addr other a length */
Dwarf_Addr targaddr = 0;
if (debug_addr_fail) {
res = DW_DLV_NO_ENTRY;
} else {
res = _dwarf_look_in_local_and_tied_by_index(
dbg,cucontext,llc->ld_rawlow,&targaddr,
error);
}
if (res != DW_DLV_OK) {
debug_addr_fail = TRUE;
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg, *error);
*error = 0;
}
} else {
llc->ld_lopc = targaddr;
llc->ld_highpc = targaddr + llc->ld_rawhigh;
}
break;
}
case DW_LLE_offset_pair:{
if (base_address_fail) {
llc->ld_index_failed = TRUE;
llc->ld_lopc = 0;
llc->ld_highpc = 0;
} else {
/*offsets of the current base address*/
llc->ld_lopc = llc->ld_rawlow +baseaddress;
llc->ld_highpc = llc->ld_rawhigh +baseaddress;
}
break;
}
case DW_LLE_default_location:{
/* nothing to do here, just has a counted
location description */
break;
}
case DW_LLE_base_address:{
llc->ld_lopc = llc->ld_rawlow;
llc->ld_highpc = llc->ld_rawlow;
baseaddress = llc->ld_rawlow;
base_address_fail = FALSE;
break;
}
case DW_LLE_start_end:{
llc->ld_lopc = llc->ld_rawlow;
llc->ld_highpc = llc->ld_rawhigh;
break;
}
case DW_LLE_start_length:{
llc->ld_lopc = llc->ld_rawlow;
llc->ld_highpc = llc->ld_rawlow + llc->ld_rawhigh;
break;
}
case DW_LLE_end_of_list:{
/* do nothing */
break;
}
default: {
dwarfstring m;
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOCLISTS_ERROR: improper DW_LLE code "
"of 0x%x is unknown. DWARF5 loclists error",
llc->ld_lle_value);
_dwarf_error_string(dbg,error,
DW_DLE_LOCLISTS_ERROR,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
}
}
return DW_DLV_OK;
}
/* New October 2015
This interface requires the use of interface functions
to get data from Dwarf_Locdesc_c. The structures
are not visible to callers. */
int
dwarf_get_loclist_c(Dwarf_Attribute attr,
Dwarf_Loc_Head_c * ll_header_out,
Dwarf_Unsigned * listlen_out,
Dwarf_Error * error)
{
Dwarf_Debug dbg;
Dwarf_Half form = 0;
Dwarf_Loc_Head_c llhead = 0;
Dwarf_CU_Context cucontext = 0;
unsigned address_size = 0;
int cuversionstamp = 0;
Dwarf_Bool is_cu = FALSE;
Dwarf_Unsigned attrnum = 0;
Dwarf_Bool is_dwo = 0;
int setup_res = DW_DLV_ERROR;
int lkind = 0;
/* ***** BEGIN CODE ***** */
setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
if (setup_res != DW_DLV_OK) {
return setup_res;
}
attrnum = attr->ar_attribute;
cuversionstamp = cucontext->cc_version_stamp;
address_size = cucontext->cc_address_size;
is_dwo = cucontext->cc_is_dwo;
lkind = determine_location_lkind(cuversionstamp,
form, attrnum, is_dwo);
if (lkind == DW_LKIND_unknown) {
dwarfstring m;
const char * formname = "<unknownform>";
const char * attrname = "<unknown attribute>";
dwarfstring_constructor(&m);
dwarf_get_FORM_name(form,&formname);
dwarf_get_AT_name(attrnum,&attrname);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOC_EXPR_BAD: For Compilation Unit "
"version %u",cuversionstamp);
dwarfstring_append_printf_u(&m,
", attribute 0x%x (",attrnum);
dwarfstring_append(&m,(char *)attrname);
dwarfstring_append_printf_u(&m,
") form 0x%x (",form);
dwarfstring_append(&m,(char *)formname);
if (is_dwo) {
dwarfstring_append(&m,") (the CU is a .dwo) ");
} else {
dwarfstring_append(&m,") (the CU is not a .dwo) ");
}
dwarfstring_append(&m," we don't undrstand the location");
_dwarf_error_string(dbg,error,DW_DLE_LOC_EXPR_BAD,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
/* Doing this early (first) to avoid repeating the alloc code
for each type */
llhead = (Dwarf_Loc_Head_c)
_dwarf_get_alloc(dbg, DW_DLA_LOC_HEAD_C, 1);
if (!llhead) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
llhead->ll_cuversion = cuversionstamp;
llhead->ll_kind = lkind;
llhead->ll_attrnum = attrnum;
llhead->ll_attrform = form;
llhead->ll_dbg = dbg;
llhead->ll_address_size = address_size;
llhead->ll_offset_size = cucontext->cc_length_size;
llhead->ll_context = cucontext;
llhead->ll_at_loclists_base_present =
cucontext->cc_loclists_base_present;
llhead->ll_at_loclists_base = cucontext->cc_loclists_base;
llhead->ll_cu_base_address_present = cucontext->cc_low_pc_present;
llhead->ll_cu_base_address = cucontext->cc_low_pc;
llhead->ll_cu_addr_base = cucontext->cc_addr_base;
llhead->ll_cu_addr_base_present =
cucontext->cc_addr_base_present;
if (lkind == DW_LKIND_loclist ||
lkind == DW_LKIND_GNU_exp_list) {
int ores = 0;
/* Here we have a loclist to deal with. */
ores = context_is_cu_not_tu(cucontext,&is_cu);
if(ores != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return setup_res;
}
ores = _dwarf_original_loclist_build(dbg,
llhead, attr, error);
if (ores != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return ores;
}
if (lkind == DW_LKIND_loclist) {
ores = cook_original_loclist_contents(dbg,llhead,
error);
} else {
ores = cook_gnu_loclist_contents(dbg,llhead,error);
}
if (ores != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return ores;
}
} else if (lkind == DW_LKIND_expression) {
/* DWARF2,3,4,5 */
int eres = 0;
eres = _dwarf_original_expression_build(dbg,
llhead, attr, error);
if (eres != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return eres;
}
} else if (lkind == DW_LKIND_loclists) {
/* DWARF5! */
int leres = 0;
leres = _dwarf_loclists_fill_in_lle_head(dbg,
attr,llhead,error);
if (leres != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return leres;
}
leres = cook_loclists_contents(dbg,llhead,error);
if (leres != DW_DLV_OK) {
dwarf_loc_head_c_dealloc(llhead);
return leres;
}
} /* ASSERT else impossible */
*ll_header_out = llhead;
*listlen_out = llhead->ll_locdesc_count;
return DW_DLV_OK;
}
/* An interface giving us no cu context!
This is not going to be quite right. */
int
dwarf_loclist_from_expr_c(Dwarf_Debug dbg,
Dwarf_Ptr expression_in,
Dwarf_Unsigned expression_length,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small dwarf_version,
Dwarf_Loc_Head_c *loc_head,
Dwarf_Unsigned * listlen,
Dwarf_Error * error)
{
/* Dwarf_Block that describes a single location expression. */
Dwarf_Block_c loc_block;
Dwarf_Loc_Head_c llhead = 0;
Dwarf_Locdesc_c llbuf = 0;
int local_listlen = 1;
Dwarf_Addr rawlowpc = 0;
Dwarf_Addr rawhighpc = MAX_ADDR;
Dwarf_Small version_stamp = dwarf_version;
int res = 0;
llhead = (Dwarf_Loc_Head_c)_dwarf_get_alloc(dbg,
DW_DLA_LOC_HEAD_C, 1);
if (!llhead) {
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
memset(&loc_block,0,sizeof(loc_block));
loc_block.bl_len = expression_length;
loc_block.bl_data = expression_in;
loc_block.bl_kind = DW_LKIND_expression; /* Not from loclist. */
loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
loc_block.bl_locdesc_offset = 0; /* Fake. Not meaningful. */
llbuf = (Dwarf_Locdesc_c)
_dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, local_listlen);
if (!llbuf) {
dwarf_loc_head_c_dealloc(llhead);
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
return (DW_DLV_ERROR);
}
llhead->ll_locdesc = llbuf;
llhead->ll_locdesc_count = local_listlen;
llhead->ll_context = 0; /* Not available! */
llhead->ll_dbg = dbg;
llhead->ll_kind = DW_LKIND_expression;
/* An empty location description (block length 0)
means the code generator emitted no variable,
the variable was not generated,
it was unused or perhaps never tested
after being set. Dwarf2,
section 2.4.1 In other words, it is not
an error, and we don't
test for block length 0 specially here. */
/* Fills in the locdesc and its operators list at index 0 */
res = _dwarf_fill_in_locdesc_op_c(dbg,
0,
llhead,
&loc_block,
address_size,
offset_size,
version_stamp,
rawlowpc,
rawhighpc,
DW_LKIND_expression,
error);
if (res != DW_DLV_OK) {
/* low level error already set: let it be passed back */
dwarf_loc_head_c_dealloc(llhead);
return (DW_DLV_ERROR);
}
*loc_head = llhead;
*listlen = local_listlen;
return (DW_DLV_OK);
}
/* New June 2020. */
int
dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c loclist_head,
Dwarf_Unsigned index,
Dwarf_Small * lle_value_out,
Dwarf_Unsigned * rawval1,
Dwarf_Unsigned * rawval2,
Dwarf_Bool * debug_addr_unavailable,
Dwarf_Addr * lowpc_out, /* 'cooked' value */
Dwarf_Addr * hipc_out, /* 'cooked' value */
Dwarf_Unsigned * loclist_expr_op_count_out,
/* Returns pointer to the specific locdesc of the index; */
Dwarf_Locdesc_c* locdesc_entry_out,
Dwarf_Small * loclist_source_out, /* 0,1, or 2 */
Dwarf_Unsigned * expression_offset_out,
Dwarf_Unsigned * locdesc_offset_out,
Dwarf_Error * error)
{
Dwarf_Locdesc_c descs_base = 0;
Dwarf_Locdesc_c desc = 0;
Dwarf_Unsigned desc_count = 0;
Dwarf_Debug dbg;
desc_count = loclist_head->ll_locdesc_count;
descs_base = loclist_head->ll_locdesc;
dbg = loclist_head->ll_dbg;
if (index >= desc_count) {
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
return (DW_DLV_ERROR);
}
desc = descs_base + index;
*lle_value_out = desc->ld_lle_value;
*rawval1 = desc->ld_rawlow;
*rawval2 = desc->ld_rawhigh;
*lowpc_out = desc->ld_lopc;
*hipc_out = desc->ld_highpc;
*debug_addr_unavailable = desc->ld_index_failed;
*loclist_expr_op_count_out = desc->ld_cents;
*locdesc_entry_out = desc;
*loclist_source_out = desc->ld_kind;
*expression_offset_out = desc->ld_section_offset;
*locdesc_offset_out = desc->ld_locdesc_offset;
return DW_DLV_OK;
}
/* Use dwarf_get_locdesc_entry_d() instead
This function is not sufficient for DWARF 5. */
int
dwarf_get_locdesc_entry_c(Dwarf_Loc_Head_c loclist_head,
Dwarf_Unsigned index,
Dwarf_Small * lle_value_out,
Dwarf_Addr * lowpc_out,
Dwarf_Addr * hipc_out,
Dwarf_Unsigned * loclist_count_out,
/* Returns pointer to the specific locdesc of the index; */
Dwarf_Locdesc_c* locdesc_entry_out,
/* 0,1,2 or 5 DW_LKIND_* */
Dwarf_Small * loclist_source_out,
Dwarf_Unsigned * expression_offset_out,
Dwarf_Unsigned * locdesc_offset_out,
Dwarf_Error * error)
{
int res = 0;
Dwarf_Unsigned cookedlow = 0;
Dwarf_Unsigned cookedhigh = 0;
Dwarf_Bool debug_addr_unavailable = FALSE;
res = dwarf_get_locdesc_entry_d(loclist_head,
index,lle_value_out,
lowpc_out,hipc_out,
&debug_addr_unavailable,
&cookedlow,&cookedhigh,
loclist_count_out,
locdesc_entry_out,
loclist_source_out,
expression_offset_out,
locdesc_offset_out,
error);
return res;
}
int
dwarf_get_location_op_value_d(Dwarf_Locdesc_c locdesc,
Dwarf_Unsigned index,
Dwarf_Small * atom_out,
Dwarf_Unsigned * operand1,
Dwarf_Unsigned * operand2,
Dwarf_Unsigned * operand3,
Dwarf_Unsigned * rawop1,
Dwarf_Unsigned * rawop2,
Dwarf_Unsigned * rawop3,
Dwarf_Unsigned * offset_for_branch,
Dwarf_Error* error)
{
Dwarf_Loc_Expr_Op op = 0;
Dwarf_Unsigned max = locdesc->ld_cents;
if(index >= max) {
Dwarf_Debug dbg = locdesc->ld_loclist_head->ll_dbg;
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
return (DW_DLV_ERROR);
}
op = locdesc->ld_s + index;
*atom_out = op->lr_atom;
*operand1 = op->lr_number;
*operand2 = op->lr_number2;
*operand3 = op->lr_number3;
*rawop1 = op->lr_raw1;
*rawop2 = op->lr_raw2;
*rawop3 = op->lr_raw3;
*offset_for_branch = op->lr_offset;
return DW_DLV_OK;
}
int
dwarf_get_location_op_value_c(Dwarf_Locdesc_c locdesc,
Dwarf_Unsigned index,
Dwarf_Small * atom_out,
Dwarf_Unsigned * operand1,
Dwarf_Unsigned * operand2,
Dwarf_Unsigned * operand3,
Dwarf_Unsigned * offset_for_branch,
Dwarf_Error* error)
{
Dwarf_Unsigned raw1 = 0;
Dwarf_Unsigned raw2 = 0;
Dwarf_Unsigned raw3 = 0;
int res = 0;
res = dwarf_get_location_op_value_d(locdesc,
index,atom_out,
operand1,operand2,operand3,
&raw1,&raw2,&raw3,
offset_for_branch,
error);
return res;
}
void
dwarf_loc_head_c_dealloc(Dwarf_Loc_Head_c loclist_head)
{
Dwarf_Debug dbg = loclist_head->ll_dbg;
/* destructor will remove content then free head
itself */
dwarf_dealloc(dbg,loclist_head,DW_DLA_LOC_HEAD_C);
}
/* ============== End of the October 2015 interfaces. */
|