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 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867
|
{
---------------------------------------------------------------------------
fpdbgdwarf.pas - Native Freepascal debugger - Dwarf symbol processing
---------------------------------------------------------------------------
This unit contains helper classes for handling and evaluating of debuggee data
described by DWARF debug symbols
---------------------------------------------------------------------------
@created(Mon Aug 1st WET 2006)
@lastmod($Date: 2019-01-04 15:12:44 +0100 (Fr, 04 Jan 2019) $)
@author(Marc Weustink <marc@@dommelstein.nl>)
@author(Martin Friebe)
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit FpDbgDwarf;
{$mode objfpc}{$H+}
{off $INLINE OFF}
(* Notes:
* FpDbgDwarfValues and Context
The Values do not add a reference to the Context. Yet they require the Context.
It is the users responsibility to keep the context, as long as any value exists.
*)
interface
uses
Classes, SysUtils, types, math, FpDbgInfo, FpDbgDwarfDataClasses, FpdMemoryTools, FpErrorMessages,
FpDbgUtil, FpDbgDwarfConst, DbgIntfBaseTypes, LazUTF8, LazLoggerBase, LazClasses;
type
TFpDwarfInfo = FpDbgDwarfDataClasses.TFpDwarfInfo;
{ TFpDwarfDefaultSymbolClassMap }
TFpDwarfDefaultSymbolClassMap = class(TFpDwarfSymbolClassMap)
public
class function HandleCompUnit(ACU: TDwarfCompilationUnit): Boolean; override;
class function GetDwarfSymbolClass(ATag: Cardinal): TDbgDwarfSymbolBaseClass; override;
class function CreateContext(AThreadId, AStackFrame: Integer; AnAddress:
TDbgPtr; ASymbol: TFpDbgSymbol; ADwarf: TFpDwarfInfo): TFpDbgInfoContext; override;
class function CreateProcSymbol(ACompilationUnit: TDwarfCompilationUnit;
AInfo: PDwarfAddressInfo; AAddress: TDbgPtr): TDbgDwarfSymbolBase; override;
end;
{ TFpDwarfInfoAddressContext }
TFpDwarfInfoAddressContext = class(TFpDbgInfoContext)
private
FSymbol: TFpDbgSymbol;
FAddress: TDBGPtr;
FThreadId, FStackFrame: Integer;
FDwarf: TFpDwarfInfo;
FlastResult: TFpDbgValue;
protected
function GetSymbolAtAddress: TFpDbgSymbol; override;
function GetProcedureAtAddress: TFpDbgValue; override;
function GetAddress: TDbgPtr; override;
function GetThreadId: Integer; override;
function GetStackFrame: Integer; override;
function GetSizeOfAddress: Integer; override;
function GetMemManager: TFpDbgMemManager; override;
property Symbol: TFpDbgSymbol read FSymbol;
property Dwarf: TFpDwarfInfo read FDwarf;
property Address: TDBGPtr read FAddress write FAddress;
property ThreadId: Integer read FThreadId write FThreadId;
property StackFrame: Integer read FStackFrame write FStackFrame;
procedure ApplyContext(AVal: TFpDbgValue); inline;
function SymbolToValue(ASym: TFpDbgSymbol): TFpDbgValue; inline;
procedure AddRefToVal(AVal: TFpDbgValue); inline;
function GetSelfParameter: TFpDbgValue; virtual;
function FindExportedSymbolInUnits(const AName: String; PNameUpper, PNameLower: PChar;
SkipCompUnit: TDwarfCompilationUnit; out ADbgValue: TFpDbgValue): Boolean; inline;
function FindSymbolInStructure(const AName: String; PNameUpper, PNameLower: PChar;
InfoEntry: TDwarfInformationEntry; out ADbgValue: TFpDbgValue): Boolean; inline;
// FindLocalSymbol: for the subroutine itself
function FindLocalSymbol(const AName: String; PNameUpper, PNameLower: PChar;
InfoEntry: TDwarfInformationEntry; out ADbgValue: TFpDbgValue): Boolean; virtual;
public
constructor Create(AThreadId, AStackFrame: Integer; AnAddress: TDbgPtr; ASymbol: TFpDbgSymbol; ADwarf: TFpDwarfInfo);
destructor Destroy; override;
function FindSymbol(const AName: String): TFpDbgValue; override;
end;
TFpDwarfSymbol = class;
TFpDwarfSymbolType = class;
TFpDwarfSymbolValue = class;
TFpDwarfSymbolValueClass = class of TFpDwarfSymbolValue;
TFpDwarfSymbolTypeClass = class of TFpDwarfSymbolType;
{%region Value objects }
{ TFpDwarfValueBase }
TFpDwarfValueBase = class(TFpDbgValue)
private
FContext: TFpDbgInfoContext;
public
property Context: TFpDbgInfoContext read FContext write FContext;
end;
{ TFpDwarfValueTypeDefinition }
TFpDwarfValueTypeDefinition = class(TFpDwarfValueBase)
private
FSymbol: TFpDbgSymbol; // stType
protected
function GetKind: TDbgSymbolKind; override;
function GetDbgSymbol: TFpDbgSymbol; override;
public
constructor Create(ASymbol: TFpDbgSymbol); // Only for stType
destructor Destroy; override;
function GetTypeCastedValue(ADataVal: TFpDbgValue): TFpDbgValue; override;
end;
{ TFpDwarfValue }
TFpDwarfValue = class(TFpDwarfValueBase)
private
FOwner: TFpDwarfSymbolType; // the creator, usually the type
FValueSymbol: TFpDwarfSymbolValue;
FTypeCastTargetType: TFpDwarfSymbolType;
FTypeCastSourceValue: TFpDbgValue;
FDataAddressCache: array of TFpDbgMemLocation;
FStructureValue: TFpDwarfValue;
FLastMember: TFpDwarfValue;
function GetDataAddressCache(AIndex: Integer): TFpDbgMemLocation;
procedure SetDataAddressCache(AIndex: Integer; AValue: TFpDbgMemLocation);
procedure SetStructureValue(AValue: TFpDwarfValue);
protected
FLastError: TFpError;
function MemManager: TFpDbgMemManager; inline;
procedure DoReferenceAdded; override;
procedure DoReferenceReleased; override;
procedure CircleBackRefActiveChanged(NewActive: Boolean); override;
procedure SetLastMember(ALastMember: TFpDwarfValue);
function GetLastError: TFpError; override;
function AddressSize: Byte; inline;
// Address of the symbol (not followed any type deref, or location)
function GetAddress: TFpDbgMemLocation; override;
function OrdOrAddress: TFpDbgMemLocation;
// Address of the data (followed type deref, location, ...)
function DataAddr: TFpDbgMemLocation;
function OrdOrDataAddr: TFpDbgMemLocation;
function GetDwarfDataAddress(out AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType = nil): Boolean;
function GetStructureDwarfDataAddress(out AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType = nil): Boolean;
function HasDwarfDataAddress: Boolean; // TODO: is this just HasAddress?
procedure Reset; virtual; // keeps lastmember and structureninfo
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function HasTypeCastInfo: Boolean;
function IsValidTypeCast: Boolean; virtual;
function GetKind: TDbgSymbolKind; override;
function GetMemberCount: Integer; override;
function GetMemberByName(AIndex: String): TFpDbgValue; override;
function GetMember(AIndex: Int64): TFpDbgValue; override;
function GetDbgSymbol: TFpDbgSymbol; override;
function GetTypeInfo: TFpDbgSymbol; override;
function GetContextTypeInfo: TFpDbgSymbol; override;
property TypeCastTargetType: TFpDwarfSymbolType read FTypeCastTargetType;
property TypeCastSourceValue: TFpDbgValue read FTypeCastSourceValue;
public
constructor Create(AOwner: TFpDwarfSymbolType);
destructor Destroy; override;
procedure SetValueSymbol(AValueSymbol: TFpDwarfSymbolValue);
function SetTypeCastInfo(AStructure: TFpDwarfSymbolType;
ASource: TFpDbgValue): Boolean; // Used for Typecast
// StructureValue: Any Value returned via GetMember points to its structure
property StructureValue: TFpDwarfValue read FStructureValue write SetStructureValue;
// DataAddressCache[0]: ValueAddress // DataAddressCache[1..n]: DataAddress
property DataAddressCache[AIndex: Integer]: TFpDbgMemLocation read GetDataAddressCache write SetDataAddressCache;
end;
{ TFpDwarfValueSized }
TFpDwarfValueSized = class(TFpDwarfValue)
private
FSize: Integer;
protected
function CanUseTypeCastAddress: Boolean;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetSize: Integer; override;
public
constructor Create(AOwner: TFpDwarfSymbolType; ASize: Integer);
end;
{ TFpDwarfValueNumeric }
TFpDwarfValueNumeric = class(TFpDwarfValueSized)
protected
FEvaluated: set of (doneUInt, doneInt, doneAddr, doneFloat);
protected
procedure Reset; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override; // svfOrdinal
function IsValidTypeCast: Boolean; override;
public
constructor Create(AOwner: TFpDwarfSymbolType; ASize: Integer);
end;
{ TFpDwarfValueInteger }
TFpDwarfValueInteger = class(TFpDwarfValueNumeric)
private
FIntValue: Int64;
protected
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsCardinal: QWord; override;
function GetAsInteger: Int64; override;
end;
{ TFpDwarfValueCardinal }
TFpDwarfValueCardinal = class(TFpDwarfValueNumeric)
private
FValue: QWord;
protected
function GetAsCardinal: QWord; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
end;
{ TFpDwarfValueFloat }
TFpDwarfValueFloat = class(TFpDwarfValueNumeric) // TDbgDwarfSymbolValue
// TODO: typecasts to int should convert
private
FValue: Extended;
protected
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsFloat: Extended; override;
end;
{ TFpDwarfValueBoolean }
TFpDwarfValueBoolean = class(TFpDwarfValueCardinal)
protected
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsBool: Boolean; override;
end;
{ TFpDwarfValueChar }
TFpDwarfValueChar = class(TFpDwarfValueCardinal)
protected
// returns single char(byte) / widechar
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsString: AnsiString; override;
function GetAsWideString: WideString; override;
end;
{ TFpDwarfValuePointer }
TFpDwarfValuePointer = class(TFpDwarfValueNumeric)
private
FLastAddrMember: TFpDbgValue;
FPointetToAddr: TFpDbgMemLocation;
protected
function GetAsCardinal: QWord; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetDataAddress: TFpDbgMemLocation; override;
function GetAsString: AnsiString; override;
function GetAsWideString: WideString; override;
function GetMember(AIndex: Int64): TFpDbgValue; override;
public
destructor Destroy; override;
end;
{ TFpDwarfValueEnum }
TFpDwarfValueEnum = class(TFpDwarfValueNumeric)
private
FValue: QWord;
FMemberIndex: Integer;
FMemberValueDone: Boolean;
procedure InitMemberIndex;
protected
procedure Reset; override;
//function IsValidTypeCast: Boolean; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsCardinal: QWord; override;
function GetAsString: AnsiString; override;
// Has exactly 0 (if the ordinal value is out of range) or 1 member (the current value's enum)
function GetMemberCount: Integer; override;
function GetMember({%H-}AIndex: Int64): TFpDbgValue; override;
end;
{ TFpDwarfValueEnumMember }
TFpDwarfValueEnumMember = class(TFpDwarfValue)
private
FOwnerVal: TFpDwarfSymbolValue;
protected
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsCardinal: QWord; override;
function GetAsString: AnsiString; override;
function IsValidTypeCast: Boolean; override;
public
constructor Create(AOwner: TFpDwarfSymbolValue);
end;
{ TFpDwarfValueConstNumber }
TFpDwarfValueConstNumber = class(TFpDbgValueConstNumber)
protected
procedure Update(AValue: QWord; ASigned: Boolean);
end;
{ TFpDwarfValueSet }
TFpDwarfValueSet = class(TFpDwarfValueSized)
private
FMem: array of Byte;
FMemberCount: Integer;
FMemberMap: array of Integer;
FNumValue: TFpDwarfValueConstNumber;
FTypedNumValue: TFpDbgValue;
procedure InitMap;
protected
procedure Reset; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetMemberCount: Integer; override;
function GetMember(AIndex: Int64): TFpDbgValue; override;
function GetAsCardinal: QWord; override; // only up to qmord
function IsValidTypeCast: Boolean; override;
public
destructor Destroy; override;
end;
{ TFpDwarfValueStruct }
TFpDwarfValueStruct = class(TFpDwarfValue)
private
FDataAddress: TFpDbgMemLocation;
FDataAddressDone: Boolean;
protected
procedure Reset; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetAsCardinal: QWord; override;
function GetDataAddress: TFpDbgMemLocation; override;
function GetDataSize: Integer; override;
function GetSize: Integer; override;
end;
{ TFpDwarfValueStructTypeCast }
TFpDwarfValueStructTypeCast = class(TFpDwarfValue)
private
FMembers: TFpDbgCircularRefCntObjList;
FDataAddress: TFpDbgMemLocation;
FDataAddressDone: Boolean;
protected
procedure Reset; override;
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetKind: TDbgSymbolKind; override;
function GetAsCardinal: QWord; override;
function GetSize: Integer; override;
function GetDataSize: Integer; override;
function GetDataAddress: TFpDbgMemLocation; override;
function IsValidTypeCast: Boolean; override;
public
destructor Destroy; override;
function GetMemberByName(AIndex: String): TFpDbgValue; override;
function GetMember(AIndex: Int64): TFpDbgValue; override;
function GetMemberCount: Integer; override;
end;
{ TFpDwarfValueConstAddress }
TFpDwarfValueConstAddress = class(TFpDbgValueConstAddress)
protected
procedure Update(AnAddress: TFpDbgMemLocation);
end;
{ TFpDwarfValueArray }
TFpDwarfValueArray = class(TFpDwarfValue)
private
FAddrObj: TFpDwarfValueConstAddress;
protected
function GetFieldFlags: TFpDbgValueFieldFlags; override;
function GetKind: TDbgSymbolKind; override;
function GetAsCardinal: QWord; override;
function GetDataAddress: TFpDbgMemLocation; override;
function GetMember(AIndex: Int64): TFpDbgValue; override;
function GetMemberEx(const AIndex: array of Int64): TFpDbgValue; override;
function GetMemberCount: Integer; override;
function GetMemberCountEx(const AIndex: array of Int64): Integer; override;
function GetIndexType(AIndex: Integer): TFpDbgSymbol; override;
function GetIndexTypeCount: Integer; override;
function IsValidTypeCast: Boolean; override;
public
destructor Destroy; override;
end;
{%endregion Value objects }
{%region Symbol objects }
TInitLocParserData = record
(* DW_AT_data_member_location: Is always pushed on stack
DW_AT_data_location: Is avalibale for DW_OP_push_object_address
*)
ObjectDataAddress: TFpDbgMemLocation;
ObjectDataAddrPush: Boolean; // always push ObjectDataAddress on stack: DW_AT_data_member_location
end;
PInitLocParserData = ^TInitLocParserData;
{ TDbgDwarfIdentifier }
{ TFpDwarfSymbol }
TFpDwarfSymbol = class(TDbgDwarfSymbolBase)
private
FNestedTypeInfo: TFpDwarfSymbolType;
FParentTypeInfo: TFpDwarfSymbol;
FDwarfReadFlags: set of (didtNameRead, didtTypeRead, didtArtificialRead, didtIsArtifical);
function GetNestedTypeInfo: TFpDwarfSymbolType;
protected
(* There will be a circular reference between parenttype and self
"self" will only set its reference to parenttype, if self has other references. *)
procedure DoReferenceAdded; override;
procedure DoReferenceReleased; override;
procedure CircleBackRefActiveChanged(ANewActive: Boolean); override;
procedure SetParentTypeInfo(AValue: TFpDwarfSymbol); virtual;
function DoGetNestedTypeInfo: TFpDwarfSymbolType; virtual;
function ReadMemberVisibility(out AMemberVisibility: TDbgSymbolMemberVisibility): Boolean;
function IsArtificial: Boolean; // usud by formal param and subprogram
procedure NameNeeded; override;
procedure TypeInfoNeeded; override;
property NestedTypeInfo: TFpDwarfSymbolType read GetNestedTypeInfo;
// OwnerTypeInfo: reverse of "NestedTypeInfo" (variable that is of this type)
// property OwnerTypeInfo: TDbgDwarfIdentifier read FOwnerTypeInfo; // write SetOwnerTypeInfo;
// ParentTypeInfo: funtion for local var / class for member
property ParentTypeInfo: TFpDwarfSymbol read FParentTypeInfo write SetParentTypeInfo;
function DataSize: Integer; virtual;
protected
function InitLocationParser(const {%H-}ALocationParser: TDwarfLocationExpression;
AnInitLocParserData: PInitLocParserData = nil): Boolean; virtual;
function LocationFromTag(ATag: Cardinal; AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; // kept, if tag does not exist
AnInitLocParserData: PInitLocParserData = nil;
AnInformationEntry: TDwarfInformationEntry = nil;
ASucessOnMissingTag: Boolean = False
): Boolean;
// GetDataAddress: data of a class, or string
function GetDataAddress(AValueObj: TFpDwarfValue; var AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType; ATargetCacheIndex: Integer): Boolean;
function GetDataAddressNext(AValueObj: TFpDwarfValue; var AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType; ATargetCacheIndex: Integer): Boolean; virtual;
function HasAddress: Boolean; virtual;
procedure Init; override;
public
class function CreateSubClass(AName: String; AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbol;
destructor Destroy; override;
function StartScope: TDbgPtr; // return 0, if none. 0 includes all anyway
end;
{ TFpDwarfSymbolValue }
TFpDwarfSymbolValue = class(TFpDwarfSymbol) // var, const, member, ...
protected
FValueObject: TFpDwarfValue;
FMembers: TFpDbgCircularRefCntObjList;
function GetValueAddress({%H-}AValueObj: TFpDwarfValue;{%H-} out AnAddress: TFpDbgMemLocation): Boolean; virtual;
function GetValueDataAddress(AValueObj: TFpDwarfValue; out AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType = nil): Boolean;
procedure KindNeeded; override;
procedure MemberVisibilityNeeded; override;
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberByName(AIndex: String): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
procedure Init; override;
public
destructor Destroy; override;
class function CreateValueSubClass(AName: String; AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbolValue;
end;
{ TFpDwarfSymbolValueWithLocation }
TFpDwarfSymbolValueWithLocation = class(TFpDwarfSymbolValue)
private
procedure FrameBaseNeeded(ASender: TObject); // Sender = TDwarfLocationExpression
protected
function GetValueObject: TFpDbgValue; override;
function InitLocationParser(const ALocationParser: TDwarfLocationExpression;
AnInitLocParserData: PInitLocParserData): Boolean; override;
end;
{ TFpDwarfSymbolType }
(* Types and allowed tags in dwarf 2
DW_TAG_enumeration_type, DW_TAG_subroutine_type, DW_TAG_union_type,
DW_TAG_ptr_to_member_type, DW_TAG_set_type, DW_TAG_subrange_type, DW_TAG_file_type,
DW_TAG_thrown_type
DW_TAG_base_type
DW_AT_encoding Y
DW_AT_bit_offset Y
DW_AT_bit_size Y
DW_TAG_base_type
| DW_TAG_typedef
| | DW_TAG_string_type
| | | DW_TAG_array_type
| | | |
| | | | DW_TAG_class_type
| | | | | DW_TAG_structure_type
| | | | | |
| | | | | | DW_TAG_enumeration_type
| | | | | | | DW_TAG_set_type
| | | | | | | | DW_TAG_enumerator
| | | | | | | | | DW_TAG_subrange_type
DW_AT_name Y Y Y Y Y Y Y Y Y Y
DW_AT_sibling Y Y Y Y Y Y Y Y Y Y
DECL Y Y Y Y Y Y Y Y Y
DW_AT_byte_size Y Y Y Y Y Y Y Y
DW_AT_abstract_origin Y Y Y Y Y Y Y Y
DW_AT_accessibility Y Y Y Y Y Y Y Y
DW_AT_declaration Y Y Y Y Y Y Y Y
DW_AT_start_scope Y Y Y Y Y Y Y
DW_AT_visibility Y Y Y Y Y Y Y Y
DW_AT_type Y Y Y Y
DW_AT_segment Y DW_TAG_string_type
DW_AT_string_length Y
DW_AT_ordering Y DW_TAG_array_type
DW_AT_stride_size Y
DW_AT_const_value Y DW_TAG_enumerator
DW_AT_count Y DW_TAG_subrange_type
DW_AT_lower_bound Y
DW_AT_upper_bound Y
DW_TAG_pointer_type
| DW_TAG_reference_type
| | DW_TAG_packed_type
| | | DW_TAG_const_type
| | | | DW_TAG_volatile_type
DW_AT_address_class Y Y
DW_AT_sibling Y Y Y Y Y
DW_AT_type Y Y Y Y Y
DECL = DW_AT_decl_column, DW_AT_decl_file, DW_AT_decl_line
*)
TFpDwarfSymbolType = class(TFpDwarfSymbol)
protected
procedure Init; override;
procedure MemberVisibilityNeeded; override;
procedure SizeNeeded; override;
function GetTypedValueObject({%H-}ATypeCast: Boolean): TFpDwarfValue; virtual; // returns refcount=1 for caller, no cached copy kept
public
class function CreateTypeSubClass(AName: String; AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbolType;
function TypeCastValue(AValue: TFpDbgValue): TFpDbgValue; override;
// TODO: flag bounds as cardinal if needed
function GetValueBounds({%H-}AValueObj: TFpDwarfValue; out ALowBound, AHighBound: Int64): Boolean; virtual;
(*TODO: workaround / quickfix // only partly implemented
When reading several elements of an array (dyn or stat), the typeinfo is always the same instance (type of array entry)
But once that instance has read data (like bounds / dwarf3 bounds are read from app mem), this is cached.
So all consecutive entries get the same info...
array of string
array of shortstring
array of {dyn} array
This works similar to "Init", but should only clear data that is not static / depends on memory reads
Bounds (and maybe all such data) should be stored on the value object)
*)
procedure ResetValueBounds; virtual;
end;
{ TFpDwarfSymbolTypeBasic }
TFpDwarfSymbolTypeBasic = class(TFpDwarfSymbolType)
//function DoGetNestedTypeInfo: TFpDwarfSymbolType; // return nil
protected
procedure KindNeeded; override;
procedure TypeInfoNeeded; override;
function GetTypedValueObject({%H-}ATypeCast: Boolean): TFpDwarfValue; override;
function GetHasBounds: Boolean; override;
function GetOrdHighBound: Int64; override;
function GetOrdLowBound: Int64; override;
end;
{ TFpDwarfSymbolTypeModifier }
TFpDwarfSymbolTypeModifier = class(TFpDwarfSymbolType)
protected
procedure TypeInfoNeeded; override;
procedure ForwardToSymbolNeeded; override;
function GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue; override;
end;
{ TFpDwarfSymbolTypeRef }
TFpDwarfSymbolTypeRef = class(TFpDwarfSymbolTypeModifier)
protected
function GetFlags: TDbgSymbolFlags; override;
function GetDataAddressNext(AValueObj: TFpDwarfValue; var AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType; ATargetCacheIndex: Integer): Boolean; override;
end;
{ TFpDwarfSymbolTypeDeclaration }
TFpDwarfSymbolTypeDeclaration = class(TFpDwarfSymbolTypeModifier)
protected
// fpc encodes classes as pointer, not ref (so Obj1 = obj2 compares the pointers)
// typedef > pointer > srtuct
// while a pointer to class/object: pointer > typedef > ....
function DoGetNestedTypeInfo: TFpDwarfSymbolType; override;
end;
{ TFpDwarfSymbolTypeSubRange }
TFpDwarfSubRangeBoundReadState = (rfNotRead, rfNotFound, rfConst, rfValue);
TFpDwarfSymbolTypeSubRange = class(TFpDwarfSymbolTypeModifier)
// TODO not a modifier, maybe have a forwarder base class
private
FLowBoundConst: Int64;
FLowBoundValue: TFpDwarfSymbolValue;
FLowBoundState: TFpDwarfSubRangeBoundReadState;
FHighBoundConst: Int64;
FHighBoundValue: TFpDwarfSymbolValue;
FHighBoundState: TFpDwarfSubRangeBoundReadState;
FCountConst: Int64;
FCountValue: TFpDwarfSymbolValue;
FCountState: TFpDwarfSubRangeBoundReadState;
FLowEnumIdx, FHighEnumIdx: Integer;
FEnumIdxValid: Boolean;
procedure InitEnumIdx;
procedure ReadBounds(AValueObj: TFpDwarfValue);
protected
function DoGetNestedTypeInfo: TFpDwarfSymbolType;override;
function GetHasBounds: Boolean; override;
function GetOrdHighBound: Int64; override;
function GetOrdLowBound: Int64; override;
procedure NameNeeded; override;
procedure KindNeeded; override;
procedure SizeNeeded; override;
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
function GetFlags: TDbgSymbolFlags; override;
procedure Init; override;
public
function GetValueBounds(AValueObj: TFpDwarfValue; out ALowBound,
AHighBound: Int64): Boolean; override;
procedure ResetValueBounds; override;
end;
{ TFpDwarfSymbolTypePointer }
TFpDwarfSymbolTypePointer = class(TFpDwarfSymbolType)
private
FIsInternalPointer: Boolean;
function GetIsInternalPointer: Boolean; inline;
function IsInternalDynArrayPointer: Boolean; inline;
protected
procedure TypeInfoNeeded; override;
procedure KindNeeded; override;
procedure SizeNeeded; override;
procedure ForwardToSymbolNeeded; override;
function GetDataAddressNext(AValueObj: TFpDwarfValue; var AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType; ATargetCacheIndex: Integer): Boolean; override;
function GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue; override;
function DataSize: Integer; override;
public
property IsInternalPointer: Boolean read GetIsInternalPointer write FIsInternalPointer; // Class (also DynArray, but DynArray is handled without this)
end;
{ TFpDwarfSymbolValueEnumMember }
TFpDwarfSymbolValueEnumMember = class(TFpDwarfSymbolValue)
FOrdinalValue: Int64;
FOrdinalValueRead, FHasOrdinalValue: Boolean;
procedure ReadOrdinalValue;
protected
procedure KindNeeded; override;
function GetHasOrdinalValue: Boolean; override;
function GetOrdinalValue: Int64; override;
procedure Init; override;
function GetValueObject: TFpDbgValue; override;
end;
{ TFpDwarfSymbolTypeEnum }
TFpDwarfSymbolTypeEnum = class(TFpDwarfSymbolType)
private
FMembers: TFpDbgCircularRefCntObjList;
procedure CreateMembers;
protected
function GetTypedValueObject({%H-}ATypeCast: Boolean): TFpDwarfValue; override;
procedure KindNeeded; override;
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberByName(AIndex: String): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
function GetHasBounds: Boolean; override;
function GetOrdHighBound: Int64; override;
function GetOrdLowBound: Int64; override;
public
destructor Destroy; override;
end;
{ TFpDwarfSymbolTypeSet }
TFpDwarfSymbolTypeSet = class(TFpDwarfSymbolType)
protected
procedure KindNeeded; override;
function GetTypedValueObject({%H-}ATypeCast: Boolean): TFpDwarfValue; override;
function GetMemberCount: Integer; override;
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
end;
(*
If not specified
.NestedTypeInfo --> copy of TypeInfo
.ParentTypeInfo --> nil
ParentTypeInfo: has a weak RefCount (only AddRef, if self has other refs)
AnObject = TFpDwarfSymbolValueVariable
|-- .TypeInfo --> TBar = TFpDwarfSymbolTypeStructure [*1]
|-- .ParentTypeInfo --> may point to subroutine, if param or local var // TODO
TBar = TFpDwarfSymbolTypeStructure
|-- .TypeInfo --> TBarBase = TFpDwarfSymbolTypeStructure
TBarBase = TFpDwarfSymbolTypeStructure
|-- .TypeInfo --> TOBject = TFpDwarfSymbolTypeStructure
TObject = TFpDwarfSymbolTypeStructure
|-- .TypeInfo --> nil
FField = TFpDwarfSymbolValueMember (declared in TBarBase)
|-- .TypeInfo --> Integer = TFpDwarfSymbolTypeBasic [*1]
|-- .ParentTypeInfo --> TBarBase
[*1] May have TFpDwarfSymbolTypeDeclaration or others
*)
{ TFpDwarfSymbolValueMember }
TFpDwarfSymbolValueMember = class(TFpDwarfSymbolValueWithLocation)
protected
function GetValueAddress(AValueObj: TFpDwarfValue; out AnAddress: TFpDbgMemLocation): Boolean; override;
function HasAddress: Boolean; override;
end;
{ TFpDwarfSymbolTypeStructure }
TFpDwarfSymbolTypeStructure = class(TFpDwarfSymbolType)
// record or class
private
FMembers: TFpDbgCircularRefCntObjList;
FLastChildByName: TFpDwarfSymbol;
FInheritanceInfo: TDwarfInformationEntry;
procedure CreateMembers;
procedure InitInheritanceInfo; inline;
protected
function DoGetNestedTypeInfo: TFpDwarfSymbolType; override;
procedure KindNeeded; override;
function GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue; override;
// GetMember, if AIndex > Count then parent
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberByName(AIndex: String): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
function GetDataAddressNext(AValueObj: TFpDwarfValue; var AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType; ATargetCacheIndex: Integer): Boolean; override;
public
destructor Destroy; override;
end;
{ TFpDwarfSymbolTypeArray }
TFpDwarfSymbolTypeArray = class(TFpDwarfSymbolType)
private
FMembers: TFpDbgCircularRefCntObjList;
FRowMajor: Boolean;
FStrideInBits: Int64;
FDwarfArrayReadFlags: set of (didtStrideRead, didtOrdering);
procedure CreateMembers;
procedure ReadStride;
procedure ReadOrdering;
protected
procedure KindNeeded; override;
function GetTypedValueObject({%H-}ATypeCast: Boolean): TFpDwarfValue; override;
function GetFlags: TDbgSymbolFlags; override;
// GetMember: returns the TYPE/range of each index. NOT the data
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberByName({%H-}AIndex: String): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
function GetMemberAddress(AValObject: TFpDwarfValue; const AIndex: Array of Int64): TFpDbgMemLocation;
public
destructor Destroy; override;
procedure ResetValueBounds; override;
end;
{ TFpDwarfSymbolValueProc }
TFpDwarfSymbolValueProc = class(TFpDwarfSymbolValue)
private
//FCU: TDwarfCompilationUnit;
FProcMembers: TRefCntObjList; // Locals
FLastMember: TFpDbgSymbol;
FAddress: TDbgPtr;
FAddressInfo: PDwarfAddressInfo;
FStateMachine: TDwarfLineInfoStateMachine;
FFrameBaseParser: TDwarfLocationExpression;
FSelfParameter: TFpDwarfValue;
function StateMachineValid: Boolean;
function ReadVirtuality(out AFlags: TDbgSymbolFlags): Boolean;
procedure CreateMembers;
protected
function GetMember(AIndex: Int64): TFpDbgSymbol; override;
function GetMemberByName(AIndex: String): TFpDbgSymbol; override;
function GetMemberCount: Integer; override;
function GetFrameBase(ASender: TDwarfLocationExpression): TDbgPtr;
procedure KindNeeded; override;
procedure SizeNeeded; override;
function GetFlags: TDbgSymbolFlags; override;
function GetColumn: Cardinal; override;
function GetFile: String; override;
// function GetFlags: TDbgSymbolFlags; override;
function GetLine: Cardinal; override;
function GetValueObject: TFpDbgValue; override;
public
constructor Create(ACompilationUnit: TDwarfCompilationUnit; AInfo: PDwarfAddressInfo; AAddress: TDbgPtr); overload;
destructor Destroy; override;
// TODO members = locals ?
function GetSelfParameter(AnAddress: TDbgPtr = 0): TFpDwarfValue;
end;
{ TFpDwarfSymbolValueVariable }
TFpDwarfSymbolValueVariable = class(TFpDwarfSymbolValueWithLocation)
protected
function GetValueAddress(AValueObj: TFpDwarfValue; out AnAddress: TFpDbgMemLocation): Boolean; override;
function HasAddress: Boolean; override;
public
end;
{ TFpDwarfSymbolValueParameter }
TFpDwarfSymbolValueParameter = class(TFpDwarfSymbolValueWithLocation)
protected
function GetValueAddress(AValueObj: TFpDwarfValue; out AnAddress: TFpDbgMemLocation): Boolean; override;
function HasAddress: Boolean; override;
function GetFlags: TDbgSymbolFlags; override;
public
end;
{ TFpDwarfSymbolUnit }
TFpDwarfSymbolUnit = class(TFpDwarfSymbol)
private
FLastChildByName: TFpDbgSymbol;
protected
procedure Init; override;
function GetMemberByName(AIndex: String): TFpDbgSymbol; override;
public
destructor Destroy; override;
end;
{%endregion Symbol objects }
implementation
var
FPDBG_DWARF_VERBOSE, FPDBG_DWARF_ERRORS, FPDBG_DWARF_WARNINGS, FPDBG_DWARF_SEARCH, FPDBG_DWARF_DATA_WARNINGS: PLazLoggerLogGroup;
{ TFpDwarfDefaultSymbolClassMap }
class function TFpDwarfDefaultSymbolClassMap.HandleCompUnit(ACU: TDwarfCompilationUnit): Boolean;
begin
Result := True;
end;
class function TFpDwarfDefaultSymbolClassMap.GetDwarfSymbolClass(ATag: Cardinal): TDbgDwarfSymbolBaseClass;
begin
case ATag of
// TODO:
DW_TAG_constant:
Result := TFpDwarfSymbolValue;
DW_TAG_string_type,
DW_TAG_union_type, DW_TAG_ptr_to_member_type,
DW_TAG_file_type,
DW_TAG_thrown_type, DW_TAG_subroutine_type:
Result := TFpDwarfSymbolType;
// Type types
DW_TAG_packed_type,
DW_TAG_const_type,
DW_TAG_volatile_type: Result := TFpDwarfSymbolTypeModifier;
DW_TAG_reference_type: Result := TFpDwarfSymbolTypeRef;
DW_TAG_typedef: Result := TFpDwarfSymbolTypeDeclaration;
DW_TAG_pointer_type: Result := TFpDwarfSymbolTypePointer;
DW_TAG_base_type: Result := TFpDwarfSymbolTypeBasic;
DW_TAG_subrange_type: Result := TFpDwarfSymbolTypeSubRange;
DW_TAG_enumeration_type: Result := TFpDwarfSymbolTypeEnum;
DW_TAG_enumerator: Result := TFpDwarfSymbolValueEnumMember;
DW_TAG_set_type: Result := TFpDwarfSymbolTypeSet;
DW_TAG_structure_type,
DW_TAG_class_type: Result := TFpDwarfSymbolTypeStructure;
DW_TAG_array_type: Result := TFpDwarfSymbolTypeArray;
// Value types
DW_TAG_variable: Result := TFpDwarfSymbolValueVariable;
DW_TAG_formal_parameter: Result := TFpDwarfSymbolValueParameter;
DW_TAG_member: Result := TFpDwarfSymbolValueMember;
DW_TAG_subprogram: Result := TFpDwarfSymbolValueProc;
//
DW_TAG_compile_unit: Result := TFpDwarfSymbolUnit;
else
Result := TFpDwarfSymbol;
end;
end;
class function TFpDwarfDefaultSymbolClassMap.CreateContext(AThreadId, AStackFrame: Integer;
AnAddress: TDbgPtr; ASymbol: TFpDbgSymbol; ADwarf: TFpDwarfInfo): TFpDbgInfoContext;
begin
Result := TFpDwarfInfoAddressContext.Create(AThreadId, AStackFrame, AnAddress, ASymbol, ADwarf);
end;
class function TFpDwarfDefaultSymbolClassMap.CreateProcSymbol(ACompilationUnit: TDwarfCompilationUnit;
AInfo: PDwarfAddressInfo; AAddress: TDbgPtr): TDbgDwarfSymbolBase;
begin
Result := TFpDwarfSymbolValueProc.Create(ACompilationUnit, AInfo, AAddress);
end;
{ TDbgDwarfInfoAddressContext }
function TFpDwarfInfoAddressContext.GetSymbolAtAddress: TFpDbgSymbol;
begin
Result := FSymbol;
end;
function TFpDwarfInfoAddressContext.GetProcedureAtAddress: TFpDbgValue;
begin
Result := inherited GetProcedureAtAddress;
ApplyContext(Result);
end;
function TFpDwarfInfoAddressContext.GetAddress: TDbgPtr;
begin
Result := FAddress;
end;
function TFpDwarfInfoAddressContext.GetThreadId: Integer;
begin
Result := FThreadId;
end;
function TFpDwarfInfoAddressContext.GetStackFrame: Integer;
begin
Result := FStackFrame;
end;
function TFpDwarfInfoAddressContext.GetSizeOfAddress: Integer;
begin
assert(FSymbol is TFpDwarfSymbol, 'TDbgDwarfInfoAddressContext.GetSizeOfAddress');
Result := TFpDwarfSymbol(FSymbol).CompilationUnit.AddressSize;
end;
function TFpDwarfInfoAddressContext.GetMemManager: TFpDbgMemManager;
begin
Result := FDwarf.MemManager;
end;
procedure TFpDwarfInfoAddressContext.ApplyContext(AVal: TFpDbgValue);
begin
if (AVal <> nil) and (TFpDwarfValueBase(AVal).FContext = nil) then
TFpDwarfValueBase(AVal).FContext := Self;
end;
function TFpDwarfInfoAddressContext.SymbolToValue(ASym: TFpDbgSymbol): TFpDbgValue;
begin
if ASym = nil then begin
Result := nil;
exit;
end;
if ASym.SymbolType = stValue then begin
Result := ASym.Value;
if Result <> nil then
Result.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FlastResult, 'FindSymbol'){$ENDIF};
end
else begin
Result := TFpDwarfValueTypeDefinition.Create(ASym);
{$IFDEF WITH_REFCOUNT_DEBUG}Result.DbgRenameReference(@FlastResult, 'FindSymbol'){$ENDIF};
end;
ASym.ReleaseReference;
end;
procedure TFpDwarfInfoAddressContext.AddRefToVal(AVal: TFpDbgValue);
begin
AVal.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FlastResult, 'FindSymbol'){$ENDIF};
end;
function TFpDwarfInfoAddressContext.GetSelfParameter: TFpDbgValue;
begin
Result := TFpDwarfSymbolValueProc(FSymbol).GetSelfParameter(FAddress);
if (Result <> nil) and (TFpDwarfValueBase(Result).FContext = nil) then
TFpDwarfValueBase(Result).FContext := Self;
end;
function TFpDwarfInfoAddressContext.FindExportedSymbolInUnits(const AName: String; PNameUpper,
PNameLower: PChar; SkipCompUnit: TDwarfCompilationUnit; out ADbgValue: TFpDbgValue): Boolean;
var
i, ExtVal: Integer;
CU: TDwarfCompilationUnit;
InfoEntry, FoundInfoEntry: TDwarfInformationEntry;
s: String;
begin
Result := False;
ADbgValue := nil;
InfoEntry := nil;
FoundInfoEntry := nil;
i := FDwarf.CompilationUnitsCount;
while i > 0 do begin
dec(i);
CU := FDwarf.CompilationUnits[i];
if CU = SkipCompUnit then
continue;
//DebugLn(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier search UNIT Name=', CU.FileName]);
InfoEntry.ReleaseReference;
InfoEntry := TDwarfInformationEntry.Create(CU, nil);
InfoEntry.ScopeIndex := CU.FirstScope.Index;
if not InfoEntry.AbbrevTag = DW_TAG_compile_unit then
continue;
// compile_unit can not have startscope
s := CU.UnitName;
if (s <> '') and (CompareUtf8BothCase(PNameUpper, PNameLower, @s[1])) then begin
ReleaseRefAndNil(FoundInfoEntry);
ADbgValue := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
break;
end;
CU.ScanAllEntries;
if InfoEntry.GoNamedChildEx(PNameUpper, PNameLower) then begin
if InfoEntry.IsAddressInStartScope(FAddress) then begin
// only variables are marked "external", but types not / so we may need all top level
FoundInfoEntry.ReleaseReference;
FoundInfoEntry := InfoEntry.Clone;
//DebugLn(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier MAYBE FOUND Name=', CU.FileName]);
// DW_AT_visibility ?
if InfoEntry.ReadValue(DW_AT_external, ExtVal) then
if ExtVal <> 0 then
break;
// Search for better ADbgValue
end;
end;
end;
if FoundInfoEntry <> nil then begin;
ADbgValue := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, FoundInfoEntry));
FoundInfoEntry.ReleaseReference;
end;
InfoEntry.ReleaseReference;
Result := ADbgValue <> nil;
end;
function TFpDwarfInfoAddressContext.FindSymbolInStructure(const AName: String; PNameUpper,
PNameLower: PChar; InfoEntry: TDwarfInformationEntry; out ADbgValue: TFpDbgValue): Boolean;
var
InfoEntryInheritance: TDwarfInformationEntry;
FwdInfoPtr: Pointer;
FwdCompUint: TDwarfCompilationUnit;
SelfParam: TFpDbgValue;
begin
Result := False;
ADbgValue := nil;
InfoEntry.AddReference;
while True do begin
if not InfoEntry.IsAddressInStartScope(FAddress) then
break;
InfoEntryInheritance := InfoEntry.FindChildByTag(DW_TAG_inheritance);
if InfoEntry.GoNamedChildEx(PNameUpper, PNameLower) then begin
if InfoEntry.IsAddressInStartScope(FAddress) then begin
SelfParam := GetSelfParameter;
if (SelfParam <> nil) then begin
// TODO: only valid, as long as context is valid, because if context is freed, then self is lost too
ADbgValue := SelfParam.MemberByName[AName];
assert(ADbgValue <> nil, 'FindSymbol: SelfParam.MemberByName[AName]');
if ADbgValue <> nil then
ADbgValue.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FlastResult, 'FindSymbol'){$ENDIF};
end
else debugln(['TDbgDwarfInfoAddressContext.FindSymbol XXXXXXXXXXXXX no self']);
;
if ADbgValue = nil then begin // Todo: abort the searh /SetError
ADbgValue := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
end;
InfoEntry.ReleaseReference;
InfoEntryInheritance.ReleaseReference;
Result := True;
exit;
end;
end;
if not( (InfoEntryInheritance <> nil) and
(InfoEntryInheritance.ReadReference(DW_AT_type, FwdInfoPtr, FwdCompUint)) )
then
break;
InfoEntry.ReleaseReference;
InfoEntry := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
InfoEntryInheritance.ReleaseReference;
DebugLn(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier PARENT ', dbgs(InfoEntry, FwdCompUint) ]);
end;
InfoEntry.ReleaseReference;
Result := ADbgValue <> nil;
end;
function TFpDwarfInfoAddressContext.FindLocalSymbol(const AName: String; PNameUpper,
PNameLower: PChar; InfoEntry: TDwarfInformationEntry; out ADbgValue: TFpDbgValue): Boolean;
begin
Result := False;
ADbgValue := nil;
if not InfoEntry.GoNamedChildEx(PNameUpper, PNameLower) then
exit;
if InfoEntry.IsAddressInStartScope(FAddress) and not InfoEntry.IsArtificial then begin
ADbgValue := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
TFpDwarfSymbol(ADbgValue.DbgSymbol).ParentTypeInfo := TFpDwarfSymbolValueProc(FSymbol);
end;
Result := ADbgValue <> nil;
end;
constructor TFpDwarfInfoAddressContext.Create(AThreadId, AStackFrame: Integer;
AnAddress: TDbgPtr; ASymbol: TFpDbgSymbol; ADwarf: TFpDwarfInfo);
begin
inherited Create;
AddReference;
FAddress := AnAddress;
FThreadId := AThreadId;
FStackFrame := AStackFrame;
FDwarf := ADwarf;
FSymbol := ASymbol;
FSymbol.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSymbol, 'Context to Symbol'){$ENDIF};
end;
destructor TFpDwarfInfoAddressContext.Destroy;
begin
FlastResult.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FlastResult, 'FindSymbol'){$ENDIF};
FSymbol.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSymbol, 'Context to Symbol'){$ENDIF};
inherited Destroy;
end;
function TFpDwarfInfoAddressContext.FindSymbol(const AName: String): TFpDbgValue;
var
SubRoutine: TFpDwarfSymbolValueProc; // TDbgSymbol;
CU: TDwarfCompilationUnit;
//Scope,
StartScopeIdx: Integer;
InfoEntry: TDwarfInformationEntry;
NameUpper, NameLower: String;
InfoName: PChar;
tg: Cardinal;
PNameUpper, PNameLower: PChar;
begin
Result := nil;
if (FSymbol = nil) or not(FSymbol is TFpDwarfSymbolValueProc) or (AName = '') then
exit;
SubRoutine := TFpDwarfSymbolValueProc(FSymbol);
NameUpper := UTF8UpperCase(AName);
NameLower := UTF8LowerCase(AName);
PNameUpper := @NameUpper[1];
PNameLower := @NameLower[1];
try
CU := SubRoutine.CompilationUnit;
InfoEntry := SubRoutine.InformationEntry.Clone;
while InfoEntry.HasValidScope do begin
//debugln(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier Searching ', dbgs(InfoEntry.FScope, CU)]);
StartScopeIdx := InfoEntry.ScopeIndex;
//if InfoEntry.Abbrev = nil then
// exit;
if not InfoEntry.IsAddressInStartScope(FAddress) // StartScope = first valid address
then begin
// CONTINUE: Search parent(s)
//InfoEntry.ScopeIndex := StartScopeIdx;
InfoEntry.GoParent;
Continue;
end;
if InfoEntry.ReadName(InfoName) and not InfoEntry.IsArtificial
then begin
if (CompareUtf8BothCase(PNameUpper, PNameLower, InfoName)) then begin
// TODO: this is a pascal sperific search order? Or not?
// If this is a type with a pointer or ref, need to find the pointer or ref.
InfoEntry.GoParent;
if InfoEntry.HasValidScope and
InfoEntry.GoNamedChildEx(PNameUpper, PNameLower)
then begin
if InfoEntry.IsAddressInStartScope(FAddress) and not InfoEntry.IsArtificial then begin
Result := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
exit;
end;
end;
InfoEntry.ScopeIndex := StartScopeIdx;
Result := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
exit;
end;
end;
tg := InfoEntry.AbbrevTag;
if (tg = DW_TAG_class_type) or (tg = DW_TAG_structure_type) then begin
if FindSymbolInStructure(AName,PNameUpper, PNameLower, InfoEntry, Result) then
exit; // TODO: check error
//InfoEntry.ScopeIndex := StartScopeIdx;
end
else
if (StartScopeIdx = SubRoutine.InformationEntry.ScopeIndex) then begin // searching in subroutine
if FindLocalSymbol(AName,PNameUpper, PNameLower, InfoEntry, Result) then
exit; // TODO: check error
//InfoEntry.ScopeIndex := StartScopeIdx;
end
// TODO: nested subroutine
else
if InfoEntry.GoNamedChildEx(PNameUpper, PNameLower) then begin
if InfoEntry.IsAddressInStartScope(FAddress) and not InfoEntry.IsArtificial then begin
Result := SymbolToValue(TFpDwarfSymbol.CreateSubClass(AName, InfoEntry));
exit;
end;
end;
// Search parent(s)
InfoEntry.ScopeIndex := StartScopeIdx;
InfoEntry.GoParent;
end;
FindExportedSymbolInUnits(AName, PNameUpper, PNameLower, CU, Result);
finally
if (Result = nil) or (InfoEntry = nil)
then DebugLn(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier NOT found Name=', AName])
else DebugLn(FPDBG_DWARF_SEARCH, ['TDbgDwarf.FindIdentifier(',AName,') found Scope=', TFpDwarfSymbol(Result.DbgSymbol).InformationEntry.ScopeDebugText, ' ResultSymbol=', DbgSName(Result.DbgSymbol), ' ', Result.DbgSymbol.Name, ' in ', TFpDwarfSymbol(Result.DbgSymbol).CompilationUnit.FileName]);
ReleaseRefAndNil(InfoEntry);
FlastResult.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FlastResult, 'FindSymbol'){$ENDIF};
FlastResult := Result;
assert((Result = nil) or (Result is TFpDwarfValueBase), 'TDbgDwarfInfoAddressContext.FindSymbol: (Result = nil) or (Result is TFpDwarfValueBase)');
ApplyContext(Result);
end;
end;
{ TFpDwarfValueTypeDefinition }
function TFpDwarfValueTypeDefinition.GetKind: TDbgSymbolKind;
begin
Result := skNone;
end;
function TFpDwarfValueTypeDefinition.GetDbgSymbol: TFpDbgSymbol;
begin
Result := FSymbol;
end;
constructor TFpDwarfValueTypeDefinition.Create(ASymbol: TFpDbgSymbol);
begin
inherited Create;
FSymbol := ASymbol;
FSymbol.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSymbol, 'TFpDwarfValueTypeDefinition'){$ENDIF};
end;
destructor TFpDwarfValueTypeDefinition.Destroy;
begin
inherited Destroy;
FSymbol.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSymbol, 'TFpDwarfValueTypeDefinition'){$ENDIF};
end;
function TFpDwarfValueTypeDefinition.GetTypeCastedValue(ADataVal: TFpDbgValue): TFpDbgValue;
begin
Result := FSymbol.TypeCastValue(ADataVal);
assert((Result = nil) or (Result is TFpDwarfValue), 'TFpDwarfValueTypeDefinition.GetTypeCastedValue: (Result = nil) or (Result is TFpDwarfValue)');
if (Result <> nil) and (TFpDwarfValue(Result).FContext = nil) then
TFpDwarfValue(Result).FContext := FContext;
end;
{ TFpDwarfValue }
function TFpDwarfValue.MemManager: TFpDbgMemManager;
begin
Result := nil;
if FContext <> nil then
Result := FContext.MemManager;
if Result = nil then begin
// Either a typecast, or a member gotten from a typecast,...
assert((FOwner <> nil) and (FOwner.CompilationUnit <> nil) and (FOwner.CompilationUnit.Owner <> nil), 'TDbgDwarfSymbolValue.MemManager');
Result := FOwner.CompilationUnit.Owner.MemManager;
end;
end;
function TFpDwarfValue.GetDataAddressCache(AIndex: Integer): TFpDbgMemLocation;
begin
if AIndex < Length(FDataAddressCache) then
Result := FDataAddressCache[AIndex]
else
Result := UnInitializedLoc;
end;
function TFpDwarfValue.AddressSize: Byte;
begin
assert((FOwner <> nil) and (FOwner.CompilationUnit <> nil), 'TDbgDwarfSymbolValue.AddressSize');
Result := FOwner.CompilationUnit.AddressSize;
end;
procedure TFpDwarfValue.SetDataAddressCache(AIndex: Integer; AValue: TFpDbgMemLocation);
var
i, j: Integer;
begin
i := length(FDataAddressCache);
if AIndex >= i then begin
SetLength(FDataAddressCache, AIndex + 1 + 8);
// todo: Fillbyte 0
for j := i to Length(FDataAddressCache) - 1 do
FDataAddressCache[j] := UnInitializedLoc;
end;
FDataAddressCache[AIndex] := AValue;
end;
procedure TFpDwarfValue.SetStructureValue(AValue: TFpDwarfValue);
begin
if FStructureValue <> nil then
Reset;
if FStructureValue = AValue then
exit;
if CircleBackRefsActive and (FStructureValue <> nil) then
FStructureValue.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FStructureValue, 'TDbgDwarfSymbolValue'){$ENDIF};
FStructureValue := AValue;
if CircleBackRefsActive and (FStructureValue <> nil) then
FStructureValue.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FStructureValue, 'TDbgDwarfSymbolValue'){$ENDIF};
end;
function TFpDwarfValue.GetLastError: TFpError;
begin
Result := FLastError;
end;
function TFpDwarfValue.DataAddr: TFpDbgMemLocation;
begin
// GetDwarfDataAddress(???); What about FTypeCastSourceValue.AsCardinal ?
if FValueSymbol <> nil then begin
//FValueSymbol.GetValueAddress(Self, Result);
FValueSymbol.GetValueDataAddress(Self, Result, FOwner);
if IsError(FValueSymbol.LastError) then
FLastError := FValueSymbol.LastError;
end
else
if HasTypeCastInfo then begin
Result := FTypeCastSourceValue.Address;
if IsError(FTypeCastSourceValue.LastError) then
FLastError := FTypeCastSourceValue.LastError;
if IsReadableLoc(Result) then begin
if not FTypeCastTargetType.GetDataAddress(Self, Result, FOwner, 1) then
Result := InvalidLoc;
if IsError(FTypeCastTargetType.LastError) then
FLastError := FTypeCastTargetType.LastError;
end;
end
else
Result := InvalidLoc;
end;
function TFpDwarfValue.OrdOrDataAddr: TFpDbgMemLocation;
begin
if HasTypeCastInfo and (svfOrdinal in FTypeCastSourceValue.FieldFlags) then
Result := ConstLoc(FTypeCastSourceValue.AsCardinal)
else
Result := DataAddr;
end;
function TFpDwarfValue.GetDwarfDataAddress(out AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType): Boolean;
var
fields: TFpDbgValueFieldFlags;
begin
if FValueSymbol <> nil then begin
Assert(FValueSymbol is TFpDwarfSymbolValue, 'TDbgDwarfSymbolValue.GetDwarfDataAddress FValueSymbol');
Assert(TypeInfo is TFpDwarfSymbolType, 'TDbgDwarfSymbolValue.GetDwarfDataAddress TypeInfo');
Assert(not HasTypeCastInfo, 'TDbgDwarfSymbolValue.GetDwarfDataAddress not HasTypeCastInfo');
Result := FValueSymbol.GetValueDataAddress(Self, AnAddress, ATargetType);
if IsError(FValueSymbol.LastError) then
FLastError := FValueSymbol.LastError;
end
else
begin
// TODO: cache own address
// try typecast
Result := HasTypeCastInfo;
if not Result then
exit;
fields := FTypeCastSourceValue.FieldFlags;
AnAddress := InvalidLoc;
if svfOrdinal in fields then
AnAddress := ConstLoc(FTypeCastSourceValue.AsCardinal)
else
if svfAddress in fields then
AnAddress := FTypeCastSourceValue.Address;
Result := IsReadableLoc(AnAddress);
if not Result then
exit;
Result := FTypeCastTargetType.GetDataAddress(Self, AnAddress, ATargetType, 1);
if IsError(FTypeCastTargetType.LastError) then
FLastError := FTypeCastTargetType.LastError;
end;
end;
function TFpDwarfValue.GetStructureDwarfDataAddress(out AnAddress: TFpDbgMemLocation;
ATargetType: TFpDwarfSymbolType): Boolean;
begin
AnAddress := InvalidLoc;
Result := StructureValue <> nil;
if Result then
Result := StructureValue.GetDwarfDataAddress(AnAddress, ATargetType);
end;
function TFpDwarfValue.HasDwarfDataAddress: Boolean;
begin
if FValueSymbol <> nil then begin
Assert(FValueSymbol is TFpDwarfSymbolValue, 'TDbgDwarfSymbolValue.GetDwarfDataAddress FValueSymbol');
Assert(TypeInfo is TFpDwarfSymbolType, 'TDbgDwarfSymbolValue.GetDwarfDataAddress TypeInfo');
Assert(not HasTypeCastInfo, 'TDbgDwarfSymbolValue.GetDwarfDataAddress not HasTypeCastInfo');
Result := FValueSymbol.HasAddress;
end
else
begin
// try typecast
Result := HasTypeCastInfo;
if not Result then
exit;
Result := FTypeCastSourceValue.FieldFlags * [svfAddress, svfOrdinal] <> [];
end;
end;
procedure TFpDwarfValue.Reset;
begin
FDataAddressCache := nil;
FLastError := NoError;
end;
function TFpDwarfValue.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
if FValueSymbol <> nil then begin
if FValueSymbol.HasAddress then Result := Result + [svfAddress];
end
else
if HasTypeCastInfo then begin
Result := Result + FTypeCastSourceValue.FieldFlags * [svfAddress];
end;
end;
function TFpDwarfValue.HasTypeCastInfo: Boolean;
begin
Result := (FTypeCastTargetType <> nil) and (FTypeCastSourceValue <> nil);
end;
function TFpDwarfValue.IsValidTypeCast: Boolean;
begin
Result := False;
end;
procedure TFpDwarfValue.DoReferenceAdded;
begin
inherited DoReferenceAdded;
DoPlainReferenceAdded;
end;
procedure TFpDwarfValue.DoReferenceReleased;
begin
inherited DoReferenceReleased;
DoPlainReferenceReleased;
end;
procedure TFpDwarfValue.CircleBackRefActiveChanged(NewActive: Boolean);
begin
inherited CircleBackRefActiveChanged(NewActive);
if NewActive then;
if CircleBackRefsActive then begin
if FValueSymbol <> nil then
FValueSymbol.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FValueSymbol, 'TDbgDwarfSymbolValue'){$ENDIF};
if FStructureValue <> nil then
FStructureValue.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FStructureValue, 'TDbgDwarfSymbolValue'){$ENDIF};
end
else begin
if FValueSymbol <> nil then
FValueSymbol.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FValueSymbol, 'TDbgDwarfSymbolValue'){$ENDIF};
if FStructureValue <> nil then
FStructureValue.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FStructureValue, 'TDbgDwarfSymbolValue'){$ENDIF};
end;
end;
procedure TFpDwarfValue.SetLastMember(ALastMember: TFpDwarfValue);
begin
if FLastMember <> nil then
FLastMember.ReleaseCirclularReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FLastMember, 'TDbgDwarfSymbolValue'){$ENDIF};
FLastMember := ALastMember;
if (FLastMember <> nil) then begin
FLastMember.SetStructureValue(Self);
FLastMember.AddCirclularReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FLastMember, 'TDbgDwarfSymbolValue'){$ENDIF};
if (FLastMember.FContext = nil) then
FLastMember.FContext := FContext;
end;
end;
function TFpDwarfValue.GetKind: TDbgSymbolKind;
begin
if FValueSymbol <> nil then
Result := FValueSymbol.Kind
else
if HasTypeCastInfo then
Result := FTypeCastTargetType.Kind
else
Result := inherited GetKind;
end;
function TFpDwarfValue.GetAddress: TFpDbgMemLocation;
begin
if FValueSymbol <> nil then
FValueSymbol.GetValueAddress(Self, Result)
else
if HasTypeCastInfo then
Result := FTypeCastSourceValue.Address
else
Result := inherited GetAddress;
end;
function TFpDwarfValue.OrdOrAddress: TFpDbgMemLocation;
begin
if HasTypeCastInfo and (svfOrdinal in FTypeCastSourceValue.FieldFlags) then
Result := ConstLoc(FTypeCastSourceValue.AsCardinal)
else
Result := Address;
end;
function TFpDwarfValue.GetMemberCount: Integer;
begin
if FValueSymbol <> nil then
Result := FValueSymbol.MemberCount
else
Result := inherited GetMemberCount;
end;
function TFpDwarfValue.GetMemberByName(AIndex: String): TFpDbgValue;
var
m: TFpDbgSymbol;
begin
Result := nil;
if FValueSymbol <> nil then begin
m := FValueSymbol.MemberByName[AIndex];
if m <> nil then
Result := m.Value;
end;
SetLastMember(TFpDwarfValue(Result));
end;
function TFpDwarfValue.GetMember(AIndex: Int64): TFpDbgValue;
var
m: TFpDbgSymbol;
begin
Result := nil;
if FValueSymbol <> nil then begin
m := FValueSymbol.Member[AIndex];
if m <> nil then
Result := m.Value;
end;
SetLastMember(TFpDwarfValue(Result));
end;
function TFpDwarfValue.GetDbgSymbol: TFpDbgSymbol;
begin
Result := FValueSymbol;
end;
function TFpDwarfValue.GetTypeInfo: TFpDbgSymbol;
begin
if HasTypeCastInfo then
Result := FTypeCastTargetType
else
Result := inherited GetTypeInfo;
end;
function TFpDwarfValue.GetContextTypeInfo: TFpDbgSymbol;
begin
if (FValueSymbol <> nil) and (FValueSymbol.ParentTypeInfo <> nil) then
Result := FValueSymbol.ParentTypeInfo
else
Result := nil; // internal error
end;
constructor TFpDwarfValue.Create(AOwner: TFpDwarfSymbolType);
begin
FOwner := AOwner;
inherited Create;
end;
destructor TFpDwarfValue.Destroy;
begin
FTypeCastTargetType.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastTargetType, ClassName+'.FTypeCastTargetType'){$ENDIF};
FTypeCastSourceValue.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastSourceValue, ClassName+'.FTypeCastSourceValue'){$ENDIF};
SetLastMember(nil);
inherited Destroy;
end;
procedure TFpDwarfValue.SetValueSymbol(AValueSymbol: TFpDwarfSymbolValue);
begin
if FValueSymbol = AValueSymbol then
exit;
if CircleBackRefsActive and (FValueSymbol <> nil) then
FValueSymbol.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FValueSymbol, 'TDbgDwarfSymbolValue'){$ENDIF};
FValueSymbol := AValueSymbol;
if CircleBackRefsActive and (FValueSymbol <> nil) then
FValueSymbol.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FValueSymbol, 'TDbgDwarfSymbolValue'){$ENDIF};
end;
function TFpDwarfValue.SetTypeCastInfo(AStructure: TFpDwarfSymbolType;
ASource: TFpDbgValue): Boolean;
begin
Reset;
AStructure.ResetValueBounds;
if FTypeCastSourceValue <> ASource then begin
if FTypeCastSourceValue <> nil then
FTypeCastSourceValue.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastSourceValue, ClassName+'.FTypeCastSourceValue'){$ENDIF};
FTypeCastSourceValue := ASource;
if FTypeCastSourceValue <> nil then
FTypeCastSourceValue.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastSourceValue, ClassName+'.FTypeCastSourceValue'){$ENDIF};
end;
if FTypeCastTargetType <> AStructure then begin
if FTypeCastTargetType <> nil then
FTypeCastTargetType.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastTargetType, ClassName+'.FTypeCastTargetType'){$ENDIF};
FTypeCastTargetType := AStructure;
if FTypeCastTargetType <> nil then
FTypeCastTargetType.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FTypeCastTargetType, ClassName+'.FTypeCastTargetType'){$ENDIF};
end;
Result := IsValidTypeCast;
end;
{ TFpDwarfValueSized }
function TFpDwarfValueSized.CanUseTypeCastAddress: Boolean;
begin
Result := True;
if (FTypeCastSourceValue.FieldFlags * [svfAddress, svfSize, svfSizeOfPointer] = [svfAddress]) then
exit
else
if (FTypeCastSourceValue.FieldFlags * [svfAddress, svfSize] = [svfAddress, svfSize]) and
(FTypeCastSourceValue.Size = FSize) and (FSize > 0)
then
exit;
if (FTypeCastSourceValue.FieldFlags * [svfAddress, svfSizeOfPointer] = [svfAddress, svfSizeOfPointer]) and
not ( (FTypeCastTargetType.Kind = skPointer) //or
//(FSize = AddressSize xxxxxxx)
)
then
exit;
Result := False;
end;
function TFpDwarfValueSized.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfSize];
end;
function TFpDwarfValueSized.GetSize: Integer;
begin
Result := FSize;
end;
constructor TFpDwarfValueSized.Create(AOwner: TFpDwarfSymbolType; ASize: Integer);
begin
inherited Create(AOwner);
FSize := ASize;
end;
{ TFpDwarfValueNumeric }
procedure TFpDwarfValueNumeric.Reset;
begin
inherited Reset;
FEvaluated := [];
end;
function TFpDwarfValueNumeric.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfOrdinal];
end;
function TFpDwarfValueNumeric.IsValidTypeCast: Boolean;
begin
Result := HasTypeCastInfo;
If not Result then
exit;
if (svfOrdinal in FTypeCastSourceValue.FieldFlags) or CanUseTypeCastAddress then
exit;
Result := False;
end;
constructor TFpDwarfValueNumeric.Create(AOwner: TFpDwarfSymbolType; ASize: Integer);
begin
inherited Create(AOwner, ASize);
FEvaluated := [];
end;
{ TFpDwarfValueInteger }
function TFpDwarfValueInteger.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfInteger];
end;
function TFpDwarfValueInteger.GetAsCardinal: QWord;
begin
Result := QWord(GetAsInteger); // include sign extension
end;
function TFpDwarfValueInteger.GetAsInteger: Int64;
begin
if doneInt in FEvaluated then begin
Result := FIntValue;
exit;
end;
Include(FEvaluated, doneInt);
if (FSize <= 0) or (FSize > SizeOf(Result)) then
Result := inherited GetAsInteger
else
if not MemManager.ReadSignedInt(OrdOrDataAddr, FSize, Result) then begin
Result := 0; // TODO: error
FLastError := MemManager.LastError;
end;
FIntValue := Result;
end;
{ TDbgDwarfCardinalSymbolValue }
function TFpDwarfValueCardinal.GetAsCardinal: QWord;
begin
if doneUInt in FEvaluated then begin
Result := FValue;
exit;
end;
Include(FEvaluated, doneUInt);
if (FSize <= 0) or (FSize > SizeOf(Result)) then
Result := inherited GetAsCardinal
else
if not MemManager.ReadUnsignedInt(OrdOrDataAddr, FSize, Result) then begin
Result := 0; // TODO: error
FLastError := MemManager.LastError;
end;
FValue := Result;
end;
function TFpDwarfValueCardinal.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfCardinal];
end;
{ TFpDwarfValueFloat }
function TFpDwarfValueFloat.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfFloat] - [svfOrdinal];
end;
function TFpDwarfValueFloat.GetAsFloat: Extended;
begin
if doneFloat in FEvaluated then begin
Result := FValue;
exit;
end;
Include(FEvaluated, doneUInt);
if (FSize <= 0) or (FSize > SizeOf(Result)) then
Result := inherited GetAsCardinal
else
if not MemManager.ReadFloat(OrdOrDataAddr, FSize, Result) then begin
Result := 0; // TODO: error
FLastError := MemManager.LastError;
end;
FValue := Result;
end;
{ TFpDwarfValueBoolean }
function TFpDwarfValueBoolean.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfBoolean];
end;
function TFpDwarfValueBoolean.GetAsBool: Boolean;
begin
Result := QWord(GetAsCardinal) <> 0;
end;
{ TFpDwarfValueChar }
function TFpDwarfValueChar.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
case FSize of
1: Result := Result + [svfString];
2: Result := Result + [svfWideString];
end;
end;
function TFpDwarfValueChar.GetAsString: AnsiString;
begin
// Can typecast, because of FSize = 1, GetAsCardinal only read one byte
if FSize = 2 then
Result := GetAsWideString // temporary workaround for WideChar
else
if FSize <> 1 then
Result := inherited GetAsString
else
Result := SysToUTF8(char(byte(GetAsCardinal)));
end;
function TFpDwarfValueChar.GetAsWideString: WideString;
begin
if FSize > 2 then
Result := inherited GetAsWideString
else
Result := WideChar(Word(GetAsCardinal));
end;
{ TFpDwarfValuePointer }
function TFpDwarfValuePointer.GetAsCardinal: QWord;
var
a: TFpDbgMemLocation;
begin
a := GetDataAddress;
if IsTargetAddr(a) then
Result := LocToAddr(a)
else
Result := 0;
end;
function TFpDwarfValuePointer.GetFieldFlags: TFpDbgValueFieldFlags;
var
t: TFpDbgSymbol;
begin
Result := inherited GetFieldFlags;
//TODO: svfDataAddress should depend on (hidden) Pointer or Ref in the TypeInfo
Result := Result + [svfCardinal, svfOrdinal, svfSizeOfPointer, svfDataAddress] - [svfSize]; // data address
t := TypeInfo;
if (t <> nil) then t := t.TypeInfo;
if (t <> nil) and (t.Kind = skChar) and IsReadableMem(DataAddress) then // pchar
Result := Result + [svfString]; // data address
end;
function TFpDwarfValuePointer.GetDataAddress: TFpDbgMemLocation;
begin
if doneAddr in FEvaluated then begin
Result := FPointetToAddr;
exit;
end;
Include(FEvaluated, doneAddr);
if (FSize <= 0) then
Result := InvalidLoc
else
begin
if not MemManager.ReadAddress(OrdOrDataAddr, FSize, Result) then
FLastError := MemManager.LastError;
end;
FPointetToAddr := Result;
end;
function TFpDwarfValuePointer.GetAsString: AnsiString;
var
t: TFpDbgSymbol;
i: Integer;
begin
t := TypeInfo;
if (t <> nil) then t := t.TypeInfo;
if t.Size = 2 then
Result := GetAsWideString
else
if (MemManager <> nil) and (t <> nil) and (t.Kind = skChar) and IsReadableMem(DataAddress) then begin // pchar
SetLength(Result, 2000);
i := 2000;
while (i > 0) and (not MemManager.ReadMemory(DataAddress, i, @Result[1])) do
i := i div 2;
SetLength(Result,i);
i := pos(#0, Result);
if i > 0 then
SetLength(Result,i-1);
end
else
Result := inherited GetAsString;
end;
function TFpDwarfValuePointer.GetAsWideString: WideString;
var
t: TFpDbgSymbol;
i: Integer;
begin
t := TypeInfo;
if (t <> nil) then t := t.TypeInfo;
// skWideChar ???
if (MemManager <> nil) and (t <> nil) and (t.Kind = skChar) and IsReadableMem(DataAddress) then begin // pchar
SetLength(Result, 2000);
i := 4000; // 2000 * 16 bit
while (i > 0) and (not MemManager.ReadMemory(DataAddress, i, @Result[1])) do
i := i div 2;
SetLength(Result, i div 2);
i := pos(#0, Result);
if i > 0 then
SetLength(Result, i-1);
end
else
Result := inherited GetAsWideString;
end;
function TFpDwarfValuePointer.GetMember(AIndex: Int64): TFpDbgValue;
var
ti: TFpDbgSymbol;
addr: TFpDbgMemLocation;
Tmp: TFpDwarfValueConstAddress;
begin
//TODO: ?? if no TypeInfo.TypeInfo;, then return TFpDwarfValueConstAddress.Create(addr); (for mem dump)
Result := nil;
ReleaseRefAndNil(FLastAddrMember);
if (TypeInfo = nil) then begin // TODO dedicanted error code
FLastError := CreateError(fpErrAnyError, ['Can not dereference an untyped pointer']);
exit;
end;
// TODO re-use last member
ti := TypeInfo.TypeInfo;
{$PUSH}{$R-}{$Q-} // TODO: check overflow
if ti <> nil then
AIndex := AIndex * ti.Size;
addr := DataAddress;
if not IsTargetAddr(addr) then begin
FLastError := CreateError(fpErrAnyError, ['Internal dereference error']);
exit;
end;
addr.Address := addr.Address + AIndex;
{$POP}
Tmp := TFpDwarfValueConstAddress.Create(addr);
if ti <> nil then begin
Result := ti.TypeCastValue(Tmp);
Tmp.ReleaseReference;
SetLastMember(TFpDwarfValue(Result));
Result.ReleaseReference;
end
else begin
Result := Tmp;
FLastAddrMember := Result;
end;
end;
destructor TFpDwarfValuePointer.Destroy;
begin
FLastAddrMember.ReleaseReference;
inherited Destroy;
end;
{ TFpDwarfValueEnum }
procedure TFpDwarfValueEnum.InitMemberIndex;
var
v: QWord;
i: Integer;
begin
// TODO: if TypeInfo is a subrange, check against the bounds, then bypass it, and scan all members (avoid subrange scanning members)
if FMemberValueDone then exit;
// FTypeCastTargetType (if not nil) must be same as FOwner. It may have wrappers like declaration.
v := GetAsCardinal;
i := FOwner.MemberCount - 1;
while i >= 0 do begin
if FOwner.Member[i].OrdinalValue = v then break;
dec(i);
end;
FMemberIndex := i;
FMemberValueDone := True;
end;
procedure TFpDwarfValueEnum.Reset;
begin
inherited Reset;
FMemberValueDone := False;
end;
function TFpDwarfValueEnum.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfOrdinal, svfMembers, svfIdentifier];
end;
function TFpDwarfValueEnum.GetAsCardinal: QWord;
begin
if doneUInt in FEvaluated then begin
Result := FValue;
exit;
end;
Include(FEvaluated, doneUInt);
if (FSize <= 0) or (FSize > SizeOf(Result)) then
Result := inherited GetAsCardinal
else
if not MemManager.ReadEnum(OrdOrDataAddr, FSize, Result) then begin
FLastError := MemManager.LastError;
Result := 0; // TODO: error
end;
FValue := Result;
end;
function TFpDwarfValueEnum.GetAsString: AnsiString;
begin
InitMemberIndex;
if FMemberIndex >= 0 then
Result := FOwner.Member[FMemberIndex].Name
else
Result := '';
end;
function TFpDwarfValueEnum.GetMemberCount: Integer;
begin
InitMemberIndex;
if FMemberIndex < 0 then
Result := 0
else
Result := 1;
end;
function TFpDwarfValueEnum.GetMember(AIndex: Int64): TFpDbgValue;
begin
InitMemberIndex;
if (FMemberIndex >= 0) and (AIndex = 0) then
Result := FOwner.Member[FMemberIndex].Value
else
Result := nil;
end;
{ TFpDwarfValueEnumMember }
function TFpDwarfValueEnumMember.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfOrdinal, svfIdentifier];
end;
function TFpDwarfValueEnumMember.GetAsCardinal: QWord;
begin
Result := FOwnerVal.OrdinalValue;
end;
function TFpDwarfValueEnumMember.GetAsString: AnsiString;
begin
Result := FOwnerVal.Name;
end;
function TFpDwarfValueEnumMember.IsValidTypeCast: Boolean;
begin
assert(False, 'TDbgDwarfEnumMemberSymbolValue.IsValidTypeCast can not be returned for typecast');
Result := False;
end;
constructor TFpDwarfValueEnumMember.Create(AOwner: TFpDwarfSymbolValue);
begin
FOwnerVal := AOwner;
inherited Create(nil);
end;
{ TFpDwarfValueConstNumber }
procedure TFpDwarfValueConstNumber.Update(AValue: QWord; ASigned: Boolean);
begin
Signed := ASigned;
Value := AValue;
end;
{ TFpDwarfValueSet }
procedure TFpDwarfValueSet.InitMap;
const
BitCount: array[0..15] of byte = (0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
var
i, i2, v, MemIdx, Bit, Cnt: Integer;
t: TFpDbgSymbol;
begin
if (length(FMem) > 0) or (FSize <= 0) then
exit;
t := TypeInfo;
if t = nil then exit;
t := t.TypeInfo;
if t = nil then exit;
if not MemManager.ReadSet(DataAddr, FSize, FMem) then begin
FLastError := MemManager.LastError;
exit; // TODO: error
end;
Cnt := 0;
for i := 0 to FSize - 1 do
Cnt := Cnt + (BitCount[FMem[i] and 15]) + (BitCount[(FMem[i] div 16) and 15]);
FMemberCount := Cnt;
if (Cnt = 0) then exit;
SetLength(FMemberMap, Cnt);
if (t.Kind = skEnum) then begin
i2 := 0;
for i := 0 to t.MemberCount - 1 do
begin
v := t.Member[i].OrdinalValue;
MemIdx := v shr 3;
Bit := 1 shl (v and 7);
if (FMem[MemIdx] and Bit) <> 0 then begin
assert(i2 < Cnt, 'TDbgDwarfSetSymbolValue.InitMap too many members');
if i2 = Cnt then break;
FMemberMap[i2] := i;
inc(i2);
end;
end;
if i2 < Cnt then begin
FMemberCount := i2;
debugln(FPDBG_DWARF_DATA_WARNINGS, ['TDbgDwarfSetSymbolValue.InitMap not enough members']);
end;
end
else begin
i2 := 0;
MemIdx := 0;
Bit := 1;
v := t.OrdLowBound;
for i := v to t.OrdHighBound do
begin
if (FMem[MemIdx] and Bit) <> 0 then begin
assert(i2 < Cnt, 'TDbgDwarfSetSymbolValue.InitMap too many members');
if i2 = Cnt then break;
FMemberMap[i2] := i - v; // offset from low-bound
inc(i2);
end;
if Bit = 128 then begin
Bit := 1;
inc(MemIdx);
end
else
Bit := Bit shl 1;
end;
if i2 < Cnt then begin
FMemberCount := i2;
debugln(FPDBG_DWARF_DATA_WARNINGS, ['TDbgDwarfSetSymbolValue.InitMap not enough members']);
end;
end;
end;
procedure TFpDwarfValueSet.Reset;
begin
inherited Reset;
SetLength(FMem, 0);
end;
function TFpDwarfValueSet.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfMembers];
if FSize <= 8 then
Result := Result + [svfOrdinal];
end;
function TFpDwarfValueSet.GetMemberCount: Integer;
begin
InitMap;
Result := FMemberCount;
end;
function TFpDwarfValueSet.GetMember(AIndex: Int64): TFpDbgValue;
var
t: TFpDbgSymbol;
begin
Result := nil;
InitMap;
t := TypeInfo;
if t = nil then exit;
t := t.TypeInfo;
if t = nil then exit;
assert(t is TFpDwarfSymbolType, 'TDbgDwarfSetSymbolValue.GetMember t');
if t.Kind = skEnum then begin
Result := t.Member[FMemberMap[AIndex]].Value;
end
else begin
if (FNumValue = nil) or (FNumValue.RefCount > 1) then // refcount 1 by FTypedNumValue
FNumValue := TFpDwarfValueConstNumber.Create(FMemberMap[AIndex] + t.OrdLowBound, t.Kind = skInteger)
else
begin
FNumValue.Update(FMemberMap[AIndex] + t.OrdLowBound, t.Kind = skInteger);
FNumValue.AddReference;
end;
if (FTypedNumValue = nil) or (FTypedNumValue.RefCount > 1) then begin
FTypedNumValue.ReleaseReference;
FTypedNumValue := t.TypeCastValue(FNumValue)
end
else
TFpDwarfValue(FTypedNumValue).SetTypeCastInfo(TFpDwarfSymbolType(t), FNumValue); // update
FNumValue.ReleaseReference;
Assert((FTypedNumValue <> nil) and (TFpDwarfValue(FTypedNumValue).IsValidTypeCast), 'TDbgDwarfSetSymbolValue.GetMember FTypedNumValue');
Assert((FNumValue <> nil) and (FNumValue.RefCount > 0), 'TDbgDwarfSetSymbolValue.GetMember FNumValue');
Result := FTypedNumValue;
end;
end;
function TFpDwarfValueSet.GetAsCardinal: QWord;
begin
Result := 0;
if (FSize <= SizeOf(Result)) and (length(FMem) > 0) then
move(FMem[0], Result, FSize);
end;
function TFpDwarfValueSet.IsValidTypeCast: Boolean;
var
f: TFpDbgValueFieldFlags;
begin
Result := HasTypeCastInfo;
If not Result then
exit;
assert(FTypeCastTargetType.Kind = skSet, 'TFpDwarfValueSet.IsValidTypeCast: FTypeCastTargetType.Kind = skSet');
if (FTypeCastSourceValue.TypeInfo = FTypeCastTargetType)
then
exit; // pointer deref
f := FTypeCastSourceValue.FieldFlags;
if (f * [svfAddress, svfSize, svfSizeOfPointer] = [svfAddress]) then
exit;
if (f * [svfAddress, svfSize] = [svfAddress, svfSize]) and
(FTypeCastSourceValue.Size = FTypeCastTargetType.Size)
then
exit;
Result := False;
end;
destructor TFpDwarfValueSet.Destroy;
begin
FTypedNumValue.ReleaseReference;
inherited Destroy;
end;
{ TFpDwarfValueStruct }
procedure TFpDwarfValueStruct.Reset;
begin
inherited Reset;
FDataAddressDone := False;
end;
function TFpDwarfValueStruct.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfMembers];
//TODO: svfDataAddress should depend on (hidden) Pointer or Ref in the TypeInfo
if Kind in [skClass] then begin
Result := Result + [svfOrdinal, svfDataAddress, svfDataSize]; // svfDataSize
if (FValueSymbol <> nil) and FValueSymbol.HasAddress then
Result := Result + [svfSizeOfPointer];
end
else begin
Result := Result + [svfSize];
end;
end;
function TFpDwarfValueStruct.GetAsCardinal: QWord;
begin
Result := QWord(LocToAddrOrNil(DataAddress));
end;
function TFpDwarfValueStruct.GetDataAddress: TFpDbgMemLocation;
var
t: TFpDbgMemLocation;
begin
if FValueSymbol <> nil then begin
if not FDataAddressDone then begin
FDataAddress := InvalidLoc;
FValueSymbol.GetValueAddress(Self, t);
assert(SizeOf(FDataAddress) >= AddressSize, 'TDbgDwarfStructSymbolValue.GetDataAddress');
if (MemManager <> nil) then begin
FDataAddress := MemManager.ReadAddress(t, AddressSize);
if not IsValidLoc(FDataAddress) then
FLastError := MemManager.LastError;
end;
FDataAddressDone := True;
end;
Result := FDataAddress;
end
else
Result := inherited GetDataAddress;
end;
function TFpDwarfValueStruct.GetDataSize: Integer;
begin
Assert((FValueSymbol = nil) or (FValueSymbol.TypeInfo is TFpDwarfSymbol));
if (FValueSymbol <> nil) and (FValueSymbol.TypeInfo <> nil) then
if FValueSymbol.TypeInfo.Kind = skClass then
Result := TFpDwarfSymbol(FValueSymbol.TypeInfo).DataSize
else
Result := FValueSymbol.TypeInfo.Size
else
Result := -1;
end;
function TFpDwarfValueStruct.GetSize: Integer;
begin
if (Kind <> skClass) and (FValueSymbol <> nil) and (FValueSymbol.TypeInfo <> nil) then
Result := FValueSymbol.TypeInfo.Size
else
Result := -1;
end;
{ TFpDwarfValueStructTypeCast }
procedure TFpDwarfValueStructTypeCast.Reset;
begin
inherited Reset;
FDataAddressDone := False;
end;
function TFpDwarfValueStructTypeCast.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfMembers];
if kind = skClass then // todo detect hidden pointer
Result := Result + [svfDataSize]
else
Result := Result + [svfSize];
//TODO: svfDataAddress should depend on (hidden) Pointer or Ref in the TypeInfo
if Kind in [skClass] then
Result := Result + [svfOrdinal, svfDataAddress, svfSizeOfPointer]; // svfDataSize
end;
function TFpDwarfValueStructTypeCast.GetKind: TDbgSymbolKind;
begin
if HasTypeCastInfo then
Result := FTypeCastTargetType.Kind
else
Result := inherited GetKind;
end;
function TFpDwarfValueStructTypeCast.GetAsCardinal: QWord;
begin
Result := QWord(LocToAddrOrNil(DataAddress));
end;
function TFpDwarfValueStructTypeCast.GetSize: Integer;
begin
if (Kind <> skClass) and (FTypeCastTargetType <> nil) then
Result := FTypeCastTargetType.Size
else
Result := -1;
end;
function TFpDwarfValueStructTypeCast.GetDataSize: Integer;
begin
Assert((FTypeCastTargetType = nil) or (FTypeCastTargetType is TFpDwarfSymbol));
if FTypeCastTargetType <> nil then
if FTypeCastTargetType.Kind = skClass then
Result := TFpDwarfSymbol(FTypeCastTargetType).DataSize
else
Result := FTypeCastTargetType.Size
else
Result := -1;
end;
function TFpDwarfValueStructTypeCast.GetDataAddress: TFpDbgMemLocation;
var
fields: TFpDbgValueFieldFlags;
t: TFpDbgMemLocation;
begin
if HasTypeCastInfo then begin
if not FDataAddressDone then begin
// TODO: wrong for records // use GetDwarfDataAddress
fields := FTypeCastSourceValue.FieldFlags;
if svfOrdinal in fields then
FDataAddress := TargetLoc(TDbgPtr(FTypeCastSourceValue.AsCardinal))
else
if svfAddress in fields then begin
FDataAddress := InvalidLoc;
t := FTypeCastSourceValue.Address;
assert(SizeOf(FDataAddress) >= AddressSize, 'TDbgDwarfStructSymbolValue.GetDataAddress');
if (MemManager <> nil) then begin
FDataAddress := MemManager.ReadAddress(t, AddressSize);
if not IsValidLoc(FDataAddress) then
FLastError := MemManager.LastError;
end;
end;
FDataAddressDone := True;
end;
Result := FDataAddress;
end
else
Result := inherited GetDataAddress;
end;
function TFpDwarfValueStructTypeCast.IsValidTypeCast: Boolean;
var
f: TFpDbgValueFieldFlags;
begin
Result := HasTypeCastInfo;
if not Result then
exit;
if FTypeCastTargetType.Kind = skClass then begin
f := FTypeCastSourceValue.FieldFlags;
Result := (svfOrdinal in f); // ordinal is prefered in GetDataAddress
if Result then
exit;
Result := (svfAddress in f) and
( ( not(svfSize in f) ) or // either svfSizeOfPointer or a void type, e.g. pointer(1)^
( (svfSize in f) and (FTypeCastSourceValue.Size = AddressSize) )
);
end
else begin
f := FTypeCastSourceValue.FieldFlags;
if (f * [{svfOrdinal, }svfAddress] = [svfAddress]) then begin
if (f * [svfSize, svfSizeOfPointer]) = [svfSize] then
Result := Result and (FTypeCastTargetType.Size = FTypeCastSourceValue.Size)
else
if (f * [svfSize, svfSizeOfPointer]) = [svfSizeOfPointer] then
Result := Result and (FTypeCastTargetType.Size = AddressSize)
else
Result := (f * [svfSize, svfSizeOfPointer]) = []; // source is a void type, e.g. pointer(1)^
end
else
Result := False;
end;
end;
destructor TFpDwarfValueStructTypeCast.Destroy;
begin
FreeAndNil(FMembers);
inherited Destroy;
end;
function TFpDwarfValueStructTypeCast.GetMemberByName(AIndex: String): TFpDbgValue;
var
tmp: TFpDbgSymbol;
begin
Result := nil;
if not HasTypeCastInfo then
exit;
tmp := FTypeCastTargetType.MemberByName[AIndex];
if (tmp <> nil) then begin
assert((tmp is TFpDwarfSymbolValue), 'TDbgDwarfStructTypeCastSymbolValue.GetMemberByName'+DbgSName(tmp));
if FMembers = nil then
FMembers := TFpDbgCircularRefCntObjList.Create;
FMembers.Add(tmp);
Result := tmp.Value;
end;
SetLastMember(TFpDwarfValue(Result));
end;
function TFpDwarfValueStructTypeCast.GetMember(AIndex: Int64): TFpDbgValue;
var
tmp: TFpDbgSymbol;
begin
Result := nil;
if not HasTypeCastInfo then
exit;
// TODO: Why store them all in list? They are hold by the type
tmp := FTypeCastTargetType.Member[AIndex];
if (tmp <> nil) then begin
assert((tmp is TFpDwarfSymbolValue), 'TDbgDwarfStructTypeCastSymbolValue.GetMemberByName'+DbgSName(tmp));
if FMembers = nil then
FMembers := TFpDbgCircularRefCntObjList.Create;
FMembers.Add(tmp);
Result := tmp.Value;
end;
SetLastMember(TFpDwarfValue(Result));
end;
function TFpDwarfValueStructTypeCast.GetMemberCount: Integer;
var
ti: TFpDbgSymbol;
begin
Result := 0;
if not HasTypeCastInfo then
exit;
Result := FTypeCastTargetType.MemberCount;
ti := FTypeCastTargetType;
//TODO: cache result
if ti.Kind in [skClass, skObject] then
while ti.TypeInfo <> nil do begin
ti := ti.TypeInfo;
Result := Result + ti.MemberCount;
end;
end;
{ TFpDwarfValueConstAddress }
procedure TFpDwarfValueConstAddress.Update(AnAddress: TFpDbgMemLocation);
begin
Address := AnAddress;
end;
{ TFpDwarfValueArray }
function TFpDwarfValueArray.GetFieldFlags: TFpDbgValueFieldFlags;
begin
Result := inherited GetFieldFlags;
Result := Result + [svfMembers];
if (TypeInfo <> nil) and (sfDynArray in TypeInfo.Flags) then
Result := Result + [svfOrdinal, svfDataAddress];
end;
function TFpDwarfValueArray.GetKind: TDbgSymbolKind;
begin
Result := skArray;
end;
function TFpDwarfValueArray.GetAsCardinal: QWord;
begin
// TODO cache
if not MemManager.ReadUnsignedInt(OrdOrAddress, AddressSize, Result) then begin
FLastError := MemManager.LastError;
Result := 0;
end;
end;
function TFpDwarfValueArray.GetDataAddress: TFpDbgMemLocation;
begin
Result := OrdOrDataAddr;
end;
function TFpDwarfValueArray.GetMember(AIndex: Int64): TFpDbgValue;
begin
Result := GetMemberEx([AIndex]);
end;
function TFpDwarfValueArray.GetMemberEx(const AIndex: array of Int64
): TFpDbgValue;
var
Addr: TFpDbgMemLocation;
i: Integer;
begin
Result := nil;
assert((FOwner is TFpDwarfSymbolTypeArray) and (FOwner.Kind = skArray));
Addr := TFpDwarfSymbolTypeArray(FOwner).GetMemberAddress(Self, AIndex);
if not IsReadableLoc(Addr) then exit;
// FAddrObj.RefCount: hold by self
i := 1;
// FAddrObj.RefCount: hold by FLastMember (ignore only, if FLastMember is not hold by others)
if (FLastMember <> nil) and (FLastMember.RefCount = 1) then
i := 2;
if (FAddrObj = nil) or (FAddrObj.RefCount > i) then begin
FAddrObj.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FAddrObj, 'TDbgDwarfArraySymbolValue'){$ENDIF};
FAddrObj := TFpDwarfValueConstAddress.Create(Addr);
{$IFDEF WITH_REFCOUNT_DEBUG}FAddrObj.DbgRenameReference(@FAddrObj, 'TDbgDwarfArraySymbolValue');{$ENDIF}
end
else begin
FAddrObj.Update(Addr);
end;
if (FLastMember = nil) or (FLastMember.RefCount > 1) then begin
SetLastMember(TFpDwarfValue(FOwner.TypeInfo.TypeCastValue(FAddrObj)));
FLastMember.ReleaseReference;
end
else begin
TFpDwarfValue(FLastMember).SetTypeCastInfo(TFpDwarfSymbolType(FOwner.TypeInfo), FAddrObj);
end;
Result := FLastMember;
end;
function TFpDwarfValueArray.GetMemberCount: Integer;
var
t, t2: TFpDbgSymbol;
Addr: TFpDbgMemLocation;
LowBound, HighBound: int64;
i: Int64;
begin
Result := 0;
t := TypeInfo;
if t.MemberCount < 1 then // IndexTypeCount;
exit;
t2 := t.Member[0]; // IndexType[0];
if not ((t2 is TFpDwarfSymbolType) and (TFpDwarfSymbolType(t2).GetValueBounds(self, LowBound, HighBound))) and
not t2.HasBounds then begin
if (sfDynArray in t.Flags) and (AsCardinal <> 0) and
GetDwarfDataAddress(Addr, TFpDwarfSymbolType(FOwner))
then begin
if not (IsReadableMem(Addr) and (LocToAddr(Addr) > 4)) then
exit;
Addr.Address := Addr.Address - AddressSize;
if MemManager.ReadSignedInt(Addr, 4, i) then begin
Result := Integer(i)+1;
exit;
end
else
FLastError := MemManager.LastError;
end;
exit;
end;
if t2.HasBounds then begin
LowBound := t2.OrdLowBound;
HighBound := t2.OrdHighBound;
if HighBound < LowBound then
exit(0); // empty array // TODO: error
// TODO: XXXXX Dynamic max limit
if HighBound - LowBound > 3000 then
HighBound := LowBound + 3000;
Result := Integer(HighBound - LowBound + 1);
end;
end;
function TFpDwarfValueArray.GetMemberCountEx(const AIndex: array of Int64
): Integer;
var
t: TFpDbgSymbol;
begin
Result := 0;
t := TypeInfo;
if length(AIndex) >= t.MemberCount then
exit;
t := t.Member[length(AIndex)];
if not t.HasBounds then
exit;
Result := t.OrdHighBound - t.OrdLowBound + 1;
end;
function TFpDwarfValueArray.GetIndexType(AIndex: Integer): TFpDbgSymbol;
begin
Result := TypeInfo.Member[AIndex];
end;
function TFpDwarfValueArray.GetIndexTypeCount: Integer;
begin
Result := TypeInfo.MemberCount;
end;
function TFpDwarfValueArray.IsValidTypeCast: Boolean;
var
f: TFpDbgValueFieldFlags;
begin
Result := HasTypeCastInfo;
If not Result then
exit;
assert(FTypeCastTargetType.Kind = skArray, 'TFpDwarfValueArray.IsValidTypeCast: FTypeCastTargetType.Kind = skArray');
//TODO: shortcut, if FTypeCastTargetType = FTypeCastSourceValue.TypeInfo ?
f := FTypeCastSourceValue.FieldFlags;
if (f * [svfAddress, svfSize, svfSizeOfPointer] = [svfAddress]) then
exit;
if sfDynArray in FTypeCastTargetType.Flags then begin
// dyn array
if (svfOrdinal in f)then
exit;
if (f * [svfAddress, svfSize] = [svfAddress, svfSize]) and
(FTypeCastSourceValue.Size = FOwner.CompilationUnit.AddressSize)
then
exit;
if (f * [svfAddress, svfSizeOfPointer] = [svfAddress, svfSizeOfPointer]) then
exit;
end
else begin
// stat array
if (f * [svfAddress, svfSize] = [svfAddress, svfSize]) and
(FTypeCastSourceValue.Size = FTypeCastTargetType.Size)
then
exit;
end;
Result := False;
end;
destructor TFpDwarfValueArray.Destroy;
begin
FAddrObj.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FAddrObj, 'TDbgDwarfArraySymbolValue'){$ENDIF};
inherited Destroy;
end;
{ TDbgDwarfIdentifier }
function TFpDwarfSymbol.GetNestedTypeInfo: TFpDwarfSymbolType;
begin
// TODO DW_AT_start_scope;
Result := FNestedTypeInfo;
if (Result <> nil) or (didtTypeRead in FDwarfReadFlags) then
exit;
include(FDwarfReadFlags, didtTypeRead);
FNestedTypeInfo := DoGetNestedTypeInfo;
Result := FNestedTypeInfo;
end;
procedure TFpDwarfSymbol.SetParentTypeInfo(AValue: TFpDwarfSymbol);
begin
if FParentTypeInfo = AValue then exit;
if (FParentTypeInfo <> nil) and CircleBackRefsActive then
FParentTypeInfo.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FParentTypeInfo, 'FParentTypeInfo'){$ENDIF};
FParentTypeInfo := AValue;
if (FParentTypeInfo <> nil) and CircleBackRefsActive then
FParentTypeInfo.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FParentTypeInfo, 'FParentTypeInfo'){$ENDIF};
end;
procedure TFpDwarfSymbol.DoReferenceAdded;
begin
inherited DoReferenceAdded;
DoPlainReferenceAdded;
end;
procedure TFpDwarfSymbol.DoReferenceReleased;
begin
inherited DoReferenceReleased;
DoPlainReferenceReleased;
end;
procedure TFpDwarfSymbol.CircleBackRefActiveChanged(ANewActive: Boolean);
begin
if (FParentTypeInfo = nil) then
exit;
if ANewActive then
FParentTypeInfo.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FParentTypeInfo, 'FParentTypeInfo'){$ENDIF}
else
FParentTypeInfo.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FParentTypeInfo, 'FParentTypeInfo'){$ENDIF};
end;
function TFpDwarfSymbol.DoGetNestedTypeInfo: TFpDwarfSymbolType;
var
FwdInfoPtr: Pointer;
FwdCompUint: TDwarfCompilationUnit;
InfoEntry: TDwarfInformationEntry;
begin // Do not access anything that may need forwardSymbol
if InformationEntry.ReadReference(DW_AT_type, FwdInfoPtr, FwdCompUint) then begin
InfoEntry := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
Result := TFpDwarfSymbolType.CreateTypeSubClass('', InfoEntry);
ReleaseRefAndNil(InfoEntry);
end
else
Result := nil;
end;
function TFpDwarfSymbol.ReadMemberVisibility(out
AMemberVisibility: TDbgSymbolMemberVisibility): Boolean;
var
Val: Integer;
begin
Result := InformationEntry.ReadValue(DW_AT_external, Val);
if Result and (Val <> 0) then begin
AMemberVisibility := svPublic;
exit;
end;
Result := InformationEntry.ReadValue(DW_AT_accessibility, Val);
if not Result then exit;
case Val of
DW_ACCESS_private: AMemberVisibility := svPrivate;
DW_ACCESS_protected: AMemberVisibility := svProtected;
DW_ACCESS_public: AMemberVisibility := svPublic;
else AMemberVisibility := svPrivate;
end;
end;
function TFpDwarfSymbol.IsArtificial: Boolean;
begin
if not(didtArtificialRead in FDwarfReadFlags) then begin
if InformationEntry.IsArtificial then
Include(FDwarfReadFlags, didtIsArtifical);
Include(FDwarfReadFlags, didtArtificialRead);
end;
Result := didtIsArtifical in FDwarfReadFlags;
end;
procedure TFpDwarfSymbol.NameNeeded;
var
AName: String;
begin
if InformationEntry.ReadName(AName) then
SetName(AName)
else
inherited NameNeeded;
end;
procedure TFpDwarfSymbol.TypeInfoNeeded;
begin
SetTypeInfo(NestedTypeInfo);
end;
function TFpDwarfSymbol.DataSize: Integer;
var
t: TFpDwarfSymbolType;
begin
t := NestedTypeInfo;
if t <> nil then
Result := t.DataSize
else
Result := 0;
end;
function TFpDwarfSymbol.InitLocationParser(const ALocationParser: TDwarfLocationExpression;
AnInitLocParserData: PInitLocParserData): Boolean;
begin
if (AnInitLocParserData <> nil) and IsValidLoc(AnInitLocParserData^.ObjectDataAddress)
then begin
if AnInitLocParserData^.ObjectDataAddrPush then begin
debugln(FPDBG_DWARF_VERBOSE, ['TFpDwarfSymbol.InitLocationParser Push=', dbgs(AnInitLocParserData^.ObjectDataAddress)]);
ALocationParser.Push(AnInitLocParserData^.ObjectDataAddress, lseValue);
end
else begin
debugln(FPDBG_DWARF_VERBOSE, ['TFpDwarfSymbol.InitLocationParser CurrentObjectAddress=', dbgs(AnInitLocParserData^.ObjectDataAddress)]);
ALocationParser.CurrentObjectAddress := AnInitLocParserData^.ObjectDataAddress;
end;
end;
Result := True;
end;
function TFpDwarfSymbol.LocationFromTag(ATag: Cardinal; AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; AnInitLocParserData: PInitLocParserData;
AnInformationEntry: TDwarfInformationEntry; ASucessOnMissingTag: Boolean): Boolean;
var
Val: TByteDynArray;
LocationParser: TDwarfLocationExpression;
begin
//debugln(['TDbgDwarfIdentifier.LocationFromTag', ClassName, ' ',Name, ' ', DwarfAttributeToString(ATag)]);
Result := False;
if AnInformationEntry = nil then
AnInformationEntry := InformationEntry;
//TODO: avoid copying data
// DW_AT_data_member_location in members [ block or const]
// DW_AT_location [block or reference] todo: const
if not AnInformationEntry.ReadValue(ATag, Val) then begin
(* if ASucessOnMissingTag = true AND tag does not exist
then AnAddress will NOT be modified
this can be used for DW_AT_data_member_location, if it does not exist members are on input location
TODO: review - better use temp var in caller
*)
Result := ASucessOnMissingTag;
if not Result then
AnAddress := InvalidLoc;
if not Result then
DebugLn(['LocationFromTag: failed to read DW_AT_location / ASucessOnMissingTag=', dbgs(ASucessOnMissingTag)]);
exit;
end;
AnAddress := InvalidLoc;
if Length(Val) = 0 then begin
DebugLn('LocationFromTag: Warning DW_AT_location empty');
//exit;
end;
LocationParser := TDwarfLocationExpression.Create(@Val[0], Length(Val), CompilationUnit,
AValueObj.MemManager, AValueObj.Context);
InitLocationParser(LocationParser, AnInitLocParserData);
LocationParser.Evaluate;
if IsError(LocationParser.LastError) then
SetLastError(LocationParser.LastError);
if LocationParser.ResultKind in [lseValue] then begin
AnAddress := TargetLoc(LocationParser.ResultData);
if ATag=DW_AT_location then
AnAddress.Address :=CompilationUnit.MapAddressToNewValue(AnAddress.Address);
Result := True;
end
else
if LocationParser.ResultKind in [lseRegister] then begin
AnAddress := ConstLoc(LocationParser.ResultData);
Result := True;
end
else
debugln(['TDbgDwarfIdentifier.LocationFromTag FAILED']); // TODO
LocationParser.Free;
end;
function TFpDwarfSymbol.GetDataAddress(AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType;
ATargetCacheIndex: Integer): Boolean;
var
ti: TFpDwarfSymbolType;
InitLocParserData: TInitLocParserData;
begin
InitLocParserData.ObjectDataAddress := AnAddress;
InitLocParserData.ObjectDataAddrPush := False;
Result := LocationFromTag(DW_AT_data_location, AValueObj, AnAddress, @InitLocParserData, nil, True);
if not Result then
exit;
if ATargetType = Self then begin
Result := True;
exit;
end;
//TODO: Handle AValueObj.DataAddressCache[ATargetCacheIndex];
Result := GetDataAddressNext(AValueObj, AnAddress, ATargetType, ATargetCacheIndex);
if not Result then
exit;
ti := NestedTypeInfo;
if ti <> nil then
Result := ti.GetDataAddress(AValueObj, AnAddress, ATargetType, ATargetCacheIndex+1)
else
Result := ATargetType = nil; // end of type chain
end;
function TFpDwarfSymbol.GetDataAddressNext(AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType;
ATargetCacheIndex: Integer): Boolean;
begin
Result := True;
end;
function TFpDwarfSymbol.HasAddress: Boolean;
begin
Result := False;
end;
procedure TFpDwarfSymbol.Init;
begin
//
end;
class function TFpDwarfSymbol.CreateSubClass(AName: String;
AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbol;
var
c: TDbgDwarfSymbolBaseClass;
begin
c := AnInformationEntry.CompUnit.DwarfSymbolClassMap.GetDwarfSymbolClass(AnInformationEntry.AbbrevTag);
Result := TFpDwarfSymbol(c.Create(AName, AnInformationEntry));
end;
destructor TFpDwarfSymbol.Destroy;
begin
inherited Destroy;
ReleaseRefAndNil(FNestedTypeInfo);
Assert(not CircleBackRefsActive, 'CircleBackRefsActive can not be is destructor');
// FParentTypeInfo := nil
end;
function TFpDwarfSymbol.StartScope: TDbgPtr;
begin
if not InformationEntry.ReadStartScope(Result) then
Result := 0;
end;
{ TFpDwarfSymbolValue }
function TFpDwarfSymbolValue.GetValueAddress(AValueObj: TFpDwarfValue; out
AnAddress: TFpDbgMemLocation): Boolean;
begin
Result := False;
end;
function TFpDwarfSymbolValue.GetValueDataAddress(AValueObj: TFpDwarfValue; out
AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType): Boolean;
begin
Result := TypeInfo <> nil;
if not Result then
exit;
Assert((TypeInfo is TFpDwarfSymbol) and (TypeInfo.SymbolType = stType), 'TFpDwarfSymbolValue.GetDataAddress');
Result := GetValueAddress(AValueObj, AnAddress);
Result := Result and IsReadableLoc(AnAddress);
if Result then begin
Result := TFpDwarfSymbolType(TypeInfo).GetDataAddress(AValueObj, AnAddress, ATargetType, 1);
if not Result then SetLastError(TypeInfo.LastError);
end;
end;
procedure TFpDwarfSymbolValue.KindNeeded;
var
t: TFpDbgSymbol;
begin
t := TypeInfo;
if t = nil then
inherited KindNeeded
else
SetKind(t.Kind);
end;
procedure TFpDwarfSymbolValue.MemberVisibilityNeeded;
var
Val: TDbgSymbolMemberVisibility;
begin
if ReadMemberVisibility(Val) then
SetMemberVisibility(Val)
else
if TypeInfo <> nil then
SetMemberVisibility(TypeInfo.MemberVisibility)
else
inherited MemberVisibilityNeeded;
end;
function TFpDwarfSymbolValue.GetMember(AIndex: Int64): TFpDbgSymbol;
var
ti: TFpDbgSymbol;
k: TDbgSymbolKind;
begin
ti := TypeInfo;
if ti = nil then begin
Result := inherited GetMember(AIndex);
exit;
end;
k := ti.Kind;
// while holding result, until refcount added, do not call any function
Result := ti.Member[AIndex];
assert((Result = nil) or (Result is TFpDwarfSymbolValue), 'TFpDwarfSymbolValue.GetMember is Value');
if (k in [skClass, skObject, skRecord {, skArray}]) and
(Result <> nil) and (Result is TFpDwarfSymbolValue)
then begin
if FMembers = nil then
FMembers := TFpDbgCircularRefCntObjList.Create;
FMembers.Add(Result); //TODO: last member only?
end;
end;
function TFpDwarfSymbolValue.GetMemberByName(AIndex: String): TFpDbgSymbol;
var
ti: TFpDbgSymbol;
k: TDbgSymbolKind;
begin
ti := TypeInfo;
if ti = nil then begin
Result := inherited GetMemberByName(AIndex);
exit;
end;
k := ti.Kind;
// while holding result, until refcount added, do not call any function
Result := ti.MemberByName[AIndex];
assert((Result = nil) or (Result is TFpDwarfSymbolValue), 'TFpDwarfSymbolValue.GetMember is Value');
if (k in [skClass, skObject, skRecord {, skArray}]) and
(Result <> nil) and (Result is TFpDwarfSymbolValue)
then begin
if FMembers = nil then
FMembers := TFpDbgCircularRefCntObjList.Create;
FMembers.Add(Result);
end;
end;
function TFpDwarfSymbolValue.GetMemberCount: Integer;
var
ti: TFpDbgSymbol;
begin
ti := TypeInfo;
if ti <> nil then begin
Result := ti.MemberCount;
//TODO: cache result
if ti.Kind in [skClass, skObject] then
while ti.TypeInfo <> nil do begin
ti := ti.TypeInfo;
Result := Result + ti.MemberCount;
end;
end
else
Result := inherited GetMemberCount;
end;
procedure TFpDwarfSymbolValue.Init;
begin
inherited Init;
SetSymbolType(stValue);
end;
destructor TFpDwarfSymbolValue.Destroy;
begin
Assert(not CircleBackRefsActive, 'CircleBackRefsActive can not be is ddestructor');
FreeAndNil(FMembers);
if FValueObject <> nil then begin
FValueObject.SetValueSymbol(nil);
FValueObject.ReleaseCirclularReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FValueObject, ClassName+'.FValueObject'){$ENDIF};
FValueObject := nil;
end;
ParentTypeInfo := nil;
inherited Destroy;
end;
class function TFpDwarfSymbolValue.CreateValueSubClass(AName: String;
AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbolValue;
var
c: TDbgDwarfSymbolBaseClass;
begin
c := AnInformationEntry.CompUnit.DwarfSymbolClassMap.GetDwarfSymbolClass(AnInformationEntry.AbbrevTag);
if c.InheritsFrom(TFpDwarfSymbolValue) then
Result := TFpDwarfSymbolValueClass(c).Create(AName, AnInformationEntry)
else
Result := nil;
end;
{ TFpDwarfSymbolValueWithLocation }
function TFpDwarfSymbolValueWithLocation.InitLocationParser(const ALocationParser: TDwarfLocationExpression;
AnInitLocParserData: PInitLocParserData): Boolean;
begin
Result := inherited InitLocationParser(ALocationParser, AnInitLocParserData);
ALocationParser.OnFrameBaseNeeded := @FrameBaseNeeded;
end;
procedure TFpDwarfSymbolValueWithLocation.FrameBaseNeeded(ASender: TObject);
var
p: TFpDwarfSymbol;
fb: TDBGPtr;
begin
debugln(FPDBG_DWARF_SEARCH, ['TFpDwarfSymbolValueVariable.FrameBaseNeeded ']);
p := ParentTypeInfo;
// TODO: what if parent is declaration?
if (p <> nil) and (p is TFpDwarfSymbolValueProc) then begin
fb := TFpDwarfSymbolValueProc(p).GetFrameBase(ASender as TDwarfLocationExpression);
(ASender as TDwarfLocationExpression).FrameBase := fb;
if fb = 0 then begin
debugln(FPDBG_DWARF_ERRORS, ['DWARF ERROR in TFpDwarfSymbolValueWithLocation.FrameBaseNeeded result is 0']);
end;
exit;
end;
{$warning TODO}
//else
//if OwnerTypeInfo <> nil then
// OwnerTypeInfo.fr;
// TODO: check owner
debugln(FPDBG_DWARF_ERRORS, ['DWARF ERROR in TFpDwarfSymbolValueWithLocation.FrameBaseNeeded no parent type info']);
(ASender as TDwarfLocationExpression).FrameBase := 0;
end;
function TFpDwarfSymbolValueWithLocation.GetValueObject: TFpDbgValue;
var
ti: TFpDbgSymbol;
begin
Result := FValueObject;
if Result <> nil then exit;
ti := TypeInfo;
if (ti = nil) or not (ti.SymbolType = stType) then exit;
FValueObject := TFpDwarfSymbolType(ti).GetTypedValueObject(False);
if FValueObject <> nil then begin
{$IFDEF WITH_REFCOUNT_DEBUG}FValueObject.DbgRenameReference(@FValueObject, ClassName+'.FValueObject');{$ENDIF}
FValueObject.MakePlainRefToCirclular;
FValueObject.SetValueSymbol(self);
end;
Result := FValueObject;
end;
{ TFpDwarfSymbolType }
procedure TFpDwarfSymbolType.Init;
begin
inherited Init;
SetSymbolType(stType);
end;
procedure TFpDwarfSymbolType.MemberVisibilityNeeded;
var
Val: TDbgSymbolMemberVisibility;
begin
if ReadMemberVisibility(Val) then
SetMemberVisibility(Val)
else
inherited MemberVisibilityNeeded;
end;
procedure TFpDwarfSymbolType.SizeNeeded;
var
ByteSize: Integer;
begin
if InformationEntry.ReadValue(DW_AT_byte_size, ByteSize) then
SetSize(ByteSize)
else
inherited SizeNeeded;
end;
function TFpDwarfSymbolType.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
Result := nil;
end;
function TFpDwarfSymbolType.GetValueBounds(AValueObj: TFpDwarfValue; out ALowBound,
AHighBound: Int64): Boolean;
begin
Result := HasBounds;
ALowBound := OrdLowBound;
AHighBound := OrdHighBound;
end;
procedure TFpDwarfSymbolType.ResetValueBounds;
var
ti: TFpDwarfSymbolType;
begin
ti := NestedTypeInfo;
if (ti <> nil) then
ti.ResetValueBounds;
end;
class function TFpDwarfSymbolType.CreateTypeSubClass(AName: String;
AnInformationEntry: TDwarfInformationEntry): TFpDwarfSymbolType;
var
c: TDbgDwarfSymbolBaseClass;
begin
c := AnInformationEntry.CompUnit.DwarfSymbolClassMap.GetDwarfSymbolClass(AnInformationEntry.AbbrevTag);
if c.InheritsFrom(TFpDwarfSymbolType) then
Result := TFpDwarfSymbolTypeClass(c).Create(AName, AnInformationEntry)
else
Result := nil;
end;
function TFpDwarfSymbolType.TypeCastValue(AValue: TFpDbgValue): TFpDbgValue;
begin
Result := GetTypedValueObject(True);
If Result = nil then
exit;
assert(Result is TFpDwarfValue);
if not TFpDwarfValue(Result).SetTypeCastInfo(self, AValue) then
ReleaseRefAndNil(Result);
end;
{ TDbgDwarfBaseTypeIdentifier }
procedure TFpDwarfSymbolTypeBasic.KindNeeded;
var
Encoding, ByteSize: Integer;
begin
if not InformationEntry.ReadValue(DW_AT_encoding, Encoding) then begin
DebugLn(FPDBG_DWARF_WARNINGS, ['TFpDwarfSymbolTypeBasic.KindNeeded: Failed reading encoding for ', DwarfTagToString(InformationEntry.AbbrevTag)]);
inherited KindNeeded;
exit;
end;
if InformationEntry.ReadValue(DW_AT_byte_size, ByteSize) then
SetSize(ByteSize);
case Encoding of
DW_ATE_address : SetKind(skPointer);
DW_ATE_boolean: SetKind(skBoolean);
//DW_ATE_complex_float:
DW_ATE_float: SetKind(skFloat);
DW_ATE_signed: SetKind(skInteger);
DW_ATE_signed_char: SetKind(skChar);
DW_ATE_unsigned: SetKind(skCardinal);
DW_ATE_unsigned_char: SetKind(skChar);
DW_ATE_numeric_string:SetKind(skChar); // temporary for widestring
else
begin
DebugLn(FPDBG_DWARF_WARNINGS, ['TFpDwarfSymbolTypeBasic.KindNeeded: Unknown encoding ', DwarfBaseTypeEncodingToString(Encoding), ' for ', DwarfTagToString(InformationEntry.AbbrevTag)]);
inherited KindNeeded;
end;
end;
end;
procedure TFpDwarfSymbolTypeBasic.TypeInfoNeeded;
begin
SetTypeInfo(nil);
end;
function TFpDwarfSymbolTypeBasic.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
case Kind of
skPointer: Result := TFpDwarfValuePointer.Create(Self, Size);
skInteger: Result := TFpDwarfValueInteger.Create(Self, Size);
skCardinal: Result := TFpDwarfValueCardinal.Create(Self, Size);
skBoolean: Result := TFpDwarfValueBoolean.Create(Self, Size);
skChar: Result := TFpDwarfValueChar.Create(Self, Size);
skFloat: Result := TFpDwarfValueFloat.Create(Self, Size);
end;
end;
function TFpDwarfSymbolTypeBasic.GetHasBounds: Boolean;
begin
Result := (kind = skInteger) or (kind = skCardinal);
end;
function TFpDwarfSymbolTypeBasic.GetOrdHighBound: Int64;
begin
case Kind of
skInteger: Result := int64( high(int64) shr (64 - Min(Size, 8) * 8));
skCardinal: Result := int64( high(qword) shr (64 - Min(Size, 8) * 8));
else
Result := inherited GetOrdHighBound;
end;
end;
function TFpDwarfSymbolTypeBasic.GetOrdLowBound: Int64;
begin
case Kind of
skInteger: Result := -(int64( high(int64) shr (64 - Min(Size, 8) * 8)))-1;
skCardinal: Result := 0;
else
Result := inherited GetOrdHighBound;
end;
end;
{ TFpDwarfSymbolTypeModifier }
procedure TFpDwarfSymbolTypeModifier.TypeInfoNeeded;
var
p: TFpDwarfSymbolType;
begin
p := NestedTypeInfo;
if p <> nil then
SetTypeInfo(p.TypeInfo)
else
SetTypeInfo(nil);
end;
procedure TFpDwarfSymbolTypeModifier.ForwardToSymbolNeeded;
begin
SetForwardToSymbol(NestedTypeInfo)
end;
function TFpDwarfSymbolTypeModifier.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
var
ti: TFpDwarfSymbolType;
begin
ti := NestedTypeInfo;
if ti <> nil then
Result := ti.GetTypedValueObject(ATypeCast)
else
Result := inherited;
end;
{ TFpDwarfSymbolTypeRef }
function TFpDwarfSymbolTypeRef.GetFlags: TDbgSymbolFlags;
begin
Result := (inherited GetFlags) + [sfInternalRef];
end;
function TFpDwarfSymbolTypeRef.GetDataAddressNext(AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType;
ATargetCacheIndex: Integer): Boolean;
var
t: TFpDbgMemLocation;
begin
t := AValueObj.DataAddressCache[ATargetCacheIndex];
if IsInitializedLoc(t) then begin
AnAddress := t;
end
else begin
Result := AValueObj.MemManager <> nil;
if not Result then
exit;
AnAddress := AValueObj.MemManager.ReadAddress(AnAddress, CompilationUnit.AddressSize);
AValueObj.DataAddressCache[ATargetCacheIndex] := AnAddress;
end;
Result := IsValidLoc(AnAddress);
if Result then
Result := inherited GetDataAddressNext(AValueObj, AnAddress, ATargetType, ATargetCacheIndex)
else
if IsError(AValueObj.MemManager.LastError) then
SetLastError(AValueObj.MemManager.LastError);
// Todo: other error
end;
{ TFpDwarfSymbolTypeDeclaration }
function TFpDwarfSymbolTypeDeclaration.DoGetNestedTypeInfo: TFpDwarfSymbolType;
var
ti: TFpDwarfSymbolType;
ti2: TFpDbgSymbol;
begin
Result := inherited DoGetNestedTypeInfo;
// Is internal class pointer?
// Do not trigged any cached property of the pointer
if (Result = nil) then
exit;
ti := Result;
if (ti is TFpDwarfSymbolTypeModifier) then begin
ti := TFpDwarfSymbolType(ti.TypeInfo);
if (Result = nil) then
exit;
end;
if not (ti is TFpDwarfSymbolTypePointer) then
exit;
ti2 := ti.NestedTypeInfo;
// only if it is NOT a declaration
if (ti2 <> nil) and (ti2 is TFpDwarfSymbolTypeStructure) then begin
TFpDwarfSymbolTypePointer(ti).IsInternalPointer := True;
// TODO: Flag the structure as class (save teme in KindNeeded)
end;
end;
{ TFpDwarfSymbolTypeSubRange }
procedure TFpDwarfSymbolTypeSubRange.InitEnumIdx;
var
t: TFpDwarfSymbolType;
i: Integer;
h, l: Int64;
begin
if FEnumIdxValid then
exit;
FEnumIdxValid := True;
t := NestedTypeInfo;
i := t.MemberCount - 1;
h := OrdHighBound;
l := OrdLowBound;
while (i >= 0) and (t.Member[i].OrdinalValue > h) do
dec(i);
FHighEnumIdx := i;
while (i >= 0) and (t.Member[i].OrdinalValue >= l) do
dec(i);
FLowEnumIdx := i + 1;
end;
procedure TFpDwarfSymbolTypeSubRange.ReadBounds(AValueObj: TFpDwarfValue);
var
FwdInfoPtr: Pointer;
FwdCompUint: TDwarfCompilationUnit;
NewInfo: TDwarfInformationEntry;
var
AnAddress: TFpDbgMemLocation;
InitLocParserData: TInitLocParserData;
begin
// TODO: assert(AValueObj <> nil, 'TFpDwarfSymbolTypeSubRange.ReadBounds: AValueObj <> nil');
if FLowBoundState <> rfNotRead then exit;
// Todo: search attrib-IDX only once
// Todo: LocationFromTag()
if InformationEntry.ReadReference(DW_AT_lower_bound, FwdInfoPtr, FwdCompUint) then begin
NewInfo := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
FLowBoundValue := TFpDwarfSymbolValue.CreateValueSubClass('', NewInfo);
NewInfo.ReleaseReference;
if FLowBoundValue = nil then begin
FLowBoundState := rfNotFound;
exit;
end
else
FLowBoundState := rfValue;
end
else
if InformationEntry.ReadValue(DW_AT_lower_bound, FLowBoundConst) then begin
FLowBoundState := rfConst;
end
else
begin
//FLowBoundConst := 0; // the default
//FLowBoundState := rfConst;
FLowBoundState := rfNotFound;
exit; // incomplete type
end;
if InformationEntry.ReadReference(DW_AT_upper_bound, FwdInfoPtr, FwdCompUint) then begin
NewInfo := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
FHighBoundValue := TFpDwarfSymbolValue.CreateValueSubClass('', NewInfo);
NewInfo.ReleaseReference;
if FHighBoundValue = nil then begin
FHighBoundState := rfNotFound;
exit;
end
else
FHighBoundState := rfValue;
end
else
if InformationEntry.ReadValue(DW_AT_upper_bound, FHighBoundConst) then begin
FHighBoundState := rfConst;
end
else
begin
if assigned(AValueObj) then
InitLocParserData.ObjectDataAddress := AValueObj.Address;
InitLocParserData.ObjectDataAddrPush := False;
if assigned(AValueObj) and LocationFromTag(DW_AT_upper_bound, AValueObj, AnAddress, @InitLocParserData, InformationEntry) then begin
FHighBoundState := rfConst;
FHighBoundConst := Int64(AnAddress.Address);
end
else
begin
FHighBoundState := rfNotFound;
if InformationEntry.ReadReference(DW_AT_count, FwdInfoPtr, FwdCompUint) then begin
NewInfo := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
FCountValue := TFpDwarfSymbolValue.CreateValueSubClass('', NewInfo);
NewInfo.ReleaseReference;
if FCountValue = nil then begin
FCountState := rfNotFound;
exit;
end
else
FCountState := rfValue;
end
else
if InformationEntry.ReadValue(DW_AT_count, FCountConst) then begin
FCountState := rfConst;
end
else
FCountState := rfNotFound;
end;
end;
end;
function TFpDwarfSymbolTypeSubRange.DoGetNestedTypeInfo: TFpDwarfSymbolType;
begin
Result := inherited DoGetNestedTypeInfo;
if Result <> nil then
exit;
if FLowBoundState = rfValue then
Result := FLowBoundValue.TypeInfo as TFpDwarfSymbolType
else
if FHighBoundState = rfValue then
Result := FHighBoundValue.TypeInfo as TFpDwarfSymbolType
else
if FCountState = rfValue then
Result := FCountValue.TypeInfo as TFpDwarfSymbolType;
end;
function TFpDwarfSymbolTypeSubRange.GetHasBounds: Boolean;
begin
ReadBounds(nil);
// TODO: currently limited to const.
// not standard, but upper may be missing?
Result := (FLowBoundState in [rfConst]) and
( (FHighBoundState in [rfConst]) or
(FCountState in [rfConst]) );
(*
Result := (FLowBoundState in [rfValue, rfConst]) and
( (FHighBoundState in [rfValue, rfConst]) or
(FCountState in [rfValue, rfConst]) );
*)
end;
function TFpDwarfSymbolTypeSubRange.GetOrdHighBound: Int64;
begin
// Todo range check off.
//if FHighBoundState = rfValue then
// Result := FHighBoundValue.VALUE // TODO
//else
if FHighBoundState = rfConst then
Result := FHighBoundConst
else
//if FCountState = rfValue then
// Result := GetOrdLowBound + FCountValue.VALUE - 1 // TODO
//else
if FHighBoundState = rfConst then
Result := GetOrdLowBound + FCountConst - 1;
end;
function TFpDwarfSymbolTypeSubRange.GetOrdLowBound: Int64;
begin
//if FLowBoundState = rfValue then
// Result := FLowBoundValue.VALUE // TODO
//else
Result := FLowBoundConst;
end;
procedure TFpDwarfSymbolTypeSubRange.NameNeeded;
var
AName: String;
begin
if InformationEntry.ReadName(AName) then
SetName(AName)
else
SetName('');
end;
procedure TFpDwarfSymbolTypeSubRange.KindNeeded;
var
t: TFpDbgSymbol;
begin
// TODO: limit to ordinal types
if not HasBounds then begin // does ReadBounds;
SetKind(skNone); // incomplete type
end;
t := NestedTypeInfo;
if t = nil then begin
SetKind(skInteger);
SetSize(CompilationUnit.AddressSize);
end
else
SetKind(t.Kind);
end;
procedure TFpDwarfSymbolTypeSubRange.SizeNeeded;
var
t: TFpDbgSymbol;
begin
t := NestedTypeInfo;
if t = nil then begin
SetKind(skInteger);
SetSize(CompilationUnit.AddressSize);
end
else
SetSize(t.Size);
end;
function TFpDwarfSymbolTypeSubRange.GetMember(AIndex: Int64): TFpDbgSymbol;
begin
if Kind = skEnum then begin
if not FEnumIdxValid then
InitEnumIdx;
Result := NestedTypeInfo.Member[AIndex - FLowEnumIdx];
end
else
Result := inherited GetMember(AIndex);
end;
function TFpDwarfSymbolTypeSubRange.GetMemberCount: Integer;
begin
if Kind = skEnum then begin
if not FEnumIdxValid then
InitEnumIdx;
Result := FHighEnumIdx - FLowEnumIdx + 1;
end
else
Result := inherited GetMemberCount;
end;
function TFpDwarfSymbolTypeSubRange.GetFlags: TDbgSymbolFlags;
begin
Result := (inherited GetFlags) + [sfSubRange];
end;
function TFpDwarfSymbolTypeSubRange.GetValueBounds(AValueObj: TFpDwarfValue; out
ALowBound, AHighBound: Int64): Boolean;
begin
ReadBounds(AValueObj);
Result := inherited GetValueBounds(AValueObj, ALowBound, AHighBound);
end;
procedure TFpDwarfSymbolTypeSubRange.ResetValueBounds;
begin
inherited ResetValueBounds;
FLowBoundState := rfNotRead;
FHighBoundState := rfNotRead;
FCountState := rfNotRead;
end;
procedure TFpDwarfSymbolTypeSubRange.Init;
begin
FLowBoundState := rfNotRead;
FHighBoundState := rfNotRead;
FCountState := rfNotRead;
inherited Init;
end;
{ TFpDwarfSymbolTypePointer }
function TFpDwarfSymbolTypePointer.IsInternalDynArrayPointer: Boolean;
var
ti: TFpDbgSymbol;
begin
Result := False;
ti := NestedTypeInfo; // Same as TypeInfo, but does not try to be forwarded
Result := (ti <> nil) and (ti is TFpDwarfSymbolTypeArray);
if Result then
Result := (sfDynArray in ti.Flags);
end;
procedure TFpDwarfSymbolTypePointer.TypeInfoNeeded;
var
p: TFpDwarfSymbolType;
begin
p := NestedTypeInfo;
if IsInternalPointer and (p <> nil) then begin
SetTypeInfo(p.TypeInfo);
exit;
end;
SetTypeInfo(p);
end;
function TFpDwarfSymbolTypePointer.GetIsInternalPointer: Boolean;
begin
Result := FIsInternalPointer or IsInternalDynArrayPointer;
end;
procedure TFpDwarfSymbolTypePointer.KindNeeded;
var
k: TDbgSymbolKind;
begin
if IsInternalPointer then begin
k := NestedTypeInfo.Kind;
if k = skObject then
SetKind(skClass)
else
SetKind(k);
end
else
SetKind(skPointer);
end;
procedure TFpDwarfSymbolTypePointer.SizeNeeded;
begin
SetSize(CompilationUnit.AddressSize);
end;
procedure TFpDwarfSymbolTypePointer.ForwardToSymbolNeeded;
begin
if IsInternalPointer then
SetForwardToSymbol(NestedTypeInfo) // Same as TypeInfo, but does not try to be forwarded
else
SetForwardToSymbol(nil); // inherited ForwardToSymbolNeeded;
end;
function TFpDwarfSymbolTypePointer.GetDataAddressNext(AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType;
ATargetCacheIndex: Integer): Boolean;
var
t: TFpDbgMemLocation;
begin
t := AValueObj.DataAddressCache[ATargetCacheIndex];
if IsInitializedLoc(t) then begin
AnAddress := t;
end
else begin
Result := AValueObj.MemManager <> nil;
if not Result then
exit;
AnAddress := AValueObj.MemManager.ReadAddress(AnAddress, CompilationUnit.AddressSize);
AValueObj.DataAddressCache[ATargetCacheIndex] := AnAddress;
end;
Result := IsValidLoc(AnAddress);
if Result then
Result := inherited GetDataAddressNext(AValueObj, AnAddress, ATargetType, ATargetCacheIndex)
else
if IsError(AValueObj.MemManager.LastError) then
SetLastError(AValueObj.MemManager.LastError);
// Todo: other error
end;
function TFpDwarfSymbolTypePointer.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
if IsInternalPointer then
Result := NestedTypeInfo.GetTypedValueObject(ATypeCast)
else
Result := TFpDwarfValuePointer.Create(Self, CompilationUnit.AddressSize);
end;
function TFpDwarfSymbolTypePointer.DataSize: Integer;
begin
if Kind = skClass then
Result := NestedTypeInfo.Size
else
Result := inherited DataSize;
end;
{ TDbgDwarfIdentifierEnumElement }
procedure TFpDwarfSymbolValueEnumMember.ReadOrdinalValue;
begin
if FOrdinalValueRead then exit;
FOrdinalValueRead := True;
FHasOrdinalValue := InformationEntry.ReadValue(DW_AT_const_value, FOrdinalValue);
end;
procedure TFpDwarfSymbolValueEnumMember.KindNeeded;
begin
SetKind(skEnumValue);
end;
function TFpDwarfSymbolValueEnumMember.GetHasOrdinalValue: Boolean;
begin
ReadOrdinalValue;
Result := FHasOrdinalValue;
end;
function TFpDwarfSymbolValueEnumMember.GetOrdinalValue: Int64;
begin
ReadOrdinalValue;
Result := FOrdinalValue;
end;
procedure TFpDwarfSymbolValueEnumMember.Init;
begin
FOrdinalValueRead := False;
inherited Init;
end;
function TFpDwarfSymbolValueEnumMember.GetValueObject: TFpDbgValue;
begin
Result := FValueObject;
if Result <> nil then exit;
FValueObject := TFpDwarfValueEnumMember.Create(Self);
{$IFDEF WITH_REFCOUNT_DEBUG}FValueObject.DbgRenameReference(@FValueObject, ClassName+'.FValueObject');{$ENDIF}
FValueObject.MakePlainRefToCirclular;
FValueObject.SetValueSymbol(self);
Result := FValueObject;
end;
{ TFpDwarfSymbolTypeEnum }
procedure TFpDwarfSymbolTypeEnum.CreateMembers;
var
Info, Info2: TDwarfInformationEntry;
sym: TFpDwarfSymbol;
begin
if FMembers <> nil then
exit;
FMembers := TFpDbgCircularRefCntObjList.Create;
Info := InformationEntry.FirstChild;
if Info = nil then exit;
while Info.HasValidScope do begin
if (Info.AbbrevTag = DW_TAG_enumerator) then begin
Info2 := Info.Clone;
sym := TFpDwarfSymbol.CreateSubClass('', Info2);
FMembers.Add(sym);
sym.ReleaseReference;
sym.ParentTypeInfo := self;
Info2.ReleaseReference;
end;
Info.GoNext;
end;
Info.ReleaseReference;
end;
function TFpDwarfSymbolTypeEnum.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
Result := TFpDwarfValueEnum.Create(Self, Size);
end;
procedure TFpDwarfSymbolTypeEnum.KindNeeded;
begin
SetKind(skEnum);
end;
function TFpDwarfSymbolTypeEnum.GetMember(AIndex: Int64): TFpDbgSymbol;
begin
CreateMembers;
Result := TFpDbgSymbol(FMembers[AIndex]);
end;
function TFpDwarfSymbolTypeEnum.GetMemberByName(AIndex: String): TFpDbgSymbol;
var
i: Integer;
s, s1, s2: String;
begin
if AIndex = '' then
s1 := UTF8UpperCase(AIndex);
s2 := UTF8LowerCase(AIndex);
CreateMembers;
i := FMembers.Count - 1;
while i >= 0 do begin
Result := TFpDbgSymbol(FMembers[i]);
s := Result.Name;
if (s <> '') and CompareUtf8BothCase(@s1[1], @s2[1], @s[1]) then
exit;
dec(i);
end;
Result := nil;
end;
function TFpDwarfSymbolTypeEnum.GetMemberCount: Integer;
begin
CreateMembers;
Result := FMembers.Count;
end;
function TFpDwarfSymbolTypeEnum.GetHasBounds: Boolean;
begin
Result := True;
end;
function TFpDwarfSymbolTypeEnum.GetOrdHighBound: Int64;
var
c: Integer;
begin
c := MemberCount;
if c > 0 then
Result := Member[c-1].OrdinalValue
else
Result := -1;
end;
function TFpDwarfSymbolTypeEnum.GetOrdLowBound: Int64;
var
c: Integer;
begin
c := MemberCount;
if c > 0 then
Result := Member[0].OrdinalValue
else
Result := 0;
end;
destructor TFpDwarfSymbolTypeEnum.Destroy;
var
i: Integer;
begin
if FMembers <> nil then
for i := 0 to FMembers.Count - 1 do
TFpDwarfSymbol(FMembers[i]).ParentTypeInfo := nil;
FreeAndNil(FMembers);
inherited Destroy;
end;
{ TFpDwarfSymbolTypeSet }
procedure TFpDwarfSymbolTypeSet.KindNeeded;
begin
SetKind(skSet);
end;
function TFpDwarfSymbolTypeSet.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
Result := TFpDwarfValueSet.Create(Self, Size);
end;
function TFpDwarfSymbolTypeSet.GetMemberCount: Integer;
begin
if TypeInfo.Kind = skEnum then
Result := TypeInfo.MemberCount
else
Result := inherited GetMemberCount;
end;
function TFpDwarfSymbolTypeSet.GetMember(AIndex: Int64): TFpDbgSymbol;
begin
if TypeInfo.Kind = skEnum then
Result := TypeInfo.Member[AIndex]
else
Result := inherited GetMember(AIndex);
end;
{ TFpDwarfSymbolValueMember }
function TFpDwarfSymbolValueMember.GetValueAddress(AValueObj: TFpDwarfValue; out
AnAddress: TFpDbgMemLocation): Boolean;
var
BaseAddr: TFpDbgMemLocation;
InitLocParserData: TInitLocParserData;
begin
AnAddress := AValueObj.DataAddressCache[0];
Result := IsValidLoc(AnAddress);
if IsInitializedLoc(AnAddress) then
exit;
if AValueObj = nil then debugln(['TFpDwarfSymbolValueMember.InitLocationParser: NO VAl Obj !!!!!!!!!!!!!!!'])
else if AValueObj.StructureValue = nil then debugln(['TFpDwarfSymbolValueMember.InitLocationParser: NO STRUCT Obj !!!!!!!!!!!!!!!']);
if (AValueObj = nil) or (AValueObj.StructureValue = nil) or (ParentTypeInfo = nil)
then begin
debugln(FPDBG_DWARF_ERRORS, ['DWARF ERROR in TFpDwarfSymbolValueMember.InitLocationParser Error: ',ErrorCode(LastError),' ValueObject=', DbgSName(FValueObject)]);
Result := False;
if not IsError(LastError) then
SetLastError(CreateError(fpErrLocationParserInit)); // TODO: error message?
exit;
end;
Assert((ParentTypeInfo is TFpDwarfSymbol) and (ParentTypeInfo.SymbolType = stType), '');
if not AValueObj.GetStructureDwarfDataAddress(BaseAddr, TFpDwarfSymbolType(ParentTypeInfo)) then begin
debugln(FPDBG_DWARF_ERRORS, ['DWARF ERROR in TFpDwarfSymbolValueMember.InitLocationParser Error: ',ErrorCode(LastError),' ValueObject=', DbgSName(FValueObject)]);
Result := False;
if not IsError(LastError) then
SetLastError(CreateError(fpErrLocationParserInit)); // TODO: error message?
exit;
end;
//TODO: AValueObj.StructureValue.LastError
InitLocParserData.ObjectDataAddress := BaseAddr;
InitLocParserData.ObjectDataAddrPush := True;
Result := LocationFromTag(DW_AT_data_member_location, AValueObj, AnAddress, @InitLocParserData);
AValueObj.DataAddressCache[0] := AnAddress;
end;
function TFpDwarfSymbolValueMember.HasAddress: Boolean;
begin
Result := (InformationEntry.HasAttrib(DW_AT_data_member_location));
end;
{ TFpDwarfSymbolTypeStructure }
function TFpDwarfSymbolTypeStructure.GetMemberByName(AIndex: String): TFpDbgSymbol;
var
Ident: TDwarfInformationEntry;
ti: TFpDbgSymbol;
begin
// Todo, maybe create all children?
if FLastChildByName <> nil then begin
FLastChildByName.ReleaseCirclularReference;
FLastChildByName := nil;
end;
Result := nil;
Ident := InformationEntry.FindNamedChild(AIndex);
if Ident <> nil then begin
FLastChildByName := TFpDwarfSymbol.CreateSubClass('', Ident);
FLastChildByName.MakePlainRefToCirclular;
FLastChildByName.ParentTypeInfo := self;
//assert is member ?
ReleaseRefAndNil(Ident);
Result := FLastChildByName;
exit;
end;
ti := TypeInfo; // Parent
if ti <> nil then
Result := ti.MemberByName[AIndex];
end;
function TFpDwarfSymbolTypeStructure.GetMemberCount: Integer;
begin
CreateMembers;
Result := FMembers.Count;
end;
function TFpDwarfSymbolTypeStructure.GetDataAddressNext(AValueObj: TFpDwarfValue;
var AnAddress: TFpDbgMemLocation; ATargetType: TFpDwarfSymbolType;
ATargetCacheIndex: Integer): Boolean;
var
t: TFpDbgMemLocation;
InitLocParserData: TInitLocParserData;
begin
t := AValueObj.DataAddressCache[ATargetCacheIndex];
if IsInitializedLoc(t) then begin
AnAddress := t;
Result := IsValidLoc(AnAddress);
end
else begin
InitInheritanceInfo;
//TODO: may be a constant // offset
InitLocParserData.ObjectDataAddress := AnAddress;
InitLocParserData.ObjectDataAddrPush := True;
Result := LocationFromTag(DW_AT_data_member_location, AValueObj, t, @InitLocParserData, FInheritanceInfo);
if not Result then
exit;
AnAddress := t;
AValueObj.DataAddressCache[ATargetCacheIndex] := AnAddress;
if IsError(AValueObj.MemManager.LastError) then
SetLastError(AValueObj.MemManager.LastError);
end;
Result := inherited GetDataAddressNext(AValueObj, AnAddress, ATargetType, ATargetCacheIndex);
end;
function TFpDwarfSymbolTypeStructure.GetMember(AIndex: Int64): TFpDbgSymbol;
var
ti: TFpDbgSymbol;
begin
CreateMembers;
if AIndex >= FMembers.Count then begin
ti := TypeInfo;
if ti <> nil then
Result := ti.Member[AIndex - FMembers.Count];
end
else
Result := TFpDbgSymbol(FMembers[AIndex]);
end;
destructor TFpDwarfSymbolTypeStructure.Destroy;
var
i: Integer;
begin
ReleaseRefAndNil(FInheritanceInfo);
if FMembers <> nil then begin
for i := 0 to FMembers.Count - 1 do
TFpDwarfSymbol(FMembers[i]).ParentTypeInfo := nil;
FreeAndNil(FMembers);
end;
if FLastChildByName <> nil then begin
FLastChildByName.ParentTypeInfo := nil;
FLastChildByName.ReleaseCirclularReference;
FLastChildByName := nil;
end;
inherited Destroy;
end;
procedure TFpDwarfSymbolTypeStructure.CreateMembers;
var
Info: TDwarfInformationEntry;
Info2: TDwarfInformationEntry;
sym: TFpDwarfSymbol;
begin
if FMembers <> nil then
exit;
FMembers := TFpDbgCircularRefCntObjList.Create;
Info := InformationEntry.Clone;
Info.GoChild;
while Info.HasValidScope do begin
if (Info.AbbrevTag = DW_TAG_member) or (Info.AbbrevTag = DW_TAG_subprogram) then begin
Info2 := Info.Clone;
sym := TFpDwarfSymbol.CreateSubClass('', Info2);
FMembers.Add(sym);
sym.ReleaseReference;
sym.ParentTypeInfo := self;
Info2.ReleaseReference;
end;
Info.GoNext;
end;
Info.ReleaseReference;
end;
procedure TFpDwarfSymbolTypeStructure.InitInheritanceInfo;
begin
if FInheritanceInfo = nil then
FInheritanceInfo := InformationEntry.FindChildByTag(DW_TAG_inheritance);
end;
function TFpDwarfSymbolTypeStructure.DoGetNestedTypeInfo: TFpDwarfSymbolType;
var
FwdInfoPtr: Pointer;
FwdCompUint: TDwarfCompilationUnit;
ParentInfo: TDwarfInformationEntry;
begin
Result:= nil;
InitInheritanceInfo;
if (FInheritanceInfo <> nil) and
FInheritanceInfo.ReadReference(DW_AT_type, FwdInfoPtr, FwdCompUint)
then begin
ParentInfo := TDwarfInformationEntry.Create(FwdCompUint, FwdInfoPtr);
//DebugLn(FPDBG_DWARF_SEARCH, ['Inherited from ', dbgs(ParentInfo.FInformationEntry, FwdCompUint) ]);
Result := TFpDwarfSymbolType.CreateTypeSubClass('', ParentInfo);
ParentInfo.ReleaseReference;
end;
end;
procedure TFpDwarfSymbolTypeStructure.KindNeeded;
begin
if (InformationEntry.AbbrevTag = DW_TAG_class_type) then
SetKind(skClass)
else
begin
if TypeInfo <> nil then // inheritance
SetKind(skObject) // skClass
else
if MemberByName['_vptr$TOBJECT'] <> nil then
SetKind(skObject) // skClass
else
if MemberByName['_vptr$'+Name] <> nil then
SetKind(skObject)
else
SetKind(skRecord);
end;
end;
function TFpDwarfSymbolTypeStructure.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
if ATypeCast then
Result := TFpDwarfValueStructTypeCast.Create(Self)
else
Result := TFpDwarfValueStruct.Create(Self);
end;
{ TFpDwarfSymbolTypeArray }
procedure TFpDwarfSymbolTypeArray.CreateMembers;
var
Info, Info2: TDwarfInformationEntry;
t: Cardinal;
sym: TFpDwarfSymbol;
begin
if FMembers <> nil then
exit;
FMembers := TFpDbgCircularRefCntObjList.Create;
Info := InformationEntry.FirstChild;
if Info = nil then exit;
while Info.HasValidScope do begin
t := Info.AbbrevTag;
if (t = DW_TAG_enumeration_type) or (t = DW_TAG_subrange_type) then begin
Info2 := Info.Clone;
sym := TFpDwarfSymbol.CreateSubClass('', Info2);
FMembers.Add(sym);
sym.ReleaseReference;
sym.ParentTypeInfo := self;
Info2.ReleaseReference;
end;
Info.GoNext;
end;
Info.ReleaseReference;
end;
procedure TFpDwarfSymbolTypeArray.ReadStride;
var
t: TFpDwarfSymbolType;
begin
if didtStrideRead in FDwarfArrayReadFlags then
exit;
Include(FDwarfArrayReadFlags, didtStrideRead);
if InformationEntry.ReadValue(DW_AT_bit_stride, FStrideInBits) then
exit;
CreateMembers;
if (FMembers.Count > 0) and // TODO: stride for diff member
(TDbgDwarfSymbolBase(FMembers[0]).InformationEntry.ReadValue(DW_AT_byte_stride, FStrideInBits))
then begin
FStrideInBits := FStrideInBits * 8;
exit;
end;
t := NestedTypeInfo;
if t = nil then
FStrideInBits := 0 // TODO error
else
FStrideInBits := t.Size * 8;
end;
procedure TFpDwarfSymbolTypeArray.ReadOrdering;
var
AVal: Integer;
begin
if didtOrdering in FDwarfArrayReadFlags then
exit;
Include(FDwarfArrayReadFlags, didtOrdering);
if InformationEntry.ReadValue(DW_AT_ordering, AVal) then
FRowMajor := AVal = DW_ORD_row_major
else
FRowMajor := True; // default (at least in pas)
end;
procedure TFpDwarfSymbolTypeArray.KindNeeded;
begin
SetKind(skArray); // Todo: static/dynamic?
end;
function TFpDwarfSymbolTypeArray.GetTypedValueObject(ATypeCast: Boolean): TFpDwarfValue;
begin
Result := TFpDwarfValueArray.Create(Self);
end;
function TFpDwarfSymbolTypeArray.GetFlags: TDbgSymbolFlags;
function IsDynSubRange(m: TFpDwarfSymbol): Boolean;
begin
Result := sfSubRange in m.Flags;
if not Result then exit;
while (m <> nil) and not(m is TFpDwarfSymbolTypeSubRange) do
m := m.NestedTypeInfo;
Result := m <> nil;
if not Result then exit; // TODO: should not happen, handle error
Result := TFpDwarfSymbolTypeSubRange(m).FHighBoundState = rfValue; // dynamic high bound
end;
var
m: TFpDbgSymbol;
begin
Result := inherited GetFlags;
if (MemberCount = 1) then begin // TODO: move to freepascal specific
m := Member[0];
if (not m.HasBounds) or // e.g. Subrange with missing upper bound
(m.OrdHighBound < m.OrdLowBound) or
(IsDynSubRange(TFpDwarfSymbol(m)))
then
Result := Result + [sfDynArray]
else
Result := Result + [sfStatArray];
end
else
Result := Result + [sfStatArray];
end;
function TFpDwarfSymbolTypeArray.GetMember(AIndex: Int64): TFpDbgSymbol;
begin
CreateMembers;
Result := TFpDbgSymbol(FMembers[AIndex]);
end;
function TFpDwarfSymbolTypeArray.GetMemberByName(AIndex: String): TFpDbgSymbol;
begin
Result := nil; // no named members
end;
function TFpDwarfSymbolTypeArray.GetMemberCount: Integer;
begin
CreateMembers;
Result := FMembers.Count;
end;
function TFpDwarfSymbolTypeArray.GetMemberAddress(AValObject: TFpDwarfValue;
const AIndex: array of Int64): TFpDbgMemLocation;
var
Idx, Offs, Factor: Int64;
LowBound, HighBound: int64;
i: Integer;
bsize: Integer;
m: TFpDwarfSymbol;
begin
assert((AValObject is TFpDwarfValueArray), 'TFpDwarfSymbolTypeArray.GetMemberAddress AValObject');
ReadOrdering;
ReadStride; // TODO Stride per member (member = dimension/index)
Result := InvalidLoc;
if (FStrideInBits <= 0) or (FStrideInBits mod 8 <> 0) then
exit;
CreateMembers;
if Length(AIndex) > FMembers.Count then
exit;
if AValObject is TFpDwarfValueArray then begin
if not TFpDwarfValueArray(AValObject).GetDwarfDataAddress(Result, Self) then begin
Result := InvalidLoc;
Exit;
end;
end
else
exit; // TODO error
Offs := 0;
Factor := 1;
{$PUSH}{$R-}{$Q-} // TODO: check range of index
bsize := FStrideInBits div 8;
if FRowMajor then begin
for i := Length(AIndex) - 1 downto 0 do begin
Idx := AIndex[i];
m := TFpDwarfSymbol(FMembers[i]);
if ((m is TFpDwarfSymbolType) and (TFpDwarfSymbolType(m).GetValueBounds(AValObject, LowBound, HighBound))) or
m.HasBounds then begin
Idx := Idx - m.OrdLowBound;
end;
Offs := Offs + Idx * bsize * Factor;
if i > 0 then begin
if not m.HasBounds then begin
Result := InvalidLoc;
exit;
end;
// TODO range check
Factor := Factor * (m.OrdHighBound - m.OrdLowBound + 1);
end;
end;
end
else begin
for i := 0 to Length(AIndex) - 1 do begin
Idx := AIndex[i];
m := TFpDwarfSymbol(FMembers[i]);
if m.HasBounds then begin
Idx := Idx - m.OrdLowBound;
end;
Offs := Offs + Idx * bsize * Factor;
if i < Length(AIndex) - 1 then begin
if not m.HasBounds then begin
Result := InvalidLoc;
exit;
end;
Factor := Factor * (m.OrdHighBound - m.OrdLowBound + 1);
end;
end;
end;
assert(IsTargetAddr(Result), 'DwarfArray MemberAddress');
Result.Address := Result.Address + Offs;
{$POP}
end;
destructor TFpDwarfSymbolTypeArray.Destroy;
var
i: Integer;
begin
if FMembers <> nil then begin
for i := 0 to FMembers.Count - 1 do
TFpDwarfSymbol(FMembers[i]).ParentTypeInfo := nil;
FreeAndNil(FMembers);
end;
inherited Destroy;
end;
procedure TFpDwarfSymbolTypeArray.ResetValueBounds;
var
i: Integer;
begin
debuglnEnter(['TFpDwarfSymbolTypeArray.ResetValueBounds ' , Self.ClassName, dbgs(self)]); try
inherited ResetValueBounds;
FDwarfArrayReadFlags := [];
if FMembers <> nil then
for i := 0 to FMembers.Count - 1 do
if TObject(FMembers[i]) is TFpDwarfSymbolType then
TFpDwarfSymbolType(FMembers[i]).ResetValueBounds;
finally debuglnExit(['TFpDwarfSymbolTypeArray.ResetValueBounds ' ]); end;
end;
{ TDbgDwarfSymbol }
constructor TFpDwarfSymbolValueProc.Create(ACompilationUnit: TDwarfCompilationUnit;
AInfo: PDwarfAddressInfo; AAddress: TDbgPtr);
var
InfoEntry: TDwarfInformationEntry;
begin
FAddress := AAddress;
FAddressInfo := AInfo;
InfoEntry := TDwarfInformationEntry.Create(ACompilationUnit, nil);
InfoEntry.ScopeIndex := AInfo^.ScopeIndex;
inherited Create(
String(FAddressInfo^.Name),
InfoEntry
);
SetAddress(TargetLoc(FAddressInfo^.StartPC));
InfoEntry.ReleaseReference;
//BuildLineInfo(
// AFile: String = ''; ALine: Integer = -1; AFlags: TDbgSymbolFlags = []; const AReference: TDbgSymbol = nil);
end;
destructor TFpDwarfSymbolValueProc.Destroy;
begin
FreeAndNil(FProcMembers);
FLastMember.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FLastMember, 'TFpDwarfSymbolValueProc.FLastMember'){$ENDIF};
FreeAndNil(FStateMachine);
if FSelfParameter <> nil then begin
//TDbgDwarfIdentifier(FSelfParameter.DbgSymbol).ParentTypeInfo := nil;
FSelfParameter.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSelfParameter, 'FSelfParameter'){$ENDIF};
end;
inherited Destroy;
end;
function TFpDwarfSymbolValueProc.GetColumn: Cardinal;
begin
if StateMachineValid
then Result := FStateMachine.Column
else Result := inherited GetColumn;
end;
function TFpDwarfSymbolValueProc.GetFile: String;
begin
if StateMachineValid
then Result := FStateMachine.FileName
else Result := inherited GetFile;
end;
function TFpDwarfSymbolValueProc.GetLine: Cardinal;
begin
if StateMachineValid
then Result := FStateMachine.Line
else Result := inherited GetLine;
end;
function TFpDwarfSymbolValueProc.GetValueObject: TFpDbgValue;
begin
Result := FValueObject;
if Result <> nil then exit;
FValueObject := TFpDwarfValue.Create(nil);
{$IFDEF WITH_REFCOUNT_DEBUG}FValueObject.DbgRenameReference(@FValueObject, ClassName+'.FValueObject');{$ENDIF}
FValueObject.MakePlainRefToCirclular;
FValueObject.SetValueSymbol(self);
Result := FValueObject;
end;
function TFpDwarfSymbolValueProc.StateMachineValid: Boolean;
var
SM1, SM2: TDwarfLineInfoStateMachine;
begin
Result := FStateMachine <> nil;
if Result then Exit;
if FAddressInfo^.StateMachine = nil
then begin
CompilationUnit.BuildLineInfo(FAddressInfo, False);
if FAddressInfo^.StateMachine = nil then Exit;
end;
// we cannot restore a statemachine to its current state
// so we shouldn't modify FAddressInfo^.StateMachine
// so use clones to navigate
SM1 := FAddressInfo^.StateMachine.Clone;
if FAddress < SM1.Address
then begin
// The address we want to find is before the start of this symbol ??
SM1.Free;
Exit;
end;
SM2 := FAddressInfo^.StateMachine.Clone;
repeat
if (FAddress = SM1.Address)
or not SM2.NextLine
or (FAddress < SM2.Address)
then begin
// found
FStateMachine := SM1;
SM2.Free;
Result := True;
Exit;
end;
until not SM1.NextLine;
//if all went well we shouldn't come here
SM1.Free;
SM2.Free;
end;
function TFpDwarfSymbolValueProc.ReadVirtuality(out AFlags: TDbgSymbolFlags): Boolean;
var
Val: Integer;
begin
AFlags := [];
Result := InformationEntry.ReadValue(DW_AT_virtuality, Val);
if not Result then exit;
case Val of
DW_VIRTUALITY_none: ;
DW_VIRTUALITY_virtual: AFlags := [sfVirtual];
DW_VIRTUALITY_pure_virtual: AFlags := [sfVirtual];
end;
end;
procedure TFpDwarfSymbolValueProc.CreateMembers;
var
Info: TDwarfInformationEntry;
Info2: TDwarfInformationEntry;
begin
if FProcMembers <> nil then
exit;
FProcMembers := TRefCntObjList.Create;
Info := InformationEntry.Clone;
Info.GoChild;
while Info.HasValidScope do begin
if ((Info.AbbrevTag = DW_TAG_formal_parameter) or (Info.AbbrevTag = DW_TAG_variable)) //and
//not(Info.IsArtificial)
then begin
Info2 := Info.Clone;
FProcMembers.Add(Info2);
Info2.ReleaseReference;
end;
Info.GoNext;
end;
Info.ReleaseReference;
end;
function TFpDwarfSymbolValueProc.GetMember(AIndex: Int64): TFpDbgSymbol;
begin
CreateMembers;
FLastMember.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FLastMember, 'TFpDwarfSymbolValueProc.FLastMember'){$ENDIF};
FLastMember := TFpDwarfSymbol.CreateSubClass('', TDwarfInformationEntry(FProcMembers[AIndex]));
{$IFDEF WITH_REFCOUNT_DEBUG}FLastMember.DbgRenameReference(@FLastMember, 'TFpDwarfSymbolValueProc.FLastMember');{$ENDIF}
Result := FLastMember;
end;
function TFpDwarfSymbolValueProc.GetMemberByName(AIndex: String): TFpDbgSymbol;
var
Info: TDwarfInformationEntry;
s, s2: String;
i: Integer;
begin
CreateMembers;
s2 := LowerCase(AIndex);
FLastMember.ReleaseReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FLastMember, 'TFpDwarfSymbolValueProc.FLastMember'){$ENDIF};
FLastMember := nil;;
for i := 0 to FProcMembers.Count - 1 do begin
Info := TDwarfInformationEntry(FProcMembers[i]);
if Info.ReadName(s) and (LowerCase(s) = s2) then begin
FLastMember := TFpDwarfSymbol.CreateSubClass('', Info);
{$IFDEF WITH_REFCOUNT_DEBUG}FLastMember.DbgRenameReference(@FLastMember, 'TFpDwarfSymbolValueProc.FLastMember');{$ENDIF}
break;
end;
end;
Result := FLastMember;
end;
function TFpDwarfSymbolValueProc.GetMemberCount: Integer;
begin
CreateMembers;
Result := FProcMembers.Count;
end;
function TFpDwarfSymbolValueProc.GetFrameBase(ASender: TDwarfLocationExpression): TDbgPtr;
var
Val: TByteDynArray;
begin
Result := 0;
if FFrameBaseParser = nil then begin
//TODO: avoid copying data
if not InformationEntry.ReadValue(DW_AT_frame_base, Val) then begin
// error
debugln(FPDBG_DWARF_ERRORS, ['TFpDwarfSymbolValueProc.GetFrameBase failed to read DW_AT_frame_base']);
exit;
end;
if Length(Val) = 0 then begin
// error
debugln(FPDBG_DWARF_ERRORS, ['TFpDwarfSymbolValueProc.GetFrameBase failed to read DW_AT_location']);
exit;
end;
FFrameBaseParser := TDwarfLocationExpression.Create(@Val[0], Length(Val), CompilationUnit,
ASender.MemManager, ASender.Context);
FFrameBaseParser.Evaluate;
end;
if FFrameBaseParser.ResultKind in [lseValue] then
Result := FFrameBaseParser.ResultData;
if IsError(FFrameBaseParser.LastError) then begin
SetLastError(FFrameBaseParser.LastError);
debugln(FPDBG_DWARF_ERRORS, ['TFpDwarfSymbolValueProc.GetFrameBase location parser failed ', ErrorHandler.ErrorAsString(LastError)]);
end
else
if Result = 0 then begin
debugln(FPDBG_DWARF_ERRORS, ['TFpDwarfSymbolValueProc.GetFrameBase location parser failed. result is 0']);
end;
end;
procedure TFpDwarfSymbolValueProc.KindNeeded;
begin
if TypeInfo <> nil then
SetKind(skFunction)
else
SetKind(skProcedure);
end;
procedure TFpDwarfSymbolValueProc.SizeNeeded;
begin
SetSize(FAddressInfo^.EndPC - FAddressInfo^.StartPC);
end;
function TFpDwarfSymbolValueProc.GetFlags: TDbgSymbolFlags;
var
flg: TDbgSymbolFlags;
begin
Result := inherited GetFlags;
if ReadVirtuality(flg) then
Result := Result + flg;
end;
function TFpDwarfSymbolValueProc.GetSelfParameter(AnAddress: TDbgPtr): TFpDwarfValue;
const
this1: string = 'THIS';
this2: string = 'this';
self1: string = '$SELF';
self2: string = '$self';
var
InfoEntry: TDwarfInformationEntry;
tg: Cardinal;
found: Boolean;
begin
// special: search "self"
// Todo nested procs
Result := FSelfParameter;
if Result <> nil then exit;
InfoEntry := InformationEntry.Clone;
//StartScopeIdx := InfoEntry.ScopeIndex;
InfoEntry.GoParent;
tg := InfoEntry.AbbrevTag;
if (tg = DW_TAG_class_type) or (tg = DW_TAG_structure_type) then begin
InfoEntry.ScopeIndex := InformationEntry.ScopeIndex;
found := InfoEntry.GoNamedChildEx(@this1[1], @this2[1]);
if not found then begin
InfoEntry.ScopeIndex := InformationEntry.ScopeIndex;
found := InfoEntry.GoNamedChildEx(@self1[1], @self2[1]);
end;
if found then begin
if ((AnAddress = 0) or InfoEntry.IsAddressInStartScope(AnAddress)) and
InfoEntry.IsArtificial
then begin
Result := TFpDwarfValue(TFpDwarfSymbolValue.CreateValueSubClass('self', InfoEntry).Value);
FSelfParameter := Result;
FSelfParameter.AddReference{$IFDEF WITH_REFCOUNT_DEBUG}(@FSelfParameter, 'FSelfParameter'){$ENDIF};
FSelfParameter.DbgSymbol.ReleaseReference;
//FSelfParameter.DbgSymbol.ParentTypeInfo := Self;
debugln(FPDBG_DWARF_SEARCH, ['TFpDwarfSymbolValueProc.GetSelfParameter ', InfoEntry.ScopeDebugText, DbgSName(Result)]);
end;
end;
end;
InfoEntry.ReleaseReference;
end;
{ TFpDwarfSymbolValueVariable }
function TFpDwarfSymbolValueVariable.GetValueAddress(AValueObj: TFpDwarfValue; out
AnAddress: TFpDbgMemLocation): Boolean;
begin
AnAddress := AValueObj.DataAddressCache[0];
Result := IsValidLoc(AnAddress);
if IsInitializedLoc(AnAddress) then
exit;
Result := LocationFromTag(DW_AT_location, AValueObj, AnAddress);
AValueObj.DataAddressCache[0] := AnAddress;
end;
function TFpDwarfSymbolValueVariable.HasAddress: Boolean;
begin
Result := InformationEntry.HasAttrib(DW_AT_location);
end;
{ TFpDwarfSymbolValueParameter }
function TFpDwarfSymbolValueParameter.GetValueAddress(AValueObj: TFpDwarfValue; out
AnAddress: TFpDbgMemLocation): Boolean;
begin
AnAddress := AValueObj.DataAddressCache[0];
Result := IsValidLoc(AnAddress);
if IsInitializedLoc(AnAddress) then
exit;
Result := LocationFromTag(DW_AT_location, AValueObj, AnAddress);
AValueObj.DataAddressCache[0] := AnAddress;
end;
function TFpDwarfSymbolValueParameter.HasAddress: Boolean;
begin
Result := InformationEntry.HasAttrib(DW_AT_location);
end;
function TFpDwarfSymbolValueParameter.GetFlags: TDbgSymbolFlags;
begin
Result := (inherited GetFlags) + [sfParameter];
end;
{ TFpDwarfSymbolUnit }
procedure TFpDwarfSymbolUnit.Init;
begin
inherited Init;
SetSymbolType(stNone);
SetKind(skUnit);
end;
function TFpDwarfSymbolUnit.GetMemberByName(AIndex: String): TFpDbgSymbol;
var
Ident: TDwarfInformationEntry;
begin
// Todo, param to only search external.
ReleaseRefAndNil(FLastChildByName);
Result := nil;
Ident := InformationEntry.Clone;
Ident.GoNamedChildEx(AIndex);
if Ident <> nil then
Result := TFpDwarfSymbol.CreateSubClass('', Ident);
// No need to set ParentTypeInfo
ReleaseRefAndNil(Ident);
FLastChildByName := Result;
end;
destructor TFpDwarfSymbolUnit.Destroy;
begin
ReleaseRefAndNil(FLastChildByName);
inherited Destroy;
end;
initialization
DwarfSymbolClassMapList.SetDefaultMap(TFpDwarfDefaultSymbolClassMap);
FPDBG_DWARF_VERBOSE := DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_VERBOSE' {$IFDEF FPDBG_DWARF_VERBOSE} , True {$ENDIF} );
FPDBG_DWARF_ERRORS := DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_ERRORS' {$IFDEF FPDBG_DWARF_ERRORS} , True {$ENDIF} );
FPDBG_DWARF_WARNINGS := DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_WARNINGS' {$IFDEF FPDBG_DWARF_WARNINGS} , True {$ENDIF} );
FPDBG_DWARF_SEARCH := DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_SEARCH' {$IFDEF FPDBG_DWARF_SEARCH} , True {$ENDIF} );
FPDBG_DWARF_DATA_WARNINGS := DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_DATA_WARNINGS' {$IFDEF FPDBG_DWARF_DATA_WARNINGS} , True {$ENDIF} );
end.
|