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
|
/*
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.0 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://xdebug.derickrethans.nl/license.php |
| If you did not receive a copy of the Xdebug license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| xdebug@derickrethans.nl so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Derick Rethans <derick@xdebug.org> |
| Ilia Alshanetsky <ilia@prohost.org> |
| Harald Radi <harald.radi@nme.at> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "main/php_version.h"
#include "xdebug_compat.h"
#if HAVE_XDEBUG
#ifndef PHP_WIN32
#include <sys/time.h>
#include <unistd.h>
#else
#include "win32/time.h"
#include <process.h>
#endif
#include "TSRM.h"
#include "SAPI.h"
#include "main/php_ini.h"
#include "ext/standard/head.h"
#include "ext/standard/html.h"
#include "ext/standard/info.h"
#include "ext/standard/php_smart_str.h"
#include "php_globals.h"
#include "ext/standard/php_var.h"
#include "zend.h"
#include "zend_API.h"
#include "zend_alloc.h"
#include "zend_execute.h"
#include "zend_compile.h"
#include "zend_constants.h"
#include "zend_extensions.h"
#ifdef ZEND_ENGINE_2
# include "zend_exceptions.h"
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
# include "zend_vm.h"
# endif
#endif
#include "php_xdebug.h"
#include "xdebug_private.h"
#include "xdebug_code_coverage.h"
#include "xdebug_com.h"
#include "xdebug_llist.h"
#include "xdebug_mm.h"
#include "xdebug_var.h"
#include "xdebug_profiler.h"
#include "xdebug_superglobals.h"
#include "usefulstuff.h"
/* execution redirection functions */
zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type TSRMLS_DC);
zend_op_array* xdebug_compile_file(zend_file_handle*, int TSRMLS_DC);
void (*xdebug_old_execute)(zend_op_array *op_array TSRMLS_DC);
void xdebug_execute(zend_op_array *op_array TSRMLS_DC);
void (*xdebug_old_execute_internal)(zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
void xdebug_execute_internal(zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
/* error callback repalcement functions */
void (*old_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
void (*new_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
#ifdef ZEND_ENGINE_2
void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
#endif
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0)
int (*old_exit_handler)(ZEND_OPCODE_HANDLER_ARGS);
#endif
#ifdef ZEND_ENGINE_2
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
#endif
static zval *get_zval(zend_execute_data *zdata, znode *node, temp_variable *Ts, int *is_var);
static char* return_trace_stack_frame_begin(function_stack_entry* i, int fnr TSRMLS_DC);
static char* return_trace_stack_frame_end(function_stack_entry* i, int fnr TSRMLS_DC);
static char* return_trace_stack_retval(function_stack_entry* i, zval* retval TSRMLS_DC);
int zend_xdebug_initialised = 0;
function_entry xdebug_functions[] = {
PHP_FE(xdebug_get_stack_depth, NULL)
PHP_FE(xdebug_get_function_stack, NULL)
PHP_FE(xdebug_print_function_stack, NULL)
PHP_FE(xdebug_get_declared_vars, NULL)
PHP_FE(xdebug_call_class, NULL)
PHP_FE(xdebug_call_function, NULL)
PHP_FE(xdebug_call_file, NULL)
PHP_FE(xdebug_call_line, NULL)
PHP_FE(xdebug_var_dump, NULL)
PHP_FE(xdebug_debug_zval, NULL)
PHP_FE(xdebug_debug_zval_stdout, NULL)
PHP_FE(xdebug_enable, NULL)
PHP_FE(xdebug_disable, NULL)
PHP_FE(xdebug_is_enabled, NULL)
PHP_FE(xdebug_break, NULL)
PHP_FE(xdebug_start_trace, NULL)
PHP_FE(xdebug_stop_trace, NULL)
PHP_FE(xdebug_get_tracefile_name, NULL)
PHP_FE(xdebug_get_profiler_filename, NULL)
PHP_FE(xdebug_dump_aggr_profiling_data, NULL)
PHP_FE(xdebug_clear_aggr_profiling_data, NULL)
#if HAVE_PHP_MEMORY_USAGE
PHP_FE(xdebug_memory_usage, NULL)
PHP_FE(xdebug_peak_memory_usage, NULL)
#endif
PHP_FE(xdebug_time_index, NULL)
PHP_FE(xdebug_start_code_coverage, NULL)
PHP_FE(xdebug_stop_code_coverage, NULL)
PHP_FE(xdebug_get_code_coverage, NULL)
PHP_FE(xdebug_get_function_count, NULL)
PHP_FE(xdebug_dump_superglobals, NULL)
{NULL, NULL, NULL}
};
zend_module_entry xdebug_module_entry = {
STANDARD_MODULE_HEADER,
"xdebug",
xdebug_functions,
PHP_MINIT(xdebug),
PHP_MSHUTDOWN(xdebug),
PHP_RINIT(xdebug),
#ifndef ZEND_ENGINE_2
PHP_RSHUTDOWN(xdebug),
#else
NULL,
#endif
PHP_MINFO(xdebug),
XDEBUG_VERSION,
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6
NO_MODULE_GLOBALS,
#endif
#ifdef ZEND_ENGINE_2
ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xdebug),
#else
NULL,
#endif
STANDARD_MODULE_PROPERTIES_EX
};
ZEND_DECLARE_MODULE_GLOBALS(xdebug)
#if COMPILE_DL_XDEBUG
ZEND_GET_MODULE(xdebug)
#endif
static PHP_INI_MH(OnUpdateServer)
{
DUMP_TOK(server);
}
static PHP_INI_MH(OnUpdateGet)
{
DUMP_TOK(get);
}
static PHP_INI_MH(OnUpdatePost)
{
DUMP_TOK(post);
}
static PHP_INI_MH(OnUpdateCookie)
{
DUMP_TOK(cookie);
}
static PHP_INI_MH(OnUpdateFiles)
{
DUMP_TOK(files);
}
static PHP_INI_MH(OnUpdateEnv)
{
DUMP_TOK(env);
}
static PHP_INI_MH(OnUpdateRequest)
{
DUMP_TOK(request);
}
static PHP_INI_MH(OnUpdateSession)
{
DUMP_TOK(session);
}
static PHP_INI_MH(OnUpdateIDEKey)
{
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
if (!new_value) {
XG(ide_key) = NULL;
} else {
XG(ide_key) = xdstrdup(new_value);
}
return SUCCESS;
}
static PHP_INI_MH(OnUpdateDebugMode)
{
if (!new_value) {
XG(remote_mode) = XDEBUG_NONE;
} else if (strcmp(new_value, "jit") == 0) {
XG(remote_mode) = XDEBUG_JIT;
} else if (strcmp(new_value, "req") == 0) {
XG(remote_mode) = XDEBUG_REQ;
} else {
XG(remote_mode) = XDEBUG_NONE;
}
return SUCCESS;
}
PHP_INI_BEGIN()
/* Debugger settings */
STD_PHP_INI_BOOLEAN("xdebug.auto_trace", "0", PHP_INI_ALL, OnUpdateBool, auto_trace, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_output_dir", "/tmp", PHP_INI_ALL, OnUpdateString, trace_output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_output_name", "trace.%c", PHP_INI_ALL, OnUpdateString, trace_output_name, zend_xdebug_globals, xdebug_globals)
#if ZEND_EXTENSION_API_NO < 90000000
STD_PHP_INI_ENTRY("xdebug.trace_format", "0", PHP_INI_ALL, OnUpdateInt, trace_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_options", "0", PHP_INI_ALL, OnUpdateInt, trace_options, zend_xdebug_globals, xdebug_globals)
#else
STD_PHP_INI_ENTRY("xdebug.trace_format", "0", PHP_INI_ALL, OnUpdateLong, trace_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_options", "0", PHP_INI_ALL, OnUpdateLong, trace_options, zend_xdebug_globals, xdebug_globals)
#endif
STD_PHP_INI_BOOLEAN("xdebug.collect_includes","1", PHP_INI_ALL, OnUpdateBool, collect_includes, zend_xdebug_globals, xdebug_globals)
#if ZEND_EXTENSION_API_NO < 90000000
STD_PHP_INI_ENTRY("xdebug.collect_params", "0", PHP_INI_ALL, OnUpdateInt, collect_params, zend_xdebug_globals, xdebug_globals)
#else
STD_PHP_INI_ENTRY("xdebug.collect_params", "0", PHP_INI_ALL, OnUpdateLong, collect_params, zend_xdebug_globals, xdebug_globals)
#endif
STD_PHP_INI_BOOLEAN("xdebug.collect_return", "0", PHP_INI_ALL, OnUpdateBool, collect_return, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.collect_vars", "0", PHP_INI_ALL, OnUpdateBool, collect_vars, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.default_enable", "1", PHP_INI_ALL, OnUpdateBool, default_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.extended_info", "1", PHP_INI_SYSTEM, OnUpdateBool, extended_info, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.manual_url", "http://www.php.net", PHP_INI_ALL, OnUpdateString, manual_url, zend_xdebug_globals, xdebug_globals)
#if ZEND_EXTENSION_API_NO < 90000000
STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "100", PHP_INI_ALL, OnUpdateInt, max_nesting_level, zend_xdebug_globals, xdebug_globals)
#else
STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "100", PHP_INI_ALL, OnUpdateLong, max_nesting_level, zend_xdebug_globals, xdebug_globals)
#endif
STD_PHP_INI_BOOLEAN("xdebug.show_exception_trace", "0", PHP_INI_ALL, OnUpdateBool, show_ex_trace, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.show_local_vars", "0", PHP_INI_ALL, OnUpdateBool, show_local_vars, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.show_mem_delta", "0", PHP_INI_ALL, OnUpdateBool, show_mem_delta, zend_xdebug_globals, xdebug_globals)
/* Dump superglobals settings */
PHP_INI_ENTRY("xdebug.dump.COOKIE", NULL, PHP_INI_ALL, OnUpdateCookie)
PHP_INI_ENTRY("xdebug.dump.ENV", NULL, PHP_INI_ALL, OnUpdateEnv)
PHP_INI_ENTRY("xdebug.dump.FILES", NULL, PHP_INI_ALL, OnUpdateFiles)
PHP_INI_ENTRY("xdebug.dump.GET", NULL, PHP_INI_ALL, OnUpdateGet)
PHP_INI_ENTRY("xdebug.dump.POST", NULL, PHP_INI_ALL, OnUpdatePost)
PHP_INI_ENTRY("xdebug.dump.REQUEST", NULL, PHP_INI_ALL, OnUpdateRequest)
PHP_INI_ENTRY("xdebug.dump.SERVER", NULL, PHP_INI_ALL, OnUpdateServer)
PHP_INI_ENTRY("xdebug.dump.SESSION", NULL, PHP_INI_ALL, OnUpdateSession)
STD_PHP_INI_BOOLEAN("xdebug.dump_globals", "1", PHP_INI_ALL, OnUpdateBool, dump_globals, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.dump_once", "1", PHP_INI_ALL, OnUpdateBool, dump_once, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.dump_undefined", "0", PHP_INI_ALL, OnUpdateBool, dump_undefined, zend_xdebug_globals, xdebug_globals)
/* Profiler settings */
STD_PHP_INI_BOOLEAN("xdebug.profiler_enable", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.profiler_output_dir", "/tmp", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, profiler_output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.profiler_output_name", "cachegrind.out.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, profiler_output_name, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_enable_trigger", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_enable_trigger, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_append", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_append, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_aggregate", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_aggregate, zend_xdebug_globals, xdebug_globals)
/* Remote debugger settings */
STD_PHP_INI_BOOLEAN("xdebug.remote_enable", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, remote_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_handler", "dbgp", PHP_INI_ALL, OnUpdateString, remote_handler, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_host", "localhost", PHP_INI_ALL, OnUpdateString, remote_host, zend_xdebug_globals, xdebug_globals)
PHP_INI_ENTRY("xdebug.remote_mode", "req", PHP_INI_ALL, OnUpdateDebugMode)
#if ZEND_EXTENSION_API_NO < 90000000
STD_PHP_INI_ENTRY("xdebug.remote_port", "9000", PHP_INI_ALL, OnUpdateInt, remote_port, zend_xdebug_globals, xdebug_globals)
#else
STD_PHP_INI_ENTRY("xdebug.remote_port", "9000", PHP_INI_ALL, OnUpdateLong, remote_port, zend_xdebug_globals, xdebug_globals)
#endif
STD_PHP_INI_BOOLEAN("xdebug.remote_autostart","0", PHP_INI_ALL, OnUpdateBool, remote_autostart, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_log", "", PHP_INI_ALL, OnUpdateString, remote_log, zend_xdebug_globals, xdebug_globals)
PHP_INI_ENTRY("xdebug.idekey", "", PHP_INI_ALL, OnUpdateIDEKey)
/* Variable display settings */
#if ZEND_EXTENSION_API_NO < 90000000
STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128", PHP_INI_ALL, OnUpdateInt, display_max_children, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_data", "512", PHP_INI_ALL, OnUpdateInt, display_max_data, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateInt, display_max_depth, zend_xdebug_globals, xdebug_globals)
#else
STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128", PHP_INI_ALL, OnUpdateLong, display_max_children, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_data", "512", PHP_INI_ALL, OnUpdateLong, display_max_data, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateLong, display_max_depth, zend_xdebug_globals, xdebug_globals)
#endif
PHP_INI_END()
static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
{
xg->stack = NULL;
xg->level = 0;
xg->do_trace = 0;
xg->trace_file = NULL;
xg->do_code_coverage = 0;
xg->breakpoint_count = 0;
xg->ide_key = NULL;
xdebug_llist_init(&xg->server, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->get, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->post, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->cookie, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->files, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->env, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->request, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->session, xdebug_superglobals_dump_dtor);
}
static void php_xdebug_shutdown_globals (zend_xdebug_globals *xg TSRMLS_DC)
{
xdebug_llist_empty(&xg->server, NULL);
xdebug_llist_empty(&xg->get, NULL);
xdebug_llist_empty(&xg->post, NULL);
xdebug_llist_empty(&xg->cookie, NULL);
xdebug_llist_empty(&xg->files, NULL);
xdebug_llist_empty(&xg->env, NULL);
xdebug_llist_empty(&xg->request, NULL);
xdebug_llist_empty(&xg->session, NULL);
}
void xdebug_env_key()
{
char *ide_key = getenv("DBGP_IDEKEY");
if (!ide_key || !*ide_key) {
ide_key = getenv("USER");
if (!ide_key || !*ide_key) {
ide_key = getenv("USERNAME");
}
}
if (ide_key && *ide_key) {
zend_alter_ini_entry("xdebug.idekey", sizeof("xdebug.idekey"), ide_key, strlen(ide_key), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
}
void xdebug_env_config()
{
char *config = getenv("XDEBUG_CONFIG");
xdebug_arg *parts;
int i;
/*
XDEBUG_CONFIG format:
XDEBUG_CONFIG=var=val var=val
*/
xdebug_env_key();
if (!config) {
return;
}
parts = (xdebug_arg*) xdmalloc(sizeof(xdebug_arg));
xdebug_arg_init(parts);
xdebug_explode(" ", config, parts, -1);
for (i = 0; i < parts->c; ++i) {
char *name = NULL;
char *envvar = parts->args[i];
char *envval = NULL;
char *eq = strchr(envvar, '=');
if (!eq || !*eq) {
continue;
}
*eq = 0;
envval = eq + 1;
if (!*envval) {
continue;
}
if (strcasecmp(envvar, "remote_enable") == 0) {
name = "xdebug.remote_enable";
} else
if (strcasecmp(envvar, "remote_port") == 0) {
name = "xdebug.remote_port";
} else
if (strcasecmp(envvar, "remote_host") == 0) {
name = "xdebug.remote_host";
} else
if (strcasecmp(envvar, "remote_handler") == 0) {
name = "xdebug.remote_handler";
} else
if (strcasecmp(envvar, "remote_mode") == 0) {
name = "xdebug.remote_mode";
} else
if (strcasecmp(envvar, "idekey") == 0) {
name = "xdebug.idekey";
} else
if (strcasecmp(envvar, "profiler_enable") == 0) {
name = "xdebug.profiler_enable";
} else
if (strcasecmp(envvar, "profiler_output_dir") == 0) {
name = "xdebug.profiler_output_dir";
} else
if (strcasecmp(envvar, "profiler_output_name") == 0) {
name = "xdebug.profiler_output_name";
} else
if (strcasecmp(envvar, "profiler_enable_trigger") == 0) {
name = "xdebug.profiler_enable_trigger";
} else
if (strcasecmp(envvar, "remote_log") == 0) {
name = "xdebug.remote_log";
}
if (name) {
zend_alter_ini_entry(name, strlen(name) + 1, envval, strlen(envval), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
}
xdebug_arg_dtor(parts);
}
#ifdef ZEND_ENGINE_2
/* Needed for code coverage as Zend doesn't always add EXT_STMT when expected */
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
#define XDEBUG_SET_OPCODE_OVERRIDE(f,oc) \
zend_set_user_opcode_handler(oc, xdebug_##f##_handler);
#define XDEBUG_OPCODE_OVERRIDE(f) static int xdebug_##f##_handler(ZEND_OPCODE_HANDLER_ARGS) \
{ \
if (XG(do_code_coverage)) { \
zend_op *cur_opcode; \
int lineno; \
char *file; \
int file_len; \
zend_op_array *op_array = execute_data->op_array; \
\
cur_opcode = *EG(opline_ptr); \
lineno = cur_opcode->lineno; \
\
file = op_array->filename; \
file_len = strlen(file); \
\
xdebug_count_line(file, lineno, 0, 0 TSRMLS_CC); \
} \
return ZEND_USER_OPCODE_DISPATCH; \
}
#else
#define XDEBUG_SET_OPCODE_OVERRIDE(f,oc) \
old_##f##_handler = zend_opcode_handlers[oc]; \
zend_opcode_handlers[oc] = xdebug_##f##_handler; \
#define XDEBUG_OPCODE_OVERRIDE(f) \
static int (*old_##f##_handler)(ZEND_OPCODE_HANDLER_ARGS); \
static int xdebug_##f##_handler(ZEND_OPCODE_HANDLER_ARGS) \
{ \
if (XG(do_code_coverage)) { \
zend_op *cur_opcode; \
int lineno; \
char *file; \
int file_len; \
\
cur_opcode = *EG(opline_ptr); \
lineno = cur_opcode->lineno; \
\
file = op_array->filename; \
file_len = strlen(file); \
\
xdebug_count_line(file, lineno, 0, 0 TSRMLS_CC); \
} \
return old_##f##_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); \
}
#endif
XDEBUG_OPCODE_OVERRIDE(jmp)
XDEBUG_OPCODE_OVERRIDE(jmpz)
XDEBUG_OPCODE_OVERRIDE(is_identical)
XDEBUG_OPCODE_OVERRIDE(is_not_identical)
XDEBUG_OPCODE_OVERRIDE(is_equal)
XDEBUG_OPCODE_OVERRIDE(is_not_equal)
XDEBUG_OPCODE_OVERRIDE(is_smaller)
XDEBUG_OPCODE_OVERRIDE(is_smaller_or_equal)
XDEBUG_OPCODE_OVERRIDE(assign)
XDEBUG_OPCODE_OVERRIDE(assign_dim)
XDEBUG_OPCODE_OVERRIDE(add_array_element)
XDEBUG_OPCODE_OVERRIDE(return)
XDEBUG_OPCODE_OVERRIDE(ext_stmt)
XDEBUG_OPCODE_OVERRIDE(raise_abstract_error)
XDEBUG_OPCODE_OVERRIDE(send_var)
XDEBUG_OPCODE_OVERRIDE(send_var_no_ref)
XDEBUG_OPCODE_OVERRIDE(send_val)
XDEBUG_OPCODE_OVERRIDE(new)
XDEBUG_OPCODE_OVERRIDE(ext_fcall_begin)
XDEBUG_OPCODE_OVERRIDE(catch)
XDEBUG_OPCODE_OVERRIDE(bool)
XDEBUG_OPCODE_OVERRIDE(add_string)
XDEBUG_OPCODE_OVERRIDE(init_array)
XDEBUG_OPCODE_OVERRIDE(fetch_obj_r)
XDEBUG_OPCODE_OVERRIDE(fetch_obj_w)
XDEBUG_OPCODE_OVERRIDE(fetch_dim_r)
XDEBUG_OPCODE_OVERRIDE(fetch_obj_func_arg)
XDEBUG_OPCODE_OVERRIDE(fetch_dim_func_arg)
XDEBUG_OPCODE_OVERRIDE(fetch_class)
XDEBUG_OPCODE_OVERRIDE(fetch_constant)
XDEBUG_OPCODE_OVERRIDE(concat)
XDEBUG_OPCODE_OVERRIDE(isset_isempty_dim_obj)
XDEBUG_OPCODE_OVERRIDE(pre_inc_obj)
#endif
PHP_MINIT_FUNCTION(xdebug)
{
zend_extension dummy_ext;
ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals);
REGISTER_INI_ENTRIES();
#if 0
#ifdef ZEND_ENGINE_2
# if PHP_MINOR_VERSION >= 1
zend_vm_use_old_executor();
# endif
#endif
#endif
/* initialize aggregate call information hash */
zend_hash_init_ex(&XG(aggr_calls), 50, NULL, (dtor_func_t) xdebug_profile_aggr_call_entry_dtor, 1, 0);
/* Redirect compile and execute functions to our own */
old_compile_file = zend_compile_file;
zend_compile_file = xdebug_compile_file;
xdebug_old_execute = zend_execute;
zend_execute = xdebug_execute;
xdebug_old_execute_internal = zend_execute_internal;
zend_execute_internal = xdebug_execute_internal;
/* Replace error handler callback with our own */
old_error_cb = zend_error_cb;
new_error_cb = xdebug_error_cb;
#ifdef ZEND_ENGINE_2
/* Get reserved offset */
XG(reserved_offset) = zend_get_resource_handle(&dummy_ext);
/* Overload the "exit" opcode */
XDEBUG_SET_OPCODE_OVERRIDE(exit, ZEND_EXIT);
XDEBUG_SET_OPCODE_OVERRIDE(jmp, ZEND_JMP);
XDEBUG_SET_OPCODE_OVERRIDE(jmpz, ZEND_JMPZ);
XDEBUG_SET_OPCODE_OVERRIDE(is_identical, ZEND_IS_IDENTICAL);
XDEBUG_SET_OPCODE_OVERRIDE(is_not_identical, ZEND_IS_NOT_IDENTICAL);
XDEBUG_SET_OPCODE_OVERRIDE(is_equal, ZEND_IS_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE(is_not_equal, ZEND_IS_NOT_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE(is_smaller, ZEND_IS_SMALLER);
XDEBUG_SET_OPCODE_OVERRIDE(is_smaller_or_equal, ZEND_IS_SMALLER_OR_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE(assign, ZEND_ASSIGN);
XDEBUG_SET_OPCODE_OVERRIDE(assign_dim, ZEND_ASSIGN_DIM);
XDEBUG_SET_OPCODE_OVERRIDE(add_array_element, ZEND_ADD_ARRAY_ELEMENT);
XDEBUG_SET_OPCODE_OVERRIDE(return, ZEND_RETURN);
XDEBUG_SET_OPCODE_OVERRIDE(ext_stmt, ZEND_EXT_STMT);
XDEBUG_SET_OPCODE_OVERRIDE(raise_abstract_error, ZEND_RAISE_ABSTRACT_ERROR);
XDEBUG_SET_OPCODE_OVERRIDE(send_var, ZEND_SEND_VAR);
XDEBUG_SET_OPCODE_OVERRIDE(send_var_no_ref, ZEND_SEND_VAR_NO_REF);
XDEBUG_SET_OPCODE_OVERRIDE(send_val, ZEND_SEND_VAL);
XDEBUG_SET_OPCODE_OVERRIDE(new, ZEND_NEW);
XDEBUG_SET_OPCODE_OVERRIDE(ext_fcall_begin, ZEND_EXT_FCALL_BEGIN);
XDEBUG_SET_OPCODE_OVERRIDE(catch, ZEND_CATCH);
XDEBUG_SET_OPCODE_OVERRIDE(bool, ZEND_BOOL);
XDEBUG_SET_OPCODE_OVERRIDE(add_string, ZEND_ADD_STRING);
XDEBUG_SET_OPCODE_OVERRIDE(init_array, ZEND_INIT_ARRAY);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_dim_r, ZEND_FETCH_DIM_R);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_obj_r, ZEND_FETCH_OBJ_R);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_obj_w, ZEND_FETCH_OBJ_W);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_obj_func_arg, ZEND_FETCH_OBJ_FUNC_ARG);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_dim_func_arg, ZEND_FETCH_DIM_FUNC_ARG);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_class, ZEND_FETCH_CLASS);
XDEBUG_SET_OPCODE_OVERRIDE(fetch_constant, ZEND_FETCH_CONSTANT);
XDEBUG_SET_OPCODE_OVERRIDE(concat, ZEND_CONCAT);
XDEBUG_SET_OPCODE_OVERRIDE(isset_isempty_dim_obj, ZEND_ISSET_ISEMPTY_DIM_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE(pre_inc_obj, ZEND_PRE_INC_OBJ);
#endif
if (zend_xdebug_initialised == 0) {
zend_error(E_WARNING, "Xdebug MUST be loaded as a Zend extension");
}
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_APPEND", XDEBUG_TRACE_OPTION_APPEND, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_COMPUTERIZED", XDEBUG_TRACE_OPTION_COMPUTERIZED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_HTML", XDEBUG_TRACE_OPTION_HTML, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT);
XG(breakpoint_count) = 0;
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(xdebug)
{
if (XG(profiler_aggregate)) {
xdebug_profiler_output_aggr_data(NULL TSRMLS_CC);
}
/* Reset compile, execute and error callbacks */
zend_compile_file = old_compile_file;
zend_execute = xdebug_old_execute;
zend_execute_internal = xdebug_old_execute_internal;
zend_error_cb = old_error_cb;
zend_hash_destroy(&XG(aggr_calls));
#ifdef ZTS
ts_free_id(xdebug_globals_id);
#else
php_xdebug_shutdown_globals(&xdebug_globals TSRMLS_CC);
#endif
return SUCCESS;
}
static void xdebug_used_var_dtor(void *dummy, void *elem)
{
char *s = elem;
if (s) {
xdfree(s);
}
}
static void xdebug_stack_element_dtor(void *dummy, void *elem)
{
int i;
function_stack_entry *e = elem;
e->refcount--;
if (e->refcount == 0) {
if (e->function.function) {
xdfree(e->function.function);
}
if (e->function.class) {
xdfree(e->function.class);
}
if (e->filename) {
xdfree(e->filename);
}
if (e->var) {
for (i = 0; i < e->varc; i++) {
if (e->var[i].name) {
xdfree(e->var[i].name);
}
}
xdfree(e->var);
}
if (e->include_filename) {
xdfree(e->include_filename);
}
if (e->used_vars) {
xdebug_llist_destroy(e->used_vars, NULL);
}
if (e->profile.call_list) {
xdebug_llist_destroy(e->profile.call_list, NULL);
}
xdfree(e);
}
}
#if PHP_VERSION_ID >= 50200
#define COOKIE_ENCODE , 1, 0
#elif PHP_API_VERSION >= 20030820
#define COOKIE_ENCODE , 1
#else
#define COOKIE_ENCODE
#endif
PHP_RINIT_FUNCTION(xdebug)
{
zend_function *orig;
char *idekey;
zval **dummy;
/* get xdebug ini entries from the environment also */
xdebug_env_config();
idekey = zend_ini_string("xdebug.idekey", sizeof("xdebug.idekey"), 0);
XG(no_exec) = 0;
XG(level) = 0;
XG(do_trace) = 0;
XG(do_code_coverage) = 0;
XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
XG(stack) = xdebug_llist_alloc(xdebug_stack_element_dtor);
XG(trace_file) = NULL;
XG(tracefile_name) = NULL;
XG(profile_file) = NULL;
XG(profile_filename) = NULL;
XG(prev_memory) = 0;
XG(function_count) = 0;
XG(active_symbol_table) = NULL;
XG(last_exception_trace) = NULL;
if (idekey && *idekey) {
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
XG(ide_key) = xdstrdup(idekey);
}
/* Check if we have this special get variable that stops a debugging
* request without executing any code */
if (
(
(
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, "XDEBUG_SESSION_STOP_NO_EXEC", sizeof("XDEBUG_SESSION_STOP_NO_EXEC"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, "XDEBUG_SESSION_STOP_NO_EXEC", sizeof("XDEBUG_SESSION_STOP_NO_EXEC"), (void **) &dummy) == SUCCESS
)
)
&& !SG(headers_sent)
) {
php_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), "", 0, time(NULL) + 3600, "/", 1, NULL, 0, 0 COOKIE_ENCODE TSRMLS_CC);
XG(no_exec) = 1;
}
/* Only enabled extended info when it is not disabled */
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
CG(compiler_options) = CG(compiler_options) | (XG(extended_info) ? ZEND_COMPILE_EXTENDED_INFO : 0);
#else
CG(extended_info) = XG(extended_info);
#endif
if (XG(default_enable)) {
zend_error_cb = new_error_cb;
#ifdef ZEND_ENGINE_2
zend_throw_exception_hook = xdebug_throw_exception_hook;
#endif
}
XG(remote_enabled) = 0;
XG(profiler_enabled) = 0;
XG(breakpoints_allowed) = 1;
if (XG(auto_trace) && XG(trace_output_dir) && strlen(XG(trace_output_dir))) {
/* In case we do an auto-trace we are not interested in the return
* value, but we still have to free it. */
xdfree(xdebug_start_trace(NULL, XG(trace_options) TSRMLS_CC));
}
/* Initialize some debugger context properties */
XG(context).program_name = NULL;
XG(context).list.last_file = NULL;
XG(context).list.last_line = 0;
XG(context).do_break = 0;
XG(context).do_step = 0;
XG(context).do_next = 0;
XG(context).do_finish = 0;
/* Initialize dump superglobals */
XG(dumped) = 0;
/* Initialize start time */
XG(start_time) = xdebug_get_utime();
/* Override var_dump with our own function */
zend_hash_find(EG(function_table), "var_dump", 9, (void **)&orig);
XG(orig_var_dump_func) = orig->internal_function.handler;
orig->internal_function.handler = zif_xdebug_var_dump;
/* Override set_time_limit with our own function to prevent timing out while debugging */
zend_hash_find(EG(function_table), "set_time_limit", 15, (void **)&orig);
XG(orig_set_time_limit_func) = orig->internal_function.handler;
orig->internal_function.handler = zif_xdebug_set_time_limit;
return SUCCESS;
}
#ifdef ZEND_ENGINE_2
ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug)
{
zend_function *orig;
TSRMLS_FETCH();
#else
PHP_RSHUTDOWN_FUNCTION(xdebug)
{
zend_function *orig;
#endif
if (XG(remote_enabled)) {
XG(context).handler->remote_deinit(&(XG(context)));
xdebug_close_socket(XG(context).socket);
}
if (XG(context).program_name) {
xdfree(XG(context).program_name);
}
xdebug_llist_destroy(XG(stack), NULL);
XG(stack) = NULL;
if (XG(do_trace) && XG(trace_file)) {
xdebug_stop_trace(TSRMLS_C);
}
if (XG(profile_file)) {
fclose(XG(profile_file));
}
if (XG(profile_filename)) {
xdfree(XG(profile_filename));
}
if (XG(ide_key)) {
xdfree(XG(ide_key));
XG(ide_key) = NULL;
}
XG(level) = 0;
XG(do_trace) = 0;
XG(do_code_coverage) = 0;
xdebug_hash_destroy(XG(code_coverage));
if (XG(context.list.last_file)) {
xdfree(XG(context).list.last_file);
}
if (XG(last_exception_trace)) {
xdfree(XG(last_exception_trace));
}
/* Reset var_dump and set_time_limit to the original function */
zend_hash_find(EG(function_table), "var_dump", 9, (void **)&orig);
orig->internal_function.handler = XG(orig_var_dump_func);
zend_hash_find(EG(function_table), "set_time_limit", 15, (void **)&orig);
orig->internal_function.handler = XG(orig_set_time_limit_func);
return SUCCESS;
}
PHP_MINFO_FUNCTION(xdebug)
{
xdebug_remote_handler_info *ptr = xdebug_handlers_get();
php_info_print_table_start();
php_info_print_table_header(2, "xdebug support", "enabled");
php_info_print_table_row(2, "Version", XDEBUG_VERSION);
php_info_print_table_end();
if (zend_xdebug_initialised == 0) {
php_info_print_table_start();
php_info_print_table_header(1, "XDEBUG NOT LOADED AS ZEND EXTENSION");
php_info_print_table_end();
}
php_info_print_table_start();
php_info_print_table_header(2, "Supported protocols", "Revision");
while (ptr->name) {
php_info_print_table_row(2, ptr->description, ptr->handler.get_revision());
ptr++;
}
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC)
{
memset(tmp, 0, sizeof(xdebug_func));
if (edata) {
if (edata->function_state.function->common.function_name) {
#if ZEND_EXTENSION_API_NO < 90000000
if (edata->ce) {
tmp->type = XFUNC_STATIC_MEMBER;
tmp->class = xdstrdup(edata->ce->name);
} else if (edata->object.ptr) {
tmp->type = XFUNC_MEMBER;
tmp->class = xdstrdup(edata->object.ptr->value.obj.ce->name);
} else {
tmp->type = XFUNC_NORMAL;
}
#else
if (edata->object) {
tmp->type = XFUNC_MEMBER;
if (edata->function_state.function->common.scope) { /* __autoload has no scope */
tmp->class = xdstrdup(edata->function_state.function->common.scope->name);
}
} else if (EG(scope) && edata->function_state.function->common.scope && edata->function_state.function->common.scope->name) {
tmp->type = XFUNC_STATIC_MEMBER;
tmp->class = xdstrdup(edata->function_state.function->common.scope->name);
} else {
tmp->type = XFUNC_NORMAL;
}
#endif
tmp->function = xdstrdup(edata->function_state.function->common.function_name);
} else {
switch (edata->opline->op2.u.constant.value.lval) {
case ZEND_EVAL:
tmp->type = XFUNC_EVAL;
break;
case ZEND_INCLUDE:
tmp->type = XFUNC_INCLUDE;
break;
case ZEND_REQUIRE:
tmp->type = XFUNC_REQUIRE;
break;
case ZEND_INCLUDE_ONCE:
tmp->type = XFUNC_INCLUDE_ONCE;
break;
case ZEND_REQUIRE_ONCE:
tmp->type = XFUNC_REQUIRE_ONCE;
break;
default:
tmp->type = XFUNC_UNKNOWN;
break;
}
}
}
}
static void trace_function_begin(function_stack_entry *fse, int function_nr TSRMLS_DC)
{
if (XG(do_trace) && XG(trace_file)) {
char *t = return_trace_stack_frame_begin(fse, function_nr TSRMLS_CC);
if (fprintf(XG(trace_file), "%s", t) < 0) {
fclose(XG(trace_file));
XG(trace_file) = NULL;
} else {
fflush(XG(trace_file));
}
xdfree(t);
}
}
static void trace_function_end(function_stack_entry *fse, int function_nr TSRMLS_DC)
{
if (XG(do_trace) && XG(trace_file)) {
char *t = return_trace_stack_frame_end(fse, function_nr TSRMLS_CC);
if (fprintf(XG(trace_file), "%s", t) < 0) {
fclose(XG(trace_file));
XG(trace_file) = NULL;
} else {
fflush(XG(trace_file));
}
xdfree(t);
}
}
static function_stack_entry *add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type TSRMLS_DC)
{
zend_execute_data *edata = EG(current_execute_data);
function_stack_entry *tmp;
zend_op *cur_opcode;
zval **param;
int i = 0;
char *aggr_key;
int aggr_key_len;
tmp = xdmalloc (sizeof (function_stack_entry));
tmp->var = NULL;
tmp->varc = 0;
tmp->refcount = 1;
tmp->level = XG(level);
tmp->arg_done = 0;
tmp->used_vars = NULL;
tmp->user_defined = type;
tmp->filename = NULL;
tmp->include_filename = NULL;
tmp->profile.call_list = xdebug_llist_alloc(xdebug_profile_call_entry_dtor);
tmp->op_array = op_array;
tmp->symbol_table = NULL;
tmp->execute_data = NULL;
if (edata && edata->op_array) {
/* Normal function calls */
tmp->filename = xdstrdup(edata->op_array->filename);
XG(function_count)++;
} else if (edata &&
edata->prev_execute_data &&
XDEBUG_LLIST_TAIL(XG(stack))
) {
/* Ugly hack for call_user_*() type function calls */
zend_function *tmpf = edata->prev_execute_data->function_state.function;
if (tmpf && (tmpf->common.type != 3) && tmpf->common.function_name) {
if (
(strcmp(tmpf->common.function_name, "call_user_func") == 0) ||
(strcmp(tmpf->common.function_name, "call_user_func_array") == 0) ||
(strcmp(tmpf->common.function_name, "call_user_func_method") == 0) ||
(strcmp(tmpf->common.function_name, "call_user_func_method_array") == 0)
) {
tmp->filename = xdstrdup(((function_stack_entry*) XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack))))->filename);
}
}
XG(function_count)++;
}
if (!tmp->filename) {
/* Includes/main script etc */
tmp->filename = (op_array && op_array->filename) ? xdstrdup(op_array->filename): NULL;
}
/* Call user function locations */
if (!tmp->filename && XDEBUG_LLIST_TAIL(XG(stack)) && XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack))) ) {
tmp->filename = xdstrdup(((function_stack_entry*) XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack))))->filename);
}
#if HAVE_PHP_MEMORY_USAGE
tmp->prev_memory = XG(prev_memory);
tmp->memory = XG_MEMORY_USAGE();
XG(prev_memory) = tmp->memory;
#else
tmp->memory = 0;
tmp->prev_memory = 0;
#endif
tmp->time = xdebug_get_utime();
tmp->lineno = 0;
xdebug_build_fname(&(tmp->function), zdata TSRMLS_CC);
if (!tmp->function.type) {
tmp->function.function = xdstrdup("{main}");
tmp->function.class = NULL;
tmp->function.type = XFUNC_NORMAL;
} else if (tmp->function.type & XFUNC_INCLUDES) {
cur_opcode = *EG(opline_ptr);
tmp->lineno = cur_opcode->lineno;
#if (PHP_MAJOR_VERSION == 6) || \
(PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || \
(PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0 && PHP_RELEASE_VERSION > 3) || \
(PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION == 4 && PHP_RELEASE_VERSION > 0)
if (tmp->function.type == XFUNC_EVAL) {
int is_var;
tmp->include_filename = xdebug_get_zval_value(get_zval(zdata, &zdata->opline->op1, zdata->Ts, &is_var), 0, NULL);
} else if (XG(collect_includes)) {
tmp->include_filename = xdstrdup(zend_get_executed_filename(TSRMLS_C));
}
#endif
} else {
if (edata->opline) {
cur_opcode = edata->opline;
if (cur_opcode) {
tmp->lineno = cur_opcode->lineno;
}
}
if (XG(remote_enabled) || XG(collect_params) || XG(collect_vars)) {
void **p;
int arguments_sent = 0, arguments_wanted = 0, arguments_storage = 0;
/* This calculates how many arguments where sent to a function. It
* works for both internal and user defined functions.
* op_array->num_args works only for user defined functions so
* we're not using that here. */
#if PHP_VERSION_ID >= 50300
void **curpos = NULL;
if ((!edata->opline) || ((edata->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (edata->opline->opcode == ZEND_DO_FCALL))) {
curpos = edata->function_state.arguments;
arguments_sent = (int)(zend_uintptr_t) *curpos;
arguments_wanted = arguments_sent;
p = curpos - arguments_sent;
} else {
p = zend_vm_stack_top(TSRMLS_C) - 1;
arguments_sent = (ulong) *p;
arguments_wanted = arguments_sent;
p = curpos = NULL;
}
#else
if (EG(argument_stack).top >= 2) {
p = EG(argument_stack).top_element - 2;
arguments_sent = (ulong) *p;
arguments_wanted = arguments_sent;
}
#endif
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
if (tmp->user_defined == XDEBUG_EXTERNAL) {
arguments_wanted = op_array->num_args;
}
# endif
if (arguments_wanted > arguments_sent) {
arguments_storage = arguments_wanted;
} else {
arguments_storage = arguments_sent;
}
tmp->var = xdmalloc(arguments_storage * sizeof (xdebug_var));
for (i = 0; i < arguments_sent; i++) {
tmp->var[tmp->varc].name = NULL;
tmp->var[tmp->varc].addr = NULL;
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
/* Because it is possible that more parameters are sent, then
* actually wanted we can only access the name in case there
* is an associated variable to receive the variable here. */
if (tmp->user_defined == XDEBUG_EXTERNAL && i < arguments_wanted) {
if (op_array->arg_info[i].name) {
tmp->var[tmp->varc].name = xdstrdup(op_array->arg_info[i].name);
}
}
# endif
if (XG(collect_params)) {
#if PHP_VERSION_ID >= 50300
if (p) {
param = (zval **) p++;
tmp->var[tmp->varc].addr = *param;
}
#else
param = NULL;
if (zend_ptr_stack_get_arg(tmp->varc + 1, (void**) ¶m TSRMLS_CC) == SUCCESS) {
if (param) {
tmp->var[tmp->varc].addr = *param;
}
}
#endif
}
tmp->varc++;
}
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
/* Sometimes not enough arguments are send to a user defined
* function, so we have to gather only the name for those extra. */
if (tmp->user_defined == XDEBUG_EXTERNAL && arguments_sent < arguments_wanted) {
for (i = arguments_sent; i < arguments_wanted; i++) {
if (op_array->arg_info[i].name) {
tmp->var[tmp->varc].name = xdstrdup(op_array->arg_info[i].name);
}
tmp->var[tmp->varc].addr = NULL;
tmp->varc++;
}
}
# endif
}
}
if (XG(do_code_coverage)) {
xdebug_count_line(tmp->filename, tmp->lineno, 0, 0 TSRMLS_CC);
}
if (XG(profiler_aggregate)) {
char *func_name = xdebug_show_fname(tmp->function, 0, 0 TSRMLS_CC);
aggr_key = xdebug_sprintf("%s.%s.%d", tmp->filename, func_name, tmp->lineno);
aggr_key_len = strlen(aggr_key);
if (zend_hash_find(&XG(aggr_calls), aggr_key, aggr_key_len+1, (void**)&tmp->aggr_entry) == FAILURE) {
xdebug_aggregate_entry xae;
if (tmp->user_defined == XDEBUG_EXTERNAL) {
xae.filename = xdstrdup(tmp->op_array->filename);
} else {
xae.filename = xdstrdup("php:internal");
}
xae.function = func_name;
xae.lineno = tmp->lineno;
xae.user_defined = tmp->user_defined;
xae.call_count = 0;
xae.time_own = 0;
xae.time_inclusive = 0;
xae.call_list = NULL;
zend_hash_add(&XG(aggr_calls), aggr_key, aggr_key_len+1, (void*)&xae, sizeof(xdebug_aggregate_entry), (void**)&tmp->aggr_entry);
}
}
if (XDEBUG_LLIST_TAIL(XG(stack))) {
function_stack_entry *prev = XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack)));
tmp->prev = prev;
if (XG(profiler_aggregate)) {
if (prev->aggr_entry->call_list) {
if (!zend_hash_exists(prev->aggr_entry->call_list, aggr_key, aggr_key_len+1)) {
zend_hash_add(prev->aggr_entry->call_list, aggr_key, aggr_key_len+1, (void*)&tmp->aggr_entry, sizeof(xdebug_aggregate_entry*), NULL);
}
} else {
prev->aggr_entry->call_list = xdmalloc(sizeof(HashTable));
zend_hash_init_ex(prev->aggr_entry->call_list, 1, NULL, NULL, 1, 0);
zend_hash_add(prev->aggr_entry->call_list, aggr_key, aggr_key_len+1, (void*)&tmp->aggr_entry, sizeof(xdebug_aggregate_entry*), NULL);
}
}
} else {
tmp->prev = 0;
}
xdebug_llist_insert_next(XG(stack), XDEBUG_LLIST_TAIL(XG(stack)), tmp);
if (XG(profiler_aggregate)) {
xdfree(aggr_key);
}
return tmp;
}
static void add_used_variables(function_stack_entry *fse, zend_op_array *op_array)
{
int i = 0;
int j = op_array->size;
if (!fse->used_vars) {
fse->used_vars = xdebug_llist_alloc(xdebug_used_var_dtor);
}
/* Check parameters */
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
for (i = 0; i < fse->varc; i++) {
if (fse->var[i].name) {
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(fse->var[i].name));
}
}
# endif
/* opcode scanning time */
while (i < j) {
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
char *cv = NULL;
int cv_len;
if (op_array->opcodes[i].op1.op_type == IS_CV) {
cv = zend_get_compiled_variable_name(op_array, op_array->opcodes[i].op1.u.var, &cv_len);
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(cv));
}
if (op_array->opcodes[i].op2.op_type == IS_CV) {
cv = zend_get_compiled_variable_name(op_array, op_array->opcodes[i].op2.u.var, &cv_len);
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(cv));
}
#else
if (op_array->opcodes[i].opcode == ZEND_FETCH_R || op_array->opcodes[i].opcode == ZEND_FETCH_W) {
if (op_array->opcodes[i].op1.op_type == IS_CONST) {
if (Z_TYPE(op_array->opcodes[i].op1.u.constant) == IS_STRING) {
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(op_array->opcodes[i].op1.u.constant.value.str.val));
} else { /* unusual but not impossible situation */
int use_copy;
zval tmp_zval;
zend_make_printable_zval(&(op_array->opcodes[i].op1.u.constant), &tmp_zval, &use_copy);
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(tmp_zval.value.str.val));
zval_dtor(&tmp_zval);
}
}
}
#endif
i++;
}
}
static int handle_hit_value(xdebug_brk_info *brk_info)
{
/* Increase hit counter */
brk_info->hit_count++;
/* If the hit_value is 0, the condition check is disabled */
if (!brk_info->hit_value) {
return 1;
}
switch (brk_info->hit_condition) {
case XDEBUG_HIT_GREATER_EQUAL:
if (brk_info->hit_count >= brk_info->hit_value) {
return 1;
}
break;
case XDEBUG_HIT_EQUAL:
if (brk_info->hit_count == brk_info->hit_value) {
return 1;
}
break;
case XDEBUG_HIT_MOD:
if (brk_info->hit_count % brk_info->hit_value == 0) {
return 1;
}
break;
case XDEBUG_HIT_DISABLED:
return 1;
break;
}
return 0;
}
static int handle_breakpoints(function_stack_entry *fse, int breakpoint_type)
{
xdebug_brk_info *extra_brk_info = NULL;
char *tmp_name = NULL;
TSRMLS_FETCH();
/* Function breakpoints */
if (fse->function.type == XFUNC_NORMAL) {
if (xdebug_hash_find(XG(context).function_breakpoints, fse->function.function, strlen(fse->function.function), (void *) &extra_brk_info)) {
/* Yup, breakpoint found, we call the handler when it's not
* disabled AND handle_hit_value is happy */
if (!extra_brk_info->disabled && (extra_brk_info->function_break_type == breakpoint_type)) {
if (handle_hit_value(extra_brk_info)) {
if (fse->user_defined == XDEBUG_INTERNAL || (breakpoint_type == XDEBUG_BRK_FUNC_RETURN)) {
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), fse->filename, fse->lineno, XDEBUG_BREAK, NULL, NULL)) {
return 0;
}
} else {
XG(context).do_break = 1;
}
}
}
}
}
/* class->function breakpoints */
else if (fse->function.type == XFUNC_MEMBER || fse->function.type == XFUNC_STATIC_MEMBER) {
tmp_name = xdebug_sprintf("%s::%s", fse->function.class, fse->function.function);
if (xdebug_hash_find(XG(context).class_breakpoints, tmp_name, strlen(tmp_name), (void *) &extra_brk_info)) {
/* Yup, breakpoint found, call handler if the breakpoint is not
* disabled AND handle_hit_value is happy */
if (!extra_brk_info->disabled) {
if (handle_hit_value(extra_brk_info)) {
XG(context).do_break = 1;
}
}
}
xdfree(tmp_name);
}
return 1;
}
void xdebug_execute(zend_op_array *op_array TSRMLS_DC)
{
zval **dummy;
zend_execute_data *edata = EG(current_execute_data);
function_stack_entry *fse, *xfse;
char *magic_cookie = NULL;
int do_return = (XG(do_trace) && XG(trace_file));
int function_nr = 0;
xdebug_llist_element *le;
int eval_id = 0;
if (XG(no_exec) == 1) {
php_printf("DEBUG SESSION ENDED");
return;
}
if (!XG(context).program_name) {
XG(context).program_name = xdstrdup(op_array->filename);
}
if (XG(level) == 0) {
/* Set session cookie if requested */
if (
((
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START"), (void **) &dummy) == SUCCESS
))
&& !SG(headers_sent)
) {
convert_to_string_ex(dummy);
magic_cookie = xdstrdup(Z_STRVAL_PP(dummy));
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
XG(ide_key) = xdstrdup(Z_STRVAL_PP(dummy));
php_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), Z_STRVAL_PP(dummy), Z_STRLEN_PP(dummy), time(NULL) + 3600, "/", 1, NULL, 0, 0 COOKIE_ENCODE TSRMLS_CC);
} else if (
PG(http_globals)[TRACK_VARS_COOKIE] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_COOKIE]->value.ht, "XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), (void **) &dummy) == SUCCESS
) {
convert_to_string_ex(dummy);
magic_cookie = xdstrdup(Z_STRVAL_PP(dummy));
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
XG(ide_key) = xdstrdup(Z_STRVAL_PP(dummy));
} else if (getenv("XDEBUG_CONFIG")) {
magic_cookie = xdstrdup(getenv("XDEBUG_CONFIG"));
if (XG(ide_key) && *XG(ide_key) && !SG(headers_sent)) {
php_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), XG(ide_key), strlen(XG(ide_key)), time(NULL) + 3600, "/", 1, NULL, 0, 0 COOKIE_ENCODE TSRMLS_CC);
}
}
/* Remove session cookie if requested */
if (
(
(
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP"), (void **) &dummy) == SUCCESS
)
)
&& !SG(headers_sent)
) {
if (magic_cookie) {
xdfree(magic_cookie);
magic_cookie = NULL;
}
php_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), "", 0, time(NULL) + 3600, "/", 1, NULL, 0, 0 COOKIE_ENCODE TSRMLS_CC);
}
/* Start remote context if requested */
if (
(magic_cookie || XG(remote_autostart)) &&
!XG(remote_enabled) &&
XG(remote_enable) &&
(XG(remote_mode) == XDEBUG_REQ)
) {
/* Initialize debugging session */
XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port));
if (XG(context).socket >= 0) {
XG(remote_enabled) = 1;
/* Get handler from mode */
XG(context).handler = xdebug_handler_get(XG(remote_handler));
if (!XG(context).handler) {
XG(remote_enabled) = 0;
zend_error(E_WARNING, "The remote debug handler '%s' is not supported.", XG(remote_handler));
} else if (!XG(context).handler->remote_init(&(XG(context)), XDEBUG_REQ)) {
/* The request could not be started, ignore it then */
XG(remote_enabled) = 0;
} else {
/* All is well, turn off script time outs */
zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), "0", strlen("0"), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
}
}
if (magic_cookie) {
xdfree(magic_cookie);
magic_cookie = NULL;
}
/* Check for special GET/POST parameter to start profiling */
if (
!XG(profiler_enabled) &&
(
XG(profiler_enable)
||
(
XG(profiler_enable_trigger) &&
(
(
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, "XDEBUG_PROFILE", sizeof("XDEBUG_PROFILE"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, "XDEBUG_PROFILE", sizeof("XDEBUG_PROFILE"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_COOKIE] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_COOKIE]->value.ht, "XDEBUG_PROFILE", sizeof("XDEBUG_PROFILE"), (void **) &dummy) == SUCCESS
)
)
)
)
) {
if (xdebug_profiler_init(op_array->filename TSRMLS_CC) == SUCCESS) {
XG(profiler_enabled) = 1;
}
}
}
XG(level)++;
if (XG(level) == XG(max_nesting_level)) {
php_error(E_ERROR, "Maximum function nesting level of '%ld' reached, aborting!", XG(max_nesting_level));
}
fse = add_stack_frame(edata, op_array, XDEBUG_EXTERNAL TSRMLS_CC);
function_nr = XG(function_count);
trace_function_begin(fse, function_nr TSRMLS_CC);
fse->symbol_table = EG(active_symbol_table);
fse->execute_data = EG(current_execute_data);
if (XG(remote_enabled) || XG(collect_vars) || XG(show_local_vars)) {
/* Because include/require is treated as a stack level, we have to add used
* variables in include/required files to all the stack levels above, until
* we hit a function or the top level stack. This is so that the variables
* show up correctly where they should be. We always call
* add_used_variables on the current stack level, otherwise vars in include
* files do not show up in the locals list. */
for (le = XDEBUG_LLIST_TAIL(XG(stack)); le != NULL; le = XDEBUG_LLIST_PREV(le)) {
xfse = XDEBUG_LLIST_VALP(le);
add_used_variables(xfse, op_array);
if (XDEBUG_IS_FUNCTION(xfse->function.type)) {
break;
}
}
}
if (XG(do_code_coverage) && XG(code_coverage_unused)) {
xdebug_prefill_code_coverage(op_array TSRMLS_CC);
}
/* If we're in an eval, we need to create an ID for it. This ID however
* depends on the debugger mechanism in use so we need to call a function
* in the handler for it */
if (XG(remote_enabled) && XG(context).handler->register_eval_id && fse->function.type == XFUNC_EVAL) {
eval_id = XG(context).handler->register_eval_id(&(XG(context)), fse);
}
/* Check for entry breakpoints */
if (XG(remote_enabled) && XG(breakpoints_allowed)) {
if (!handle_breakpoints(fse, XDEBUG_BRK_FUNC_CALL)) {
XG(remote_enabled) = 0;
}
}
if (XG(profiler_enabled)) {
xdebug_profiler_function_user_begin(fse TSRMLS_CC);
}
xdebug_old_execute(op_array TSRMLS_CC);
if (XG(profiler_enabled)) {
xdebug_profiler_function_user_end(fse, op_array TSRMLS_CC);
}
trace_function_end(fse, function_nr TSRMLS_CC);
/* Store return value in the trace file */
if (XG(collect_return) && do_return && XG(do_trace) && XG(trace_file)) {
if (EG(return_value_ptr_ptr) && *EG(return_value_ptr_ptr)) {
char* t = return_trace_stack_retval(fse, *EG(return_value_ptr_ptr) TSRMLS_CC);
fprintf(XG(trace_file), "%s", t);
fflush(XG(trace_file));
xdfree(t);
}
}
/* Check for return breakpoints */
if (XG(remote_enabled) && XG(breakpoints_allowed)) {
if (!handle_breakpoints(fse, XDEBUG_BRK_FUNC_RETURN)) {
XG(remote_enabled) = 0;
}
}
/* If we're in an eval, we need to destroy the created ID again. */
if (XG(remote_enabled) && XG(context).handler->unregister_eval_id && fse->function.type == XFUNC_EVAL) {
XG(context).handler->unregister_eval_id(&(XG(context)), fse, eval_id);
}
fse->symbol_table = NULL;
fse->execute_data = NULL;
xdebug_llist_remove(XG(stack), XDEBUG_LLIST_TAIL(XG(stack)), xdebug_stack_element_dtor);
XG(level)--;
}
void xdebug_execute_internal(zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC)
{
zend_execute_data *edata = EG(current_execute_data);
function_stack_entry *fse;
zend_op *cur_opcode;
int do_return = (XG(do_trace) && XG(trace_file));
int function_nr = 0;
XG(level)++;
if (XG(level) == XG(max_nesting_level)) {
php_error(E_ERROR, "Maximum function nesting level of '%ld' reached, aborting!", XG(max_nesting_level));
}
fse = add_stack_frame(edata, edata->op_array, XDEBUG_INTERNAL TSRMLS_CC);
function_nr = XG(function_count);
trace_function_begin(fse, function_nr TSRMLS_CC);
/* Check for entry breakpoints */
if (XG(remote_enabled) && XG(breakpoints_allowed)) {
if (!handle_breakpoints(fse, XDEBUG_BRK_FUNC_CALL)) {
XG(remote_enabled) = 0;
}
}
if (XG(profiler_enabled)) {
xdebug_profiler_function_internal_begin(fse TSRMLS_CC);
}
execute_internal(current_execute_data, return_value_used TSRMLS_CC);
if (XG(profiler_enabled)) {
xdebug_profiler_function_internal_end(fse TSRMLS_CC);
}
trace_function_end(fse, function_nr TSRMLS_CC);
/* Store return value in the trace file */
if (XG(collect_return) && do_return && XG(do_trace) && XG(trace_file)) {
cur_opcode = *EG(opline_ptr);
if (cur_opcode) {
zval *ret = xdebug_zval_ptr(&(cur_opcode->result), current_execute_data->Ts TSRMLS_CC);
char* t = return_trace_stack_retval(fse, ret TSRMLS_CC);
fprintf(XG(trace_file), "%s", t);
fflush(XG(trace_file));
xdfree(t);
}
}
/* Check for return breakpoints */
if (XG(remote_enabled) && XG(breakpoints_allowed)) {
if (!handle_breakpoints(fse, XDEBUG_BRK_FUNC_RETURN)) {
XG(remote_enabled) = 0;
}
}
xdebug_llist_remove(XG(stack), XDEBUG_LLIST_TAIL(XG(stack)), xdebug_stack_element_dtor);
XG(level)--;
}
static char* text_formats[10] = {
"\n",
"%s: %s in %s on line %d\n",
"\nCall Stack:\n",
#if HAVE_PHP_MEMORY_USAGE
"%10.4f %10ld %3d. %s(",
#else
"%10.4f %3d. %s(",
#endif
"'%s'",
") %s:%d\n",
"\n\nVariables in local scope (#%d):\n",
"\n",
" $%s = %s\n",
" $%s = *uninitialized*\n"
};
static char* html_formats[10] = {
"<br />\n<font size='1'><table dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n",
"<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in %s on line <i>%d</i></th></tr>\n",
#if HAVE_PHP_MEMORY_USAGE
"<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>\n",
"<tr><td bgcolor='#eeeeec' align='center'>%d</td><td bgcolor='#eeeeec' align='center'>%.4f</td><td bgcolor='#eeeeec' align='right'>%ld</td><td bgcolor='#eeeeec'>%s( ",
#else
"<tr><th align='left' bgcolor='#e9b96e' colspan='4'>Call Stack</th></tr>\n<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>\n",
"<tr><td bgcolor='#eeeeec' align='center'>%d</td><td bgcolor='#eeeeec' align='center'>%.4f</td><td bgcolor='#eeeeec'>%s( ",
#endif
"<font color='#00bb00'>'%s'</font>",
" )</td><td title='%s' bgcolor='#eeeeec'>..%s<b>:</b>%d</td></tr>\n",
#if HAVE_PHP_MEMORY_USAGE
"<tr><th align='left' colspan='5' bgcolor='#e9b96e'>Variables in local scope (#%d)</th></tr>\n",
#else
"<tr><th align='left' colspan='4' bgcolor='#e9b96e'>Variables in local scope (#%d)</th></tr>\n",
#endif
"</table></font>\n",
"<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='4' bgcolor='#eeeeec'>%s</td></tr>\n",
"<tr><td bgcolor='#eeeeec'>$%s</td><td colspan='4' bgcolor='#eeeeec' colspan='2'><i>Undefined</i></td></tr>\n"
};
static void dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, void *argument)
{
int html = *(int *)htmlq;
int len;
zval *zvar;
char *contents;
char *name = (char*) he->ptr;
HashTable *tmp_ht;
char **formats;
xdebug_str *str = (xdebug_str *) argument;
TSRMLS_FETCH();
if (!he->ptr) {
return;
}
/* Bail out on $this and $GLOBALS */
if (strcmp(name, "this") == 0 || strcmp(name, "GLOBALS") == 0) {
return;
}
tmp_ht = XG(active_symbol_table);
XG(active_symbol_table) = EG(active_symbol_table);
zvar = xdebug_get_php_symbol(name, strlen(name) + 1);
XG(active_symbol_table) = tmp_ht;
if (html) {
formats = html_formats;
} else {
formats = text_formats;
}
if (!zvar) {
xdebug_str_add(str, xdebug_sprintf(formats[9], name), 1);
return;
}
if (html) {
contents = xdebug_get_zval_value_fancy(NULL, zvar, &len, 0, NULL TSRMLS_CC);
} else {
contents = xdebug_get_zval_value(zvar, 0, NULL);
}
if (contents) {
xdebug_str_add(str, xdebug_sprintf(formats[8], name, contents), 1);
} else {
xdebug_str_add(str, xdebug_sprintf(formats[9], name), 1);
}
xdfree(contents);
}
static void log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC)
{
xdebug_llist_element *le;
function_stack_entry *i;
char *tmp_log_message;
tmp_log_message = xdebug_sprintf( "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
php_log_err(tmp_log_message TSRMLS_CC);
xdfree(tmp_log_message);
if (XG(stack) && XG(stack)->size) {
php_log_err("PHP Stack trace:" TSRMLS_CC);
for (le = XDEBUG_LLIST_HEAD(XG(stack)); le != NULL; le = XDEBUG_LLIST_NEXT(le))
{
int c = 0; /* Comma flag */
int j = 0; /* Counter */
char *tmp_name;
xdebug_str log_buffer = {0, 0, NULL};
i = XDEBUG_LLIST_VALP(le);
tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC);
xdebug_str_add(&log_buffer, xdebug_sprintf("PHP %3d. %s(", i->level, tmp_name), 1);
xdfree(tmp_name);
/* Printing vars */
for (j = 0; j < i->varc; j++) {
char *tmp_varname, *tmp_value;
if (c) {
xdebug_str_addl(&log_buffer, ", ", 2, 0);
} else {
c = 1;
}
tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup("");
xdebug_str_add(&log_buffer, tmp_varname, 0);
xdfree(tmp_varname);
if (i->var[j].addr) {
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
xdebug_str_add(&log_buffer, tmp_value, 0);
xdfree(tmp_value);
} else {
xdebug_str_addl(&log_buffer, "*uninitialized*", 15, 0);
}
}
xdebug_str_add(&log_buffer, xdebug_sprintf(") %s:%d", i->filename, i->lineno), 1);
php_log_err(log_buffer.d TSRMLS_CC);
xdebug_str_free(&log_buffer);
}
}
}
static char* get_printable_stack(int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC)
{
xdebug_llist_element *le;
function_stack_entry *i;
int len;
char **formats;
xdebug_str str = {0, 0, NULL};
if (html) {
formats = html_formats;
} else {
formats = text_formats;
}
xdebug_str_add(&str, formats[0], 0);
xdebug_str_add(&str, xdebug_sprintf(formats[1], error_type_str, buffer, error_filename, error_lineno), 1);
if (XG(stack) && XG(stack)->size) {
i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_HEAD(XG(stack)));
xdebug_str_add(&str, formats[2], 0);
for (le = XDEBUG_LLIST_HEAD(XG(stack)); le != NULL; le = XDEBUG_LLIST_NEXT(le))
{
int c = 0; /* Comma flag */
int j = 0; /* Counter */
char *tmp_name;
i = XDEBUG_LLIST_VALP(le);
tmp_name = xdebug_show_fname(i->function, html, 0 TSRMLS_CC);
if (html) {
#if HAVE_PHP_MEMORY_USAGE
xdebug_str_add(&str, xdebug_sprintf(formats[3], i->level, i->time - XG(start_time), i->memory, tmp_name), 1);
#else
xdebug_str_add(&str, xdebug_sprintf(formats[3], i->level, i->time - XG(start_time), tmp_name), 1);
#endif
} else {
#if HAVE_PHP_MEMORY_USAGE
xdebug_str_add(&str, xdebug_sprintf(formats[3], i->time - XG(start_time), i->memory, i->level, tmp_name), 1);
#else
xdebug_str_add(&str, xdebug_sprintf(formats[3], i->time - XG(start_time), i->level, tmp_name), 1);
#endif
}
xdfree(tmp_name);
/* Printing vars */
for (j = 0; j < i->varc; j++) {
char *tmp_value, *tmp_fancy_value, *tmp_fancy_synop_value;
int newlen;
if (c) {
xdebug_str_addl(&str, ", ", 2, 0);
} else {
c = 1;
}
if (i->var[j].name && XG(collect_params) >= 4) {
if (html) {
xdebug_str_add(&str, xdebug_sprintf("<span>$%s = </span>", i->var[j].name), 1);
} else {
xdebug_str_add(&str, xdebug_sprintf("$%s = ", i->var[j].name), 1);
}
}
if (i->var[j].addr) {
if (html) {
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
tmp_fancy_value = xdebug_xmlize(tmp_value, strlen(tmp_value), &newlen);
tmp_fancy_synop_value = xdebug_get_zval_synopsis_fancy("", i->var[j].addr, &len, 0, NULL TSRMLS_CC);
switch (XG(collect_params)) {
case 1: // synopsis
xdebug_str_add(&str, xdebug_sprintf("<span>%s</span>", tmp_fancy_synop_value), 1);
break;
case 2: // synopsis + full in tooltip
xdebug_str_add(&str, xdebug_sprintf("<span title='%s'>%s</span>", tmp_fancy_value, tmp_fancy_synop_value), 1);
break;
case 3: // full
default:
xdebug_str_add(&str, xdebug_sprintf("<span>%s</span>", tmp_fancy_value), 1);
break;
}
xdfree(tmp_value);
efree(tmp_fancy_value);
xdfree(tmp_fancy_synop_value);
} else {
switch (XG(collect_params)) {
case 1: // synopsis
case 2:
tmp_value = xdebug_get_zval_synopsis(i->var[j].addr, 0, NULL);
break;
case 3:
default:
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
break;
}
if (tmp_value) {
xdebug_str_add(&str, xdebug_sprintf("%s", tmp_value), 1);
xdfree(tmp_value);
} else {
xdebug_str_addl(&str, "???", 3, 0);
}
}
} else {
xdebug_str_addl(&str, "???", 3, 0);
}
}
if (i->include_filename) {
xdebug_str_add(&str, xdebug_sprintf(formats[4], i->include_filename), 1);
}
if (html) {
char *just_filename = strrchr(i->filename, DEFAULT_SLASH);
xdebug_str_add(&str, xdebug_sprintf(formats[5], i->filename, just_filename, i->lineno), 1);
} else {
xdebug_str_add(&str, xdebug_sprintf(formats[5], i->filename, i->lineno), 1);
}
}
if (XG(dump_globals) && !(XG(dump_once) && XG(dumped))) {
char *tmp = xdebug_get_printable_superglobals(html TSRMLS_CC);
if (tmp) {
xdebug_str_add(&str, tmp, 1);
}
XG(dumped) = 1;
}
if (XG(show_local_vars) && XG(stack) && XDEBUG_LLIST_TAIL(XG(stack))) {
int scope_nr = XG(stack)->size;
i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack)));
if (i->user_defined == XDEBUG_INTERNAL && XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack))) && XDEBUG_LLIST_VALP(XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack))))) {
i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack))));
scope_nr--;
}
if (i->used_vars && i->used_vars->size) {
xdebug_hash *tmp_hash;
xdebug_str_add(&str, xdebug_sprintf(formats[6], scope_nr), 1);
tmp_hash = xdebug_used_var_hash_from_llist(i->used_vars);
xdebug_hash_apply_with_argument(tmp_hash, (void*) &html, dump_used_var_with_contents, (void *) &str);
xdebug_hash_destroy(tmp_hash);
}
}
xdebug_str_add(&str, formats[7], 0);
}
return str.d;
}
static void print_stack(int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC)
{
char *printable_stack;
printable_stack = get_printable_stack(html, error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
php_printf("%s", printable_stack);
xdfree(printable_stack);
}
static char* return_trace_stack_retval(function_stack_entry* i, zval* retval TSRMLS_DC)
{
int j = 0; /* Counter */
xdebug_str str = {0, 0, NULL};
char *tmp_value;
if (XG(trace_format) != 0) {
return xdstrdup("");
}
xdebug_str_addl(&str, " ", 20, 0);
if (XG(show_mem_delta)) {
xdebug_str_addl(&str, " ", 8, 0);
}
for (j = 0; j < i->level; j++) {
xdebug_str_addl(&str, " ", 2, 0);
}
xdebug_str_addl(&str, " >=> ", 7, 0);
tmp_value = xdebug_get_zval_value(retval, 0, NULL);
if (tmp_value) {
xdebug_str_add(&str, tmp_value, 1);
}
xdebug_str_addl(&str, "\n", 2, 0);
return str.d;
}
static char* return_trace_stack_frame_begin_normal(function_stack_entry* i TSRMLS_DC)
{
int c = 0; /* Comma flag */
int j = 0; /* Counter */
char *tmp_name;
xdebug_str str = {0, 0, NULL};
tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC);
xdebug_str_add(&str, xdebug_sprintf("%10.4f ", i->time - XG(start_time)), 1);
xdebug_str_add(&str, xdebug_sprintf("%10lu ", i->memory), 1);
if (XG(show_mem_delta)) {
xdebug_str_add(&str, xdebug_sprintf("%+8ld ", i->memory - i->prev_memory), 1);
}
for (j = 0; j < i->level; j++) {
xdebug_str_addl(&str, " ", 2, 0);
}
xdebug_str_add(&str, xdebug_sprintf("-> %s(", tmp_name), 1);
xdfree(tmp_name);
/* Printing vars */
if (XG(collect_params) > 0) {
for (j = 0; j < i->varc; j++) {
char *tmp_value;
if (c) {
xdebug_str_addl(&str, ", ", 2, 0);
} else {
c = 1;
}
if (i->var[j].name && XG(collect_params) >= 4) {
xdebug_str_add(&str, xdebug_sprintf("$%s = ", i->var[j].name), 1);
}
switch (XG(collect_params)) {
case 1: // synopsis
case 2:
tmp_value = xdebug_get_zval_synopsis(i->var[j].addr, 0, NULL);
break;
case 3:
default:
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
break;
}
if (tmp_value) {
xdebug_str_add(&str, tmp_value, 1);
} else {
xdebug_str_add(&str, "???", 0);
}
}
}
if (i->include_filename) {
xdebug_str_add(&str, i->include_filename, 0);
}
xdebug_str_add(&str, xdebug_sprintf(") %s:%d\n", i->filename, i->lineno), 1);
return str.d;
}
#define return_trace_stack_frame_begin_computerized(i,f) return_trace_stack_frame_computerized((i), (f), 0 TSRMLS_CC)
#define return_trace_stack_frame_end_computerized(i,f) return_trace_stack_frame_computerized((i), (f), 1 TSRMLS_CC)
static char* return_trace_stack_frame_computerized(function_stack_entry* i, int fnr, int whence TSRMLS_DC)
{
char *tmp_name;
xdebug_str str = {0, 0, NULL};
xdebug_str_add(&str, xdebug_sprintf("%d\t", i->level), 1);
xdebug_str_add(&str, xdebug_sprintf("%d\t", fnr), 1);
if (whence == 0) { /* start */
tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC);
xdebug_str_add(&str, "0\t", 0);
xdebug_str_add(&str, xdebug_sprintf("%f\t", i->time - XG(start_time)), 1);
#if HAVE_PHP_MEMORY_USAGE
xdebug_str_add(&str, xdebug_sprintf("%lu\t", i->memory), 1);
#else
xdebug_str_add(&str, "\t", 0);
#endif
xdebug_str_add(&str, xdebug_sprintf("%s\t", tmp_name), 1);
xdebug_str_add(&str, xdebug_sprintf("%d\t", i->user_defined == XDEBUG_EXTERNAL ? 1 : 0), 1);
xdfree(tmp_name);
if (i->include_filename) {
xdebug_str_add(&str, i->include_filename, 0);
}
xdebug_str_add(&str, xdebug_sprintf("\t%s\t%d\n", i->filename, i->lineno), 1);
} else if (whence == 1) { /* end */
xdebug_str_add(&str, "1\t", 0);
xdebug_str_add(&str, xdebug_sprintf("%f\t", xdebug_get_utime() - XG(start_time)), 1);
#if HAVE_PHP_MEMORY_USAGE
xdebug_str_add(&str, xdebug_sprintf("%lu\n", XG_MEMORY_USAGE()), 1);
#else
xdebug_str_add(&str, "\n", 0);
#endif
}
return str.d;
}
static char* return_trace_stack_frame_begin_html(function_stack_entry* i, int fnr TSRMLS_DC)
{
char *tmp_name;
int j;
xdebug_str str = {0, 0, NULL};
xdebug_str_add(&str, "\t<tr>", 0);
xdebug_str_add(&str, xdebug_sprintf("<td>%d</td>", fnr), 1);
xdebug_str_add(&str, xdebug_sprintf("<td>%0.6f</td>", i->time - XG(start_time)), 1);
#if MEMORY_LIMIT
xdebug_str_add(&str, xdebug_sprintf("<td align='right'>%lu</td>", i->memory), 1);
#endif
xdebug_str_add(&str, "<td align='left'>", 0);
for (j = 0; j < i->level - 1; j++) {
xdebug_str_add(&str, " ", 0);
}
xdebug_str_add(&str, "-></td>", 0);
tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC);
xdebug_str_add(&str, xdebug_sprintf("<td>%s(", tmp_name), 1);
xdfree(tmp_name);
if (i->include_filename) {
xdebug_str_add(&str, i->include_filename, 0);
}
xdebug_str_add(&str, xdebug_sprintf(")</td><td>%s:%d</td>", i->filename, i->lineno), 1);
xdebug_str_add(&str, "</tr>\n", 0);
return str.d;
}
static char* return_trace_stack_frame_begin(function_stack_entry* i, int fnr TSRMLS_DC)
{
switch (XG(trace_format)) {
case 0:
return return_trace_stack_frame_begin_normal(i TSRMLS_CC);
case 1:
return return_trace_stack_frame_begin_computerized(i, fnr);
case 2:
return return_trace_stack_frame_begin_html(i, fnr TSRMLS_CC);
default:
return xdstrdup("");
}
}
static char* return_trace_stack_frame_end(function_stack_entry* i, int fnr TSRMLS_DC)
{
switch (XG(trace_format)) {
case 1:
return return_trace_stack_frame_end_computerized(i, fnr);
default:
return xdstrdup("");
}
}
static void xdebug_do_jit(TSRMLS_D)
{
if (!XG(remote_enabled) && XG(remote_enable) && (XG(remote_mode) == XDEBUG_JIT)) {
XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port));
if (XG(context).socket >= 0) {
XG(remote_enabled) = 0;
/* Get handler from mode */
XG(context).handler = xdebug_handler_get(XG(remote_handler));
if (!XG(context).handler) {
zend_error(E_WARNING, "The remote debug handler '%s' is not supported.", XG(remote_handler));
} else if (!XG(context).handler->remote_init(&(XG(context)), XDEBUG_JIT)) {
/* The request could not be started, ignore it then */
} else {
/* All is well, turn off script time outs */
zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), "0", strlen("0"), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
XG(remote_enabled) = 1;
}
}
}
}
#ifdef ZEND_ENGINE_2
void xdebug_throw_exception_hook(zval *exception TSRMLS_DC)
{
zval *message, *file, *line;
zend_class_entry *default_ce, *exception_ce;
xdebug_brk_info *extra_brk_info;
char *exception_trace;
if (!exception) {
return;
}
#if (PHP_MAJOR_VERSION >= 6) || ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 2))
default_ce = zend_exception_get_default(TSRMLS_C);
#else
default_ce = zend_exception_get_default();
#endif
exception_ce = zend_get_class_entry(exception TSRMLS_CC);
message = zend_read_property(default_ce, exception, "message", sizeof("message")-1, 0 TSRMLS_CC);
file = zend_read_property(default_ce, exception, "file", sizeof("file")-1, 0 TSRMLS_CC);
line = zend_read_property(default_ce, exception, "line", sizeof("line")-1, 0 TSRMLS_CC);
exception_trace = get_printable_stack(PG(html_errors), exception_ce->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line) TSRMLS_CC);
if (XG(last_exception_trace)) {
xdfree(XG(last_exception_trace));
}
XG(last_exception_trace) = exception_trace;
if (XG(show_ex_trace)) {
if (PG(log_errors)) {
log_stack(exception_ce->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line) TSRMLS_CC);
}
if (PG(display_errors)) {
php_printf("%s", exception_trace);
}
}
/* Start JIT if requested and not yet enabled */
xdebug_do_jit(TSRMLS_C);
if (XG(remote_enabled)) {
/* Check if we have a breakpoint on this exception */
if (xdebug_hash_find(XG(context).exception_breakpoints, exception_ce->name, strlen(exception_ce->name), (void *) &extra_brk_info)) {
if (handle_hit_value(extra_brk_info)) {
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), Z_STRVAL_P(file), Z_LVAL_P(line), XDEBUG_BREAK, exception_ce->name, Z_STRVAL_P(message))) {
XG(remote_enabled) = 0;
}
}
}
}
}
/* Opcode handler for exit, to be able to clean up the profiler */
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS)
{
if (XG(profiler_enabled)) {
xdebug_profiler_deinit(TSRMLS_C);
}
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
return ZEND_USER_OPCODE_DISPATCH;
#else
return old_exit_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
#endif
}
#endif
void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
{
char *buffer, *error_type_str;
int buffer_len;
xdebug_brk_info *extra_brk_info = NULL;
#if PHP_MAJOR_VERSION >= 5
error_handling_t error_handling;
zend_class_entry *exception_class;
#endif
TSRMLS_FETCH();
buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
error_type_str = xdebug_error_type(type);
#if PHP_MAJOR_VERSION >= 5
/* Store last error message for error_get_last() */
if (PG(last_error_message)) {
free(PG(last_error_message));
}
if (PG(last_error_file)) {
free(PG(last_error_file));
}
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6
PG(last_error_type) = type;
#endif
PG(last_error_message) = strdup(buffer);
PG(last_error_file) = strdup(error_filename);
PG(last_error_lineno) = error_lineno;
#endif
#if PHP_MAJOR_VERSION >= 5
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
error_handling = EG(error_handling);
exception_class = EG(exception_class);
#else
error_handling = PG(error_handling);
exception_class = PG(exception_class);
#endif
/* according to error handling mode, suppress error, throw exception or show it */
if (error_handling != EH_NORMAL) {
switch (type) {
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_PARSE:
/* fatal errors are real errors and cannot be made exceptions */
break;
case E_STRICT:
/* for the sake of BC to old damaged code */
break;
case E_NOTICE:
case E_USER_NOTICE:
/* notices are no errors and are not treated as such like E_WARNINGS */
break;
default:
/* throw an exception if we are in EH_THROW mode
* but DO NOT overwrite a pending exception
*/
if (error_handling == EH_THROW && !EG(exception)) {
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
zend_throw_error_exception(exception_class, buffer, 0, type TSRMLS_CC);
#else
zend_throw_exception(exception_class, buffer, 0 TSRMLS_CC);
#endif
}
efree(buffer);
return;
}
}
#endif
if (EG(error_reporting) & type) {
/* Log to logger */
if (PG(log_errors)) {
#ifdef PHP_WIN32
if (type==E_CORE_ERROR || type==E_CORE_WARNING) {
MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
}
#endif
log_stack(error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
}
/* Display errors */
if (PG(display_errors)) {
char *printable_stack;
/* We need to see if we have an uncaught exception fatal error now */
if (type == E_ERROR && strncmp(buffer, "Uncaught exception", 18) == 0) {
php_printf("%s", XG(last_exception_trace));
} else {
printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
php_printf("%s", printable_stack);
xdfree(printable_stack);
}
}
}
/* Start JIT if requested and not yet enabled */
xdebug_do_jit(TSRMLS_C);
/* Check for the pseudo exceptions to allow breakpoints on PHP error statuses */
if (XG(remote_enabled) && XG(breakpoints_allowed)) {
if (xdebug_hash_find(XG(context).exception_breakpoints, error_type_str, strlen(error_type_str), (void *) &extra_brk_info)) {
if (handle_hit_value(extra_brk_info)) {
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), error_filename, error_lineno, XDEBUG_BREAK, error_type_str, buffer)) {
XG(remote_enabled) = 0;
}
}
}
}
xdfree(error_type_str);
/* Bail out if we can't recover */
switch (type) {
case E_CORE_ERROR:
/* no break - intentionally */
case E_ERROR:
/*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
case E_COMPILE_ERROR:
case E_USER_ERROR:
EG(exit_status) = 255;
#if HAVE_PHP_MEMORY_USAGE
/* restore memory limit */
# if PHP_VERSION_ID >= 50200
zend_set_memory_limit(PG(memory_limit));
# else
AG(memory_limit) = PG(memory_limit);
# endif
#endif
zend_bailout();
return;
}
if (PG(track_errors) && EG(active_symbol_table)) {
zval *tmp;
ALLOC_ZVAL(tmp);
INIT_PZVAL(tmp);
Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len);
Z_STRLEN_P(tmp) = buffer_len;
Z_TYPE_P(tmp) = IS_STRING;
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
}
efree(buffer);
}
/* {{{ zend_op_array srm_compile_file (file_handle, type)
* This function provides a hook for the execution of bananas */
zend_op_array *xdebug_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
zend_op_array *op_array;
op_array = old_compile_file(file_handle, type TSRMLS_CC);
if (op_array) {
if (XG(do_code_coverage) && XG(code_coverage_unused)) {
xdebug_prefill_code_coverage(op_array TSRMLS_CC);
}
}
return op_array;
}
/* }}} */
/* {{{ proto integet xdebug_get_stack_depth()
Returns the stack depth */
PHP_FUNCTION(xdebug_get_stack_depth)
{
/* We substract one so that the function call to xdebug_get_stack_depth()
* is not part of the returned depth. */
RETURN_LONG(XG(stack)->size - 1);
}
/* {{{ proto array xdebug_get_function_stack()
Returns an array representing the current stack */
PHP_FUNCTION(xdebug_get_function_stack)
{
xdebug_llist_element *le;
int j;
unsigned int k;
zval *frame;
zval *params;
char *argument;
array_init(return_value);
le = XDEBUG_LLIST_HEAD(XG(stack));
for (k = 0; k < XG(stack)->size - 1; k++, le = XDEBUG_LLIST_NEXT(le)) {
function_stack_entry *i = XDEBUG_LLIST_VALP(le);
if (i->function.function) {
if (strcmp(i->function.function, "xdebug_get_function_stack") == 0) {
return;
}
}
/* Initialize frame array */
MAKE_STD_ZVAL(frame);
array_init(frame);
/* Add data */
if (i->function.function) {
add_assoc_string_ex(frame, "function", sizeof("function"), i->function.function, 1);
}
if (i->function.class) {
add_assoc_string_ex(frame, "class", sizeof("class"), i->function.class, 1);
}
add_assoc_string_ex(frame, "file", sizeof("file"), i->filename, 1);
add_assoc_long_ex(frame, "line", sizeof("line"), i->lineno);
/* Add parameters */
MAKE_STD_ZVAL(params);
array_init(params);
for (j = 0; j < i->varc; j++) {
if (i->var[j].addr) {
argument = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
} else {
zval *tmp_zval;
MAKE_STD_ZVAL(tmp_zval);
argument = xdebug_get_zval_value(tmp_zval, 0, NULL);
zval_dtor(tmp_zval);
FREE_ZVAL(tmp_zval);
}
if (i->var[j].name) {
add_assoc_string_ex(params, i->var[j].name, strlen(i->var[j].name) + 1, argument, 1);
} else {
add_index_string(params, j, argument, 1);
}
xdfree(argument);
}
add_assoc_zval_ex(frame, "params", sizeof("params"), params);
if (i->include_filename) {
add_assoc_string_ex(frame, "include_filename", sizeof("include_filename"), i->include_filename, 1);
}
add_next_index_zval(return_value, frame);
}
}
/* }}} */
static void attach_used_var_names(void *return_value, xdebug_hash_element *he)
{
char *name = (char*) he->ptr;
add_next_index_string(return_value, name, 1);
}
/* {{{ proto array xdebug_print_declared_vars()
Displays a stack trace */
PHP_FUNCTION(xdebug_print_function_stack)
{
function_stack_entry *i;
i = xdebug_get_stack_frame(0 TSRMLS_CC);
print_stack(PG(html_errors), "Xdebug", "user triggered", i->filename, i->lineno TSRMLS_CC);
}
/* }}} */
/* {{{ proto array xdebug_get_declared_vars()
Returns an array representing the current stack */
PHP_FUNCTION(xdebug_get_declared_vars)
{
xdebug_llist_element *le;
function_stack_entry *i;
xdebug_hash *tmp_hash;
array_init(return_value);
le = XDEBUG_LLIST_TAIL(XG(stack));
le = XDEBUG_LLIST_PREV(le);
i = XDEBUG_LLIST_VALP(le);
/* Add declared vars */
if (i->used_vars) {
tmp_hash = xdebug_used_var_hash_from_llist(i->used_vars);
xdebug_hash_apply(tmp_hash, (void *) return_value, attach_used_var_names);
xdebug_hash_destroy(tmp_hash);
}
}
/* }}} */
/* {{{ proto string xdebug_call_class()
Returns the name of the calling class */
PHP_FUNCTION(xdebug_call_class)
{
function_stack_entry *i;
long depth = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &depth) == FAILURE) {
return;
}
i = xdebug_get_stack_frame(2 + depth TSRMLS_CC);
if (i) {
RETURN_STRING(i->function.class ? i->function.class : "", 1);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto string xdebug_call_function()
Returns the function name from which the current function was called from. */
PHP_FUNCTION(xdebug_call_function)
{
function_stack_entry *i;
long depth = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &depth) == FAILURE) {
return;
}
i = xdebug_get_stack_frame(2 + depth TSRMLS_CC);
if (i) {
RETURN_STRING(i->function.function ? i->function.function : "{}", 1);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto string xdebug_call_line()
Returns the line number where the current function was called from. */
PHP_FUNCTION(xdebug_call_line)
{
function_stack_entry *i;
long depth = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &depth) == FAILURE) {
return;
}
i = xdebug_get_stack_frame(1 + depth TSRMLS_CC);
if (i) {
RETURN_LONG(i->lineno);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto int xdebug_call_file()
Returns the filename where the current function was called from. */
PHP_FUNCTION(xdebug_call_file)
{
function_stack_entry *i;
long depth = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &depth) == FAILURE) {
return;
}
i = xdebug_get_stack_frame(1 + depth TSRMLS_CC);
if (i) {
RETURN_STRING(i->filename, 1);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto void xdebug_set_time_limit(void)
Dummy function to prevent time limit from being set within the script */
PHP_FUNCTION(xdebug_set_time_limit)
{
if (!XG(remote_enabled)) {
XG(orig_set_time_limit_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}
/* }}} */
/* {{{ proto void xdebug_var_dump(mixed var [, ...] )
Outputs a fancy string representation of a variable */
PHP_FUNCTION(xdebug_var_dump)
{
zval ***args;
int argc;
int i, len;
char *val;
argc = ZEND_NUM_ARGS();
args = (zval ***)emalloc(argc * sizeof(zval **));
if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree(args);
WRONG_PARAM_COUNT;
}
for (i = 0; i < argc; i++) {
if (PG(html_errors)) {
val = xdebug_get_zval_value_fancy(NULL, (zval*) *args[i], &len, 0, NULL TSRMLS_CC);
PHPWRITE(val, len);
xdfree(val);
} else {
xdebug_php_var_dump(args[i], 1 TSRMLS_CC);
}
}
efree(args);
}
/* }}} */
/* {{{ proto void xdebug_debug_zval(mixed var [, ...] )
Outputs a fancy string representation of a variable */
PHP_FUNCTION(xdebug_debug_zval)
{
zval ***args;
int argc;
int i, len;
char *val;
zval *debugzval;
argc = ZEND_NUM_ARGS();
args = (zval ***)emalloc(argc * sizeof(zval **));
if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree(args);
WRONG_PARAM_COUNT;
}
for (i = 0; i < argc; i++) {
if (Z_TYPE_PP(args[i]) == IS_STRING) {
XG(active_symbol_table) = EG(active_symbol_table);
debugzval = xdebug_get_php_symbol(Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i]) + 1);
if (debugzval) {
php_printf("%s: ", Z_STRVAL_PP(args[i]));
if (PG(html_errors)) {
val = xdebug_get_zval_value_fancy(NULL, debugzval, &len, 1, NULL TSRMLS_CC);
PHPWRITE(val, len);
} else {
val = xdebug_get_zval_value(debugzval, 1, NULL);
PHPWRITE(val, strlen(val));
}
xdfree(val);
PHPWRITE("\n", 1);
}
}
}
efree(args);
}
/* }}} */
/* {{{ proto void xdebug_debug_zval_stdout(mixed var [, ...] )
Outputs a fancy string representation of a variable */
PHP_FUNCTION(xdebug_debug_zval_stdout)
{
zval ***args;
int argc;
int i;
char *val;
zval *debugzval;
argc = ZEND_NUM_ARGS();
args = (zval ***)emalloc(argc * sizeof(zval **));
if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree(args);
WRONG_PARAM_COUNT;
}
for (i = 0; i < argc; i++) {
if (Z_TYPE_PP(args[i]) == IS_STRING) {
XG(active_symbol_table) = EG(active_symbol_table);
debugzval = xdebug_get_php_symbol(Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i]) + 1);
if (debugzval) {
printf("%s: ", Z_STRVAL_PP(args[i]));
val = xdebug_get_zval_value(debugzval, 1, NULL);
printf("%s(%d)", val, strlen(val));
xdfree(val);
printf("\n");
}
}
}
efree(args);
}
/* }}} */
PHP_FUNCTION(xdebug_enable)
{
zend_error_cb = new_error_cb;
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6
zend_throw_exception_hook = xdebug_throw_exception_hook;
#endif
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0)
zend_opcode_handlers[ZEND_EXIT] = xdebug_exit_handler;
#endif
}
PHP_FUNCTION(xdebug_disable)
{
zend_error_cb = old_error_cb;
#ifdef ZEND_ENGINE_2
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0)
zend_opcode_handlers[ZEND_EXIT] = old_exit_handler;
# endif
zend_throw_exception_hook = NULL;
#endif
}
PHP_FUNCTION(xdebug_is_enabled)
{
RETURN_BOOL(zend_error_cb == new_error_cb);
}
PHP_FUNCTION(xdebug_break)
{
char *file;
int lineno;
if (XG(remote_enabled)) {
file = zend_get_executed_filename(TSRMLS_C);
lineno = zend_get_executed_lineno(TSRMLS_C);
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_BREAK, NULL, NULL)) {
XG(remote_enabled) = 0;
}
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
PHP_FUNCTION(xdebug_start_trace)
{
char *fname = NULL;
int fname_len = 0;
char *trace_fname;
long options = 0;
if (XG(do_trace) == 0) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &fname, &fname_len, &options) == FAILURE) {
return;
}
if ((trace_fname = xdebug_start_trace(fname, options TSRMLS_CC)) != NULL) {
XG(do_trace) = 1;
RETVAL_STRING(trace_fname, 1);
xdfree(trace_fname);
return;
} else {
php_error(E_NOTICE, "Trace could not be started");
}
XG(do_trace) = 0;
RETURN_FALSE;
} else {
php_error(E_NOTICE, "Function trace already started");
RETURN_FALSE;
}
}
char* xdebug_start_trace(char* fname, long options TSRMLS_DC)
{
char *str_time;
char *filename;
char *tmp_fname = NULL;
if (fname && strlen(fname)) {
filename = xdstrdup(fname);
} else {
if (!strlen(XG(trace_output_name)) ||
xdebug_format_output_filename(&fname, XG(trace_output_name), NULL) <= 0
) {
/* Invalid or empty xdebug.trace_output_name */
return NULL;
}
filename = xdebug_sprintf("%s/%s", XG(trace_output_dir), fname);
}
if (options & XDEBUG_TRACE_OPTION_APPEND) {
XG(trace_file) = xdebug_fopen(filename, "a", "xt", (char**) &tmp_fname);
} else {
XG(trace_file) = xdebug_fopen(filename, "w", "xt", (char**) &tmp_fname);
}
xdfree(filename);
if (options & XDEBUG_TRACE_OPTION_COMPUTERIZED) {
XG(trace_format) = 1;
}
if (options & XDEBUG_TRACE_OPTION_HTML) {
XG(trace_format) = 2;
}
if (XG(trace_file)) {
if (XG(trace_format) == 1) {
fprintf(XG(trace_file), "Version: %s\n", XDEBUG_VERSION);
}
if (XG(trace_format) == 0 || XG(trace_format) == 1) {
str_time = xdebug_get_time();
fprintf(XG(trace_file), "TRACE START [%s]\n", str_time);
xdfree(str_time);
}
if (XG(trace_format) == 2) {
fprintf(XG(trace_file), "<table dir='ltr' class='xdebug-trace' border='1' cellspacing='0'>\n");
fprintf(XG(trace_file), "\t<tr><th>#</th><th>Time</th>");
#if MEMORY_LIMIT
fprintf(XG(trace_file), "<th>Mem</th>");
#endif
fprintf(XG(trace_file), "<th colspan='2'>Function</th><th>Location</th></tr>\n");
}
XG(do_trace) = 1;
XG(tracefile_name) = tmp_fname;
return xdstrdup(XG(tracefile_name));
}
return NULL;
}
void xdebug_stop_trace(TSRMLS_D)
{
char *str_time;
double u_time;
XG(do_trace) = 0;
if (XG(trace_file)) {
if (XG(trace_format) == 0 || XG(trace_format) == 1) {
u_time = xdebug_get_utime();
fprintf(XG(trace_file), XG(trace_format) == 0 ? "%10.4f " : "\t\t\t%f\t", u_time - XG(start_time));
#if HAVE_PHP_MEMORY_USAGE
fprintf(XG(trace_file), XG(trace_format) == 0 ? "%10u" : "%lu", XG_MEMORY_USAGE());
#else
fprintf(XG(trace_file), XG(trace_format) == 0 ? "%10u" : "", 0);
#endif
fprintf(XG(trace_file), "\n");
str_time = xdebug_get_time();
fprintf(XG(trace_file), "TRACE END [%s]\n\n", str_time);
xdfree(str_time);
}
if (XG(trace_format) == 2) {
fprintf(XG(trace_file), "</table>\n");
}
fclose(XG(trace_file));
XG(trace_file) = NULL;
}
if (XG(tracefile_name)) {
xdfree(XG(tracefile_name));
XG(tracefile_name) = NULL;
}
}
PHP_FUNCTION(xdebug_stop_trace)
{
if (XG(do_trace) == 1) {
RETVAL_STRING(XG(tracefile_name), 1);
xdebug_stop_trace(TSRMLS_C);
} else {
RETVAL_FALSE;
php_error(E_NOTICE, "Function trace was not started");
}
}
PHP_FUNCTION(xdebug_get_tracefile_name)
{
if (XG(tracefile_name)) {
RETURN_STRING(XG(tracefile_name), 1);
} else {
RETURN_FALSE;
}
}
PHP_FUNCTION(xdebug_get_profiler_filename)
{
if (XG(profile_filename)) {
RETURN_STRING(XG(profile_filename), 1);
} else {
RETURN_FALSE;
}
}
PHP_FUNCTION(xdebug_dump_aggr_profiling_data)
{
char *prefix = NULL;
int prefix_len;
if (!XG(profiler_aggregate)) {
RETURN_FALSE;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &prefix, &prefix_len) == FAILURE) {
return;
}
if (xdebug_profiler_output_aggr_data(prefix TSRMLS_CC) == SUCCESS) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
PHP_FUNCTION(xdebug_clear_aggr_profiling_data)
{
if (!XG(profiler_aggregate)) {
RETURN_FALSE;
}
zend_hash_clean(&XG(aggr_calls));
RETURN_TRUE;
}
#if HAVE_PHP_MEMORY_USAGE
PHP_FUNCTION(xdebug_memory_usage)
{
RETURN_LONG(XG_MEMORY_USAGE());
}
PHP_FUNCTION(xdebug_peak_memory_usage)
{
RETURN_LONG(XG_MEMORY_PEAK_USAGE());
}
#endif
PHP_FUNCTION(xdebug_time_index)
{
RETURN_DOUBLE(xdebug_get_utime() - XG(start_time));
}
/*************************************************************************************************************************************/
#define T(offset) (*(temp_variable *)((char *) Ts + offset))
static zval *get_zval(zend_execute_data *zdata, znode *node, temp_variable *Ts, int *is_var)
{
switch (node->op_type) {
case IS_CONST:
return &node->u.constant;
break;
case IS_TMP_VAR:
*is_var = 1;
#ifdef ZEND_ENGINE_2
return &T(node->u.var).tmp_var;
#else
return &Ts[node->u.var].tmp_var;
#endif
break;
case IS_VAR:
*is_var = 1;
#ifdef ZEND_ENGINE_2
if (T(node->u.var).var.ptr) {
return T(node->u.var).var.ptr;
} else {
fprintf(stderr, "\nIS_VAR\n");
}
#else
if (Ts[node->u.var].var.ptr) {
return Ts[node->u.var].var.ptr;
} else {
fprintf(stderr, "\nIS_VAR\n");
}
#endif
break;
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || (PHP_MAJOR_VERSION >= 6)
case IS_CV:
return *zend_get_compiled_variable_value(zdata, node->u.constant.value.lval);
break;
#endif
case IS_UNUSED:
fprintf(stderr, "\nIS_UNUSED\n");
break;
default:
fprintf(stderr, "\ndefault %d\n", node->op_type);
break;
}
*is_var = 1;
return NULL;
}
ZEND_DLEXPORT void xdebug_statement_call(zend_op_array *op_array)
{
xdebug_llist_element *le;
xdebug_brk_info *brk;
function_stack_entry *fse;
int lineno;
char *file;
int file_len = 0;
int level = 0;
TSRMLS_FETCH();
lineno = EG(current_execute_data)->opline->lineno;
file = op_array->filename;
file_len = strlen(file);
if (XG(do_code_coverage)) {
xdebug_count_line(file, lineno, 0, 0 TSRMLS_CC);
}
if (XG(remote_enabled)) {
if (XG(context).do_break) {
XG(context).do_break = 0;
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_BREAK, NULL, NULL)) {
XG(remote_enabled) = 0;
return;
}
}
/* Get latest stack level */
if (XG(stack)) {
le = XDEBUG_LLIST_TAIL(XG(stack));
fse = XDEBUG_LLIST_VALP(le);
level = fse->level;
} else {
level = 0;
}
if (XG(context).do_finish && XG(context).next_level == level) { /* Check for "finish" */
XG(context).do_finish = 0;
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_STEP, NULL, NULL)) {
XG(remote_enabled) = 0;
return;
}
return;
}
if (XG(context).do_next && XG(context).next_level >= level) { /* Check for "next" */
XG(context).do_next = 0;
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_STEP, NULL, NULL)) {
XG(remote_enabled) = 0;
return;
}
return;
}
if (XG(context).do_step) { /* Check for "step" */
XG(context).do_step = 0;
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_STEP, NULL, NULL)) {
XG(remote_enabled) = 0;
return;
}
return;
}
if (XG(context).line_breakpoints) {
int break_ok;
int old_error_reporting;
zval retval;
for (le = XDEBUG_LLIST_HEAD(XG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) {
brk = XDEBUG_LLIST_VALP(le);
#if 0
printf("b->d: %d; ln: %d; b->l: %d; b->f: %s; f: %s, f_l: %d; b->f_l: %d\n",
brk->disabled, lineno, brk->lineno, brk->file, file, file_len, brk->file_len);
#endif
#if PHP_WIN32
if (!brk->disabled && lineno == brk->lineno && strncasecmp(brk->file, file + file_len - brk->file_len, brk->file_len) == 0) {
#else
if (!brk->disabled && lineno == brk->lineno && memcmp(brk->file, file + file_len - brk->file_len, brk->file_len) == 0) {
#endif
break_ok = 1; /* Breaking is allowed by default */
/* Check if we have a condition set for it */
if (brk->condition) {
/* If there is a condition, we disable breaking by
* default and only enabled it when the code evaluates
* to TRUE */
break_ok = 0;
/* Remember error reporting level */
old_error_reporting = EG(error_reporting);
EG(error_reporting) = 0;
/* Check the condition */
if (zend_eval_string(brk->condition, &retval, "xdebug conditional breakpoint" TSRMLS_CC) == SUCCESS) {
convert_to_boolean(&retval);
break_ok = retval.value.lval;
zval_dtor(&retval);
}
/* Restore error reporting level */
EG(error_reporting) = old_error_reporting;
}
if (break_ok && handle_hit_value(brk)) {
if (!XG(context).handler->remote_breakpoint(&(XG(context)), XG(stack), file, lineno, XDEBUG_BREAK, NULL, NULL)) {
XG(remote_enabled) = 0;
break;
}
return;
}
}
}
}
}
}
ZEND_DLEXPORT int xdebug_zend_startup(zend_extension *extension)
{
zend_xdebug_initialised = 1;
return zend_startup_module(&xdebug_module_entry);
}
ZEND_DLEXPORT void xdebug_zend_shutdown(zend_extension *extension)
{
/* Do nothing. */
}
ZEND_DLEXPORT void xdebug_init_oparray(zend_op_array *op_array)
{
TSRMLS_FETCH();
op_array->reserved[XG(reserved_offset)] = 0;
}
#ifndef ZEND_EXT_API
#define ZEND_EXT_API ZEND_DLEXPORT
#endif
ZEND_EXTENSION();
ZEND_DLEXPORT zend_extension zend_extension_entry = {
XDEBUG_NAME,
XDEBUG_VERSION,
XDEBUG_AUTHOR,
XDEBUG_URL,
"Copyright (c) 2002-2007",
xdebug_zend_startup,
xdebug_zend_shutdown,
NULL, /* activate_func_t */
NULL, /* deactivate_func_t */
NULL, /* message_handler_func_t */
NULL, /* op_array_handler_func_t */
xdebug_statement_call, /* statement_handler_func_t */
NULL, /* fcall_begin_handler_func_t */
NULL, /* fcall_end_handler_func_t */
xdebug_init_oparray, /* op_array_ctor_func_t */
NULL, /* op_array_dtor_func_t */
STANDARD_ZEND_EXTENSION_PROPERTIES
};
#endif
|