Menu

[r877]: / trunk / php-java-bridge / server / META-INF / java / PHPDebugger.php  Maximize  Restore  History

Download this file

1952 lines (1757 with data), 58.0 kB

   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
<?php /*-*- mode: php; tab-width:4 -*-*/
/**
PHPDebugger.inc version 1.0alpha -- A pure PHP debugger.
Copyright (C) 2009 Jost Boekemeier
This file is part of the PHPDebugger.
The PHPDebugger ("the library") is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either
version 2, or (at your option) any later version.
The library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with the PHPDebugger; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this file statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
define ("PDB_DEBUG", 0);
define ("PDB_DISABLE_JAVA", false);
ini_set("max_execution_time", 60);
/**
* Usage:
*
* 1. include() this file at the beginning of your script
*
* 2. browse to your script using firefox
*
* 3. set breakpoints using the JavaScript GUI, click on any
* variable or included file to visit that variable or file
*
* 4. click on the stop button to terminate the debug session
*
*/
/** Use the PHP/Java Bridge, if it is available */
if (!PDB_DISABLE_JAVA) @include_once("Java.inc");
/** Use our own json coder, if no native implementation is available */
if (!function_exists("json_encode")) {
function json_decode($v) {
$length = strlen($v);
$inDquote = false;
$inQuote = false;
$decoded = array();
$ctr = 0;
$str = "";
for ($i=0; $i<$length; $i++) {
$val = $v[$i];
if ($inDquote) {
if ($inQuote) {
$inQuote = false;
switch($val) {
case 'b': $str.="\b"; break;
case 't': $str.="\t"; break;
case 'n': $str.="\n"; break;
case 'r': $str.="\r"; break;
case 'f': $str.="\f"; break;
case '\"': $str.="\""; break;
case '/': $str.="/"; break;
case '\\': $str.='\\'; break;
default:
trigger_error("Cannot json decode value ${val}", E_USER_ERROR);
}
} else {
switch($val) {
case '"': $inDquote = false; break;
case '\\': $inQuote = true; break;
default: $str .= $val; break;
}
}
} else {
switch($val) {
case ':': $key = $str; $str = ""; break;
case '}':
case ',': $val = $str; $str = ""; $decoded[$key]=$val; break;
case '"': $inDquote = true; break;
}
}
}
return (object)$decoded;
}
function json_encode($array) {
$first = true;
$encoded = "{";
foreach ($array as $k=>$v) {
if (!$first)
$encoded.=",";
else
$first = false;
$encoded.='"';
$encoded.=$k;
$encoded.='":"';
$length = strlen($v);
for ($i=0; $i<$length; $i++) {
$val = $v[$i];
switch($val) {
case "\b": $encoded.='\b'; break;
case "\t": $encoded.='\t'; break;
case "\n": $encoded.='\n'; break;
case "\r": $encoded.='\r'; break;
case "\f": $encoded.='\f'; break;
case "\"": $encoded.='\"'; break;
case "/": $encoded.='\/'; break;
case "\\": $encoded.="\\\\"; break;
default:
$code = ord($val);
if ($code > 0x7f) {
trigger_error("Cannot json encode non-ascii value ${val}", E_USER_WARNING);
$encoded.= chr(0x7f & $code);
} else {
$encoded.=$val;
}
break;
}
}
$encoded.='"';
}
$encoded.="}";
return $encoded;
}
}
/**
* a simple logger
*/
class pdb_Logger {
const FATAL = 1;
const INFO = 2;
const VERBOSE = 3;
const DEBUG = 4;
private static $logLevel = 0;
private static $logFileName = "/tmp/pdb_PHPDebugger.log";
private static function println($msg, $level) {
if (!self::$logLevel) self::$logLevel=PDB_DEBUG?self::DEBUG:self::INFO;
if ($level <= self::$logLevel) {
static $file = null;
if (!$file) $file = fopen(self::$logFileName, "ab") or die("fopen");
fwrite($file, time().": ");
fwrite($file, $msg."\n");
fflush($file);
}
}
public static function logFatal($msg) {
self::println($msg, self::FATAL);
}
public static function logInfo($msg) {
self::println($msg, self::INFO);
}
public static function logMessage($msg) {
self::println($msg, self::VERBOSE);
}
public static function logDebug($msg) {
self::println($msg, self::DEBUG);
}
public static function debug($msg) {
self::logDebug($msg);
}
public static function log($msg) {
self::logMessage($msg);
}
public static function setLogLevel($level) {
self::$logLevel=$level;
}
public static function setLogFileName($name) {
self::$logFileName = $name;
}
}
interface pdb_Queue {
/**
* Read a string from the queue
* @return string a json encoded string of values
*/
public function read();
/**
* Write a string to the queue
* @param string a json encoded string of values or TRUE
*/
public function write($val);
/**
* Mark the channel as dead. If marked, read will return boolean
* TRUE, write will do nothing.
*/
public function shutdown();
}
/**
* This class represents the debugger front end connection. It
* communicates with the debugger back end using a shared-memory queue.
* It is slow, but it does not require any special library.
* @see pdb_JavaClientConnection
*/
class pdb_PollingClientConnection implements pdb_Queue {
protected $id;
protected $role, $to;
protected $chanTrm; // "back end terminated" flag
const TIMER_DURATION = 200000; // every 200ms
/**
* Create a new communication using a unique id
*/
public function pdb_PollingClientConnection($id) {
$this->id = $id;
$this->chanTrm = "pdb_trmserver{$this->id}";
$this->init();
}
protected function checkTrm() {
return isset($_SESSION[$this->chanTrm]);
}
protected function init() {
$this->role = "client";
$this->to = "server";
}
protected function poll() {
$chanCtr = "pdb_ctr{$this->role}{$this->id}";
$chan = "pdb_{$this->role}{$this->id}";
session_start();
if (!($val = $this->checkTrm())) {
pdb_Logger::debug("...{$this->role}, {$this->id} poll...");
if (!isset($_SESSION[$chanCtr])) $_SESSION[$chanCtr] = 0;
if (isset($_SESSION[$chan]) && (count($_SESSION[$chan]) > $_SESSION[$chanCtr])) {
$val = $_SESSION[$chan][$_SESSION[$chanCtr]++];
}
}
session_write_close();
return $val;
}
protected function send($val) {
$chan = "pdb_{$this->to}{$this->id}";
session_start();
if (!$this->checkTrm()) $_SESSION[$chan][]=$val;
session_write_close();
}
/**
* read a new value from the read queue
*/
public function read() {
$val = null;
$cntr = 0;
while(!($val=$this->poll())) {
if ($cntr++<=20)
usleep(self::TIMER_DURATION);
else
usleep(self::TIMER_DURATION*5);
}
return $val;
}
/**
* write a new value to the write queue
*/
public function write($val) {
$this->send($val);
}
/**
* shut down the communication channel
*/
public function shutdown() {}
}
/**
* This class represents the debugger front end connection. It
* communicates with the debugger back end using a LinkedBlockingQueue.
* Requires the PHP/Java Bridge library.
* @see pdb_PollingClientConnection
*/
class pdb_JavaClientConnection implements pdb_Queue {
protected $session;
protected $id;
protected $queue;
protected $role, $to;
protected $chanTrm; // "back end terminated" flag
public function pdb_JavaClientConnection($id) {
$this->session = java_session();
$this->id = $id;
$this->chanTrm = "pdb_trmserver{$this->id}";
$this->session->put($this->chanTrm, false);
$this->init();
}
protected function checkTrm() {
return java_is_true($this->session->get($this->chanTrm));
}
protected function init() {
$this->role = "client";
$this->to = "server";
}
/**{@inheritDoc}*/
public function read() {
$chan = "pdb_{$this->role}{$this->id}";
if (!$this->checkTrm()) {
$queue = $this->session->get($chan);
$val = $queue->remove();
$val = java_is_null($val) ? true : (string)$val;
pdb_Logger::log("${this} read: ${val}");
return $val;
}
return true;
}
/**{@inheritDoc}*/
public function write($val) {
$chan = "pdb_{$this->to}{$this->id}";
$queue = $this->session->get($chan);
if(!$this->checkTrm()) {
$queue->add($val);
pdb_Logger::log("${this} wrote: ${val}");
}
}
/**{@inheritDoc}*/
public function shutdown() {
$chan = "pdb_{$this->role}{$this->id}";
$queue = $this->session->get($chan);
if (!java_is_null($queue)) $queue->shutdown();
$chan = "pdb_{$this->to}{$this->id}";
$queue = $this->session->get($chan);
if (!java_is_null($queue)) $queue->shutdown();
$this->session->put($this->chanTrm, false);
}
public function __toString() {
return "java {$this->role} queue for {$this->id}";
}
}
/**
* The PHP parser
*/
class pdb_Parser {
const BLOCK = 1;
const STATEMENT = 2;
const EXPRESSION = 3;
private $scriptName, $content;
private $code;
private $output;
private $line, $currentLine;
private $beginStatement, $inPhp, $inDQuote;
/**
* Create a new PHP parser
* @param string the script name
* @param string the script content
*/
public function pdb_Parser($scriptName, $content) {
$this->scriptName = $scriptName;
$this->content = $content;
$this->code = token_get_all($content);
$this->output = "";
$this->line = $this->currentLine = 0;
$this->beginStatement = $this->inPhp = $this->inDQuote = false;
}
private function toggleDQuote($chr) {
if ($chr == '"') $this->inDQuote = !$this->inDQuote;
}
private function each() {
$next = each ($this->code);
if ($next) {
$cur = current($this->code);
if (is_array($cur)) {
$this->currentLine = $cur[2];
if ($this->isWhitespace($cur)) {
$this->write($cur[1]);
return $this->each();
}
}
else
$this->toggleDQuote($cur);
}
return $next;
}
private function write($code) {
//echo "write:::".$code."\n";
$this->output.=$code;
}
private function writeInclude() {
$name = "";
while(1) {
if (!$this->each()) die("parse error");
$val = current($this->code);
if (is_array($val)) {
$name.=$val[1];
} else {
if ($val==';') break;
$name.=$val;
}
}
if (PDB_DEBUG == 2)
$this->write("EVAL($name);");
else
$this->write("eval('?>'.pdb_startInclude($name)); pdb_endInclude();");
}
private function writeCall() {
while(1) {
if (!$this->each()) die("parse error");
$val = current($this->code);
if (is_array($val)) {
$this->write($val[1]);
} else {
$this->write($val);
if ($val=='{') break;
}
}
$scriptName = $this->scriptName;
$this->write("\$__pdb_CurrentFrame=pdb_startCall(\"$scriptName\");");
}
private function writeStep($pLevel) {
$token = current($this->code);
if ($this->inPhp && !$pLevel && !$this->inDQuote && $this->beginStatement && !$this->isWhitespace($token) && ($this->line != $this->currentLine)) {
$lastLine = $this->line = $this->currentLine;
$scriptName = $this->scriptName;
if (PDB_DEBUG == 2)
$this->write(";STEP($lastLine);");
else
$this->write(";pdb_step(\"$scriptName\", $lastLine, pdb_getDefinedVars(get_defined_vars(), (isset(\$this) ? \$this : NULL)));");
}
}
private function writeNext() {
$this->next();
$token = current($this->code);
if (is_array($token)) $token = $token[1];
$this->write($token);
}
private function nextIs($chr) {
$i = 0;
while(each($this->code)) {
$cur = current($this->code);
$i++;
if (is_array($cur)) {
switch ($cur[0]) {
case T_COMMENT:
case T_DOC_COMMENT:
case T_WHITESPACE:
break; /* skip */
default:
while($i--) prev($this->code);
return false; /* not found */
}
} else {
while($i--) prev($this->code);
return $cur == $chr; /* found */
}
}
while($i--) prev($this->code);
return false; /* not found */
}
private function nextTokenIs($ar) {
$i = 0;
while(each($this->code)) {
$cur = current($this->code);
$i++;
if (is_array($cur)) {
switch ($cur[0]) {
case T_COMMENT:
case T_DOC_COMMENT:
case T_WHITESPACE:
break; /* skip */
default:
while($i--) prev($this->code);
return (in_array($cur[0], $ar));
}
} else {
break; /* not found */
}
}
while($i--) prev($this->code);
return false; /* not found */
}
private function isWhitespace($token) {
$isWhitespace = false;
switch($token[0]) {
case T_COMMENT:
case T_DOC_COMMENT:
case T_WHITESPACE:
$isWhitespace = true;
break;
}
return $isWhitespace;
}
private function next() {
if (!$this->each()) trigger_error("parse error", E_USER_ERROR);
}
private function parseBlock () {
$this->parse(self::BLOCK);
}
private function parseStatement () {
$this->parse(self::STATEMENT);
}
private function parseExpression () {
$this->parse(self::EXPRESSION);
}
private function parse ($type) {
pdb_Logger::debug("parse:::$type");
$this->beginStatement = true;
$pLevel = 0;
do {
$token = current($this->code);
if (!is_array($token)) {
pdb_Logger::debug(":::".$token);
$this->write($token);
if ($this->inPhp && !$this->inDQuote) {
$this->beginStatement = false;
switch($token) {
case '(':
$pLevel++;
break;
case ')':
if (!--$pLevel && $type==self::EXPRESSION) return;
break;
case '{':
$this->next();
$this->parseBlock();
break;
case '}':
if (!$pLevel) return;
break;
case ';':
if (!$pLevel) {
if ($type==self::STATEMENT) return;
$this->beginStatement = true;
}
break;
}
}
} else {
pdb_Logger::debug(":::".$token[1].":(".token_name($token[0]).')');
if ($this->inDQuote) {
$this->write($token[1]);
continue;
}
switch($token[0]) {
case T_OPEN_TAG:
case T_START_HEREDOC:
case T_OPEN_TAG_WITH_ECHO:
$this->beginStatement = $this->inPhp = true;
$this->write($token[1]);
break;
case T_END_HEREDOC:
case T_CLOSE_TAG:
$this->writeStep($pLevel);
$this->write($token[1]);
$this->beginStatement = $this->inPhp = false;
break;
case T_FUNCTION:
$this->write($token[1]);
$this->writeCall();
$this->beginStatement = true;
break;
case T_ELSE:
$this->write($token[1]);
if ($this->nextIs('{')) {
$this->writeNext();
$this->next();
$this->parseBlock();
} else {
$this->next();
/* create an artificial block */
$this->write('{');
$this->beginStatement = true;
$this->writeStep($pLevel);
$this->parseStatement();
$this->write('}');
}
if ($type==self::STATEMENT) return;
$this->beginStatement = true;
break;
case T_DO:
$this->writeStep($pLevel);
$this->write($token[1]);
if ($this->nextIs('{')) {
$this->writeNext();
$this->next();
$this->parseBlock();
$this->next();
} else {
$this->next();
/* create an artificial block */
$this->write('{');
$this->beginStatement = true;
$this->writeStep($pLevel);
$this->parseStatement();
$this->next();
$this->write('}');
}
$token = current($this->code);
$this->write($token[1]);
if ($token[0]!=T_WHILE) trigger_error("parse error", E_USER_ERROR);
$this->next();
$this->parseExpression();
if ($type==self::STATEMENT) return;
$this->beginStatement = true;
break;
case T_IF:
case T_ELSEIF:
case T_FOR:
case T_WHILE:
$this->writeStep($pLevel);
$this->write($token[1]);
$this->next();
$this->parseExpression();
if ($this->nextIs('{')) {
$this->writeNext();
$this->next();
$this->parseBlock();
} else {
$this->next();
/* create an artificial block */
$this->write('{');
$this->beginStatement = true;
$this->writeStep($pLevel);
$this->parseStatement();
$this->write('}');
}
if ($this->nextTokenIs(array(T_ELSE, T_ELSEIF))) {
$this->beginStatement = false;
} else {
if ($type==self::STATEMENT) return;
$this->beginStatement = true;
}
break;
case T_INCLUDE:
case T_INCLUDE_ONCE:
case T_REQUIRE:
case T_REQUIRE_ONCE: // FIXME: implement require and _once
$this->writeStep($pLevel);
$this->writeInclude();
if ($type==self::STATEMENT) return;
$this->beginStatement = true;
break;
case T_CLASS:
case T_CASE:
case T_DEFAULT:
case T_PUBLIC:
case T_PRIVATE:
case T_PROTECTED:
case T_STATIC:
case T_CONST:
case T_GLOBAL:
case T_ABSTRACT:
$this->write($token[1]);
$this->beginStatement = false;
break;
default:
$this->writeStep($pLevel);
$this->write($token[1]);
$this->beginStatement = false;
break;
}
}
} while($this->each());
}
/**
* parse the given PHP script
* @return the parsed PHP script
*/
public function parseScript() {
do {
$this->parseBlock();
} while($this->each());
return $this->output;
}
}
/**
* This structure represents the debugger front-end. It is used by the
* JavaScript code to communicate with the debugger back end.
*/
class pdb_JSDebuggerClient {
private static function getDebuggerFilename() {
$script = __FILE__;
$scriptName = basename($script);
return $scriptName == "PHPDebugger.php" ? $script :"java/PHPDebugger.php";
}
private static function getCurrentRootDir() {
$scriptName = $_SERVER['SCRIPT_NAME'];
$scriptFilename = $_SERVER['SCRIPT_FILENAME'];
$scriptDirName = dirname($scriptName);
$scriptDir = dirname($scriptFilename);
if ((strlen($scriptDirName)>1) && ($scriptDirName[1]=='~')) {
$scriptDirName = ltrim($scriptDirName, "/");
$idx = strpos($scriptDirName, '/');
$scriptDirName = $idx===false ? '' : substr($scriptDirName, $idx);
} elseif ((strlen($scriptDirName)==1) && ($scriptDirName[0]=='/')) {
$scriptDirName = '';
}
return substr($scriptDir, 0, strlen($scriptDir)-strlen($scriptDirName));
}
/*
* Return the script name
* Example: %2Fopt%2Fappserv%2Fapache-tomcat-6.0.14%2Fwebapps%2FJavaBridge%2Ftest.php"
*
* @return An urlencoded file name.
*/
public static function getDebugScriptName() {
return urlencode($_SERVER['SCRIPT_FILENAME']);
}
/**
* Return the debugger URL.
* Example: "/JavaBridge/java/PHPDebugger.php?source=settings.php"
*
* @return The debugger URL.
*/
public static function getDebuggerURL() {
$path = realpath(self::getDebuggerFilename());
if (!$path)
trigger_error("No such file or directory: $path", E_USER_ERROR);
$root = self::getCurrentRootDir();
$scriptName = $_SERVER['SCRIPT_NAME'];
$scriptDirName = dirname($scriptName);
$prefix = '';
if ((strlen($scriptDirName)>1) && ($scriptDirName[1]=='~')) {
$scriptDirName = ltrim($scriptDirName, "/");
$idx = strpos($scriptDirName, '/');
$prefix = '/' . ($idx ? substr($scriptDirName, 0, $idx): $scriptDirName);
}
$path = "${prefix}" . substr($path, strlen($root));
$pathInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : "";
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : "";
$url = "${path}${pathInfo}";
if ($query) $url .= "?${query}";
return $url;
}
public static function getPostData() {
$str = '';
foreach ($_POST as $key => $value) {
if ($str) $str .= '&';
$str .= $key . '=' . urlencode($value);
}
return $str;
}
/**
* Get the server's uniqe session ID
* @return a uniqe session ID
*/
public static function getServerID() {
/*
if (!isset($_SESSION['pdb_ServerID']))
return $_SESSION['pdb_ServerID'] = 1;
else {
$oldId = $_SESSION['pdb_ServerID'];
$conn = self::getConnection($oldId);
$conn->shutdown();
return ++$_SESSION['pdb_ServerID'];
}
*/
// TODO: allow more than one debug session
$oldId = 1;
$conn = self::getConnection($oldId);
$conn->shutdown();
return $oldId;
}
private static function getConnection($id) {
if (!PDB_DISABLE_JAVA && function_exists("java_get_base") && java_server_name())
return new pdb_JavaClientConnection($id);
else
return new pdb_PollingClientConnection($id);
}
/**
* Pass the command and arguments to the debug back end and
* output the response to JavaScript.
*
* @arg array The command arguments
*/
public static function handleRequest($vars) {
$msg = (object)$vars;
if ($msg->cmd == "begin") sleep(1); // wait for the server to settle
pdb_Logger::debug("beginHandleRequest: ".$msg->cmd);
$conn = self::getConnection($msg->serverID);
$conn->write(json_encode($msg));
$response = $conn->read();
if ($msg->cmd == "end") $conn->shutdown();
$output = $response;
echo "($output)";
pdb_Logger::debug("endHandleRequest");
}
}
/**
* The current view frame. Contains the current script name. May be
* selected by clicking on a include() hyperlink Allows users to set
* breakpoints for this file.
*
* View will be discarded when go, step, end is invoked.
*/
class pdb_View {
/** The current script name */
public $scriptName;
/** Back-link to the parent or null */
public $parentView;
protected $bpCounter, $lineCounter, $code;
/**
* Create a new view frame
* @param object the parent frame
* @param string the script name
*/
public function pdb_View($parentView, $scriptName) {
$this->parentView = $parentView;
$this->scriptName = $scriptName;
$this->bpCounter = $this->lineCounter = 1;
$this->code = null;
}
private function lineCB ($val) {
return $val.(string)$this->lineCounter++;
}
private function breakpointCB ($val) {
return $val.'id="bp_'.(string)$this->bpCounter++.'"';
}
function replaceCallback($code, $split, $cb) {
$ar = explode($split, $code);
$last = array_pop($ar);
$ar = array_map($cb, $ar);
array_push($ar, $last);
return implode($ar);
}
/**
* Return a HTML representation of the current script
* @return string the clickable HTML representation of the current script
*/
public function getHtmlScriptSource() {
if (!$this->code) {
$c=
'<span class="breakpoint" id="bp_" onmousedown="return toggleBreakpoint(this, event);">'.
'<span class="currentlineIndicator normal"></span>'.
'<span class="linenumber">line#</span>'.
'<span class="breakpointIndicator normal"></span>'.
'</span><br />';
$code=show_source($this->scriptName, true);
// br => span id=pb_ ...
$code = ereg_replace('<br />', $c, $code);
// handle incomplete last line, identical to preg: '|(?<!<br >)</span>\n</span>\n</code>$|'
$code = ereg_replace('"(([^>])|([^/]>)|([^ ]/>)|([^r] />)|([^b]r />)|([^<]br />))(</span>\n</span>\n</code>)"', '\1 $c \8', $code);
$code = $this->replaceCallback($code, 'id="bp_"', array($this, "breakpointCB"));
$code = $this->replaceCallback($code, 'line#', array($this, "lineCB"));
$this->code = $code;
}
return $this->code;
}
}
/**
* The current view. Used to show the contents of a variable
*/
class pdb_VariableView extends pdb_View {
/**
* Create a new variable view
* @param object the parent frame
* @param string the variable name
* @param string the variable value
*/
public function pdb_VariableView($parentView, $name, $value) {
parent::pdb_View($parentView, $name);
$this->value = $value;
}
/**
* {@inheritDoc}
*/
public function getHtmlScriptSource() {
if (!PDB_DISABLE_JAVA && function_exists("java_get_base") && java_server_name() &&
is_object($this->value) && ($this->value instanceof java_JavaType))
return (highlight_string(java_cast($this->value, "S"), true));
else
return (highlight_string($this->value, true));
}
}
/**
* The current execution frame. Contains the current run-time script
* name along with its state
*/
class pdb_Environment extends pdb_View {
/** bool true if a dynamic breakpoint should be inserted at the next line, false otherwise */
public $stepNext;
/** The execution vars */
public $vars;
/** The current line */
public $line;
/**
* Create a new execution frame
* @param string the script name
* @param bool true if a dynamic breakpoint should be inserted at the next line, false otherwise
*/
public function pdb_Environment($scriptName, $stepNext) {
parent::pdb_View(null, $scriptName);
$this->stepNext = $stepNext;
$this->line = -1;
}
/**
* Update the execution frame with the current state
* @param string the current script name
* @param int the current execution line
* @param mixed the current variables
*/
public function update ($line, &$vars) {
$this->line = $line;
$this->vars = &$vars;
}
}
/**
* Represents a breakpoint
*/
class pdb_Breakpoint {
/** The script name */
public $scriptName;
/** The current line */
public $line;
/** The breakpointName as seen by JavaScript */
public $breakpoint;
/* The breakpoint type (not used yet) */
public $type;
/**
* Create a new breakpoint
* @param string the breakpoint name
* @param string the script name
* @param int the line
*/
public function pdb_Breakpoint($breakpointName, $scriptName, $line) {
$this->breakpoint = $breakpointName;
$this->scriptName = $scriptName;
$this->line = $line;
$this->type = 1;
}
/**
* @return the string representation of the breakpoint
*/
public function __toString() {
return "{$this->line}@{$this->scriptName}, js name: ({$this->breakpoint}, type: {$this->type})";
}
}
/**
* The current debug session. Contains the current environment stack,
* script output and all breakpoints set by the client. An optional
* view is set by the switchView command.
*/
final class pdb_Session {
/** The collection of breakpoints */
public $breakpoints;
/** The environment tree */
public $environments;
/** The current execution frame */
public $currentFrame;
/** The current view */
public $currentView;
/** The script output */
public $output;
/**
* Create a new debug session for a given script
* @param string the script name
*/
public function pdb_Session($scriptName) {
$this->breakpoints = $this->lines = array();
$this->environments = array($this->currentFrame = new pdb_Environment($scriptName, true));
$this->currentView = null;
$this->end = false;
}
/**
* Return the clickable HTML script source, either from the cusom view or from the current frame
* @return string the HTML script source
*/
public function getCurrentViewHtmlScriptSource () {
return $this->currentView ? $this->currentView->getHtmlScriptSource() : $this->currentFrame->getHtmlScriptSource();
}
/**
* Return the current frame script name
* @return string the script name of the current frame
*/
public function getScriptName () {
return $this->currentFrame->scriptName;
}
/**
* Return the current script name, either from the view or from the current frame
* @return string the current script name
*/
public function getCurrentViewScriptName () {
return $this->currentView ? $this->currentView->scriptName : $this->getScriptName();
}
/**
* Return the breakpoints for the current script
* @return object the breakpoints
*/
public function getBreakpoints () {
$bp = array();
foreach ($this->breakpoints as $breakpoint) {
if ($this->getCurrentViewScriptName() != $breakpoint->scriptName) continue;
array_push($bp, $breakpoint->breakpoint);
}
return $bp;
}
/**
* toggle and write breakpoint reply
* @param object the current comm. channel
* @param object the breakpoint
*/
public function writeToggleBreakpoint($channel, $breakpoint) {
$id = $breakpoint."@".$this->getCurrentViewScriptName();
if (!isset($this->breakpoints[$id])) {
$this->breakpoints[$id] = new pdb_Breakpoint($breakpoint, $this->getCurrentViewScriptName(), substr($breakpoint, 3));
$channel->write(array("cmd"=>"setBreakpoint", "scriptName"=>$this->getCurrentViewScriptName(), "breakpoint"=>$breakpoint));
} else {
$bp = $this->breakpoints[$id];
unset ($this->breakpoints[$id]);
$channel->write(array("cmd"=>"unsetBreakpoint", "scriptName"=>$bp->scriptName, "breakpoint"=>$bp->breakpoint));
}
}
/**
* check if there's a breakpoint
* @param string the script name
* @param int the line within the script
* @return true if a breakpoint exists at line, false otherwise
*/
public function hasBreakpoint($scriptName, $line) {
static $first = true;
if ($this->currentFrame->stepNext) return true;
foreach ($this->breakpoints as $breakpoint) {
pdb_Logger::debug("process breakpoint::: $scriptName, $line:: $breakpoint");
if($breakpoint->type==1) {
if ($first && $breakpoint->scriptName==$scriptName&&$breakpoint->line==-1) {
$first = false; return true;
}
if ($breakpoint->scriptName==$scriptName&&$breakpoint->line==$line) return true;
}
}
return false;
}
/**
* parse code
* @param string the script name
* @param string the content
* @return the parsed script
*/
public function parseCode($scriptName, $content) {
$parser = new pdb_Parser($scriptName, $content);
return $parser->parseScript();
}
private static function doEval($__pdb_Code) {
return eval ("?>".$__pdb_Code);
}
/**
* parse and execute script
* @return the script output
*/
public function parseScript() {
$code = $this->parseCode($this->getScriptName(), file_get_contents($this->getScriptName()));
if (PDB_DEBUG) pdb_Logger::debug("eval:::$code,".$this->getScriptName()."\n");
if (!PDB_DEBUG) ob_start();
self::doEval ($code);
$this->output = ob_get_contents();
if(!PDB_DEBUG) ob_end_clean();
return $this->output;
}
}
/**
* This class represents the debugger back end connection. It
* communicates with the debugger front end using a shared-memory queue.
* It is slow, but it does not require any special library.
* @see pdb_JavaServerConnection
*/
class pdb_PollingServerConnection extends pdb_PollingClientConnection {
protected function init() {
$this->role = "server";
$this->to = "client";
}
protected function poll() {
$val = "";
$chanCtr = "pdb_ctr{$this->role}{$this->id}";
$chan = "pdb_{$this->role}{$this->id}";
session_start();
if (!($val = $this->checkTrm())) {
pdb_Logger::debug("...{$this->role}, {$this->id} poll...");
if(!isset($_SESSION[$chanCtr])) {
$_SESSION[$chan] = array();
$_SESSION[$chanCtr]=0;
}
if (count($_SESSION[$chan]) > $_SESSION[$chanCtr]) {
$val = $_SESSION[$chan][$_SESSION[$chanCtr]++];
}
}
session_write_close();
return $val;
}
/**
* shut down the communication channel
*/
public function shutdown() {
pdb_Logger::debug("session terminated: {$this->chanTrm}");
session_start();
$_SESSION[$this->chanTrm] = 1;
session_write_close();
}
}
/**
* This class represents the debugger back end connection. It
* communicates with the debugger front end using a LinkedBlockingQueue.
* Requires the PHP/Java Bridge library.
* @see pdb_PollingServerConnection
*/
class pdb_JavaServerConnection extends pdb_JavaClientConnection {
public function pdb_JavaServerConnection($id) {
parent::pdb_JavaClientConnection($id);
$queue = new java("php.java.bridge.BlockingQueue");
$chan = "pdb_{$this->role}{$this->id}";
$this->session->put($chan, $queue);
$queue = new java("php.java.bridge.BlockingQueue");
$chan = "pdb_{$this->to}{$this->id}";
$this->session->put($chan, $queue);
}
protected function init() {
$this->role = "server";
$this->to = "client";
}
}
/**
* The java script debugger server daemon. Contains a debug session
* and handles debug requests from the client.
*/
class pdb_JSDebugger {
/** The pdb_Session */
public $session;
private $id;
private $end;
private $conn;
private $ignoreInterrupt;
const STEP_INTO = 1;
const STEP_OVER = 2;
const GO = 4;
private function getConnection($id) {
if (!PDB_DISABLE_JAVA && function_exists("java_get_base") && java_server_name())
return new pdb_JavaServerConnection($id);
else
return new pdb_PollingServerConnection($id);
}
/**
* Create new PHP debugger using a given comm. ID
* @param int the communication address
*/
public function pdb_JSDebugger($id) {
$this->id = $id;
$this->conn = $this->getConnection($id);
$this->end = false;
$this->ignoreInterrupt = false;
}
/**
* Return the current comm. ID
* @return int the communication address
*/
public function getServerID() {
return $this->id;
}
/**
* Read data from the front end
* @return object the data
*/
public function read() {
$val = $this->conn->read();
return $val===true?$val:json_decode($val);
}
/**
* Write data to the front end
* @param object the data
*/
public function write($data) {
$data["serverID"] = $this->getServerID();
if (PDB_DEBUG) pdb_Logger::debug("->".print_r($data, true));
return $this->conn->write(json_encode($data));
}
private function ack() {
$this->write(array("cmd"=>$this->packet->cmd));
}
/**
* Handle requests from the front end
*/
public function handleRequests() {
$this->ignoreInterrupt = false;
while(true) {
if (PDB_DEBUG) pdb_Logger::debug("handleRequests: accept");
if (($this->packet = $this->read()) === true) break; // ignore __destructors after shutdown
if (PDB_DEBUG) pdb_Logger::debug("handleRequests: done accept ".$this->packet->cmd);
switch($this->packet->cmd) {
case "status":
$this->write(array("cmd"=>$this->packet->cmd,
"line"=>$this->session->currentFrame->line,
"scriptName"=>$this->session->getCurrentViewScriptName(),
"breakpoints"=>$this->session->getBreakpoints()));
break;
case "extendedStatus":
$this->write(array("cmd"=>$this->packet->cmd,
"line"=>$this->session->currentFrame->line,
"scriptName"=>$this->session->getCurrentViewScriptName(),
"script"=>$this->session->getCurrentViewHtmlScriptSource(),
"breakpoints"=>$this->session->getBreakpoints()));
break;
case "begin":
chdir (urldecode($this->packet->cwd));
$this->session = new pdb_Session(urldecode($this->packet->scriptName));
$this->write(array("cmd"=>$this->packet->cmd,
"scriptName"=>$this->packet->scriptName,
"script"=>$this->session->getCurrentViewHtmlScriptSource()));
$this->session->parseScript();
$this->end = true;
break;
case "stepNext":
if ($this->end) break;
$this->session->currentView = null;
$this->ack();
return self::STEP_INTO;
case "stepOver":
if ($this->end) break;
$this->session->currentView = null;
$this->ack();
return self::STEP_OVER;
case "stepOut":
case "go":
if ($this->end) break;
$this->session->currentView = null;
$this->ack();
return self::GO;
case "toggleBreakpoint":
$this->session->writeToggleBreakpoint($this, $this->packet->breakpoint);
break;
case "switchView":
$name = urldecode($this->packet->scriptName);
if ($name[0]=='$') {
$value = $this->session->currentFrame->vars[substr($name, 1)];
$this->session->currentView = new pdb_VariableView($this->session->currentView, $name, $value);
} else {
$value = eval("return ".$name.";");
if (file_exists($value))
$this->session->currentView = new pdb_View($this->session->currentView, realpath($value));
else
$this->session->currentView = new pdb_VariableView($this->session->currentView, $name, $value);
}
$this->ack();
break;
case "backView":
if ($this->session->currentView)
$this->session->currentView = $this->session->currentView->parentView;
$this->ack();
break;
case "output":
if ($this->session) {
if (!$this->end)
$this->session->output = ob_get_contents();
$this->write(array("cmd"=>$this->packet->cmd,
"output"=>$this->session->output));
} else {
$this->ack();
}
break;
case "end":
$this->session->currentView = null;
$this->ack();
$this->shutdown();
//return;
exit(0);
default:
pdb_Logger::debug("illegal packet: " . print_r($this->packet, true));
exit(1);
}
}
}
/**
* shut down the current comm. channel
*/
public function shutdown() {
$this->conn->shutdown();
}
/**
* called at run-time for each frame
* @return the current frame
*/
public function startCall($scriptName) {
/* check for stepOver and stepOut */
$stepNext = $this->session->currentFrame->stepNext == pdb_JSDebugger::STEP_INTO ? pdb_JSDebugger::STEP_INTO : false;
pdb_Logger::debug("startCall::$scriptName, $stepNext");
return new pdb_Environment($scriptName, $stepNext);
}
protected function resolveIncludePath($scriptName) {
if (file_exists($scriptName)) return realpath($scriptName);
$paths = explode(PATH_SEPARATOR, get_include_path());
$name = $scriptName;
foreach ($paths as $path) {
$scriptName = realpath("${path}${name}");
if ($scriptName) return $scriptName;
}
trigger_error("file $scriptName not found", E_USER_ERROR);
}
/**
* called at run-time for each included file
* @param string the script name
* @return string the code
*/
public function startInclude($scriptName) {
$isDebugger = (basename($scriptName) == "PHPDebugger.php");
if (!$isDebugger)
$scriptName = $this->resolveIncludePath($scriptName);
pdb_Logger::debug("scriptName::$scriptName, $isDebugger");
$stepNext = $this->session->currentFrame->stepNext == pdb_JSDebugger::STEP_INTO ? pdb_JSDebugger::STEP_INTO : false;
$this->session->currentFrame = new pdb_Environment($scriptName, $stepNext);
if ($isDebugger) // do not debug self
$code = "<?php ?>";
else
$code = $this->session->parseCode(realpath($scriptName), file_get_contents($scriptName));
array_push($this->session->environments, $this->session->currentFrame);
pdb_Logger::debug("include:::".$code);
return $code; // eval -> pdb_step/MSG_READY or pdb_endInclude/MSG_READY OR FINISH
}
/**
* called at run-time after the script has been included
*/
public function endInclude() {
array_pop($this->session->environments);
$this->session->currentFrame = end($this->session->environments);
}
/**
* called at run-time for each line
* @param string the script name
* @param int the current line
* @param mixed the execution variables
*/
public function step($scriptName, $line, $vars) {
if ($this->ignoreInterrupt) return; // avoid spurious step calls from __destruct() method
$this->ignoreInterrupt = true;
pdb_Logger::logDebug("step: $scriptName @ $line");
// pull the current frame from the stack or the top-level environment
$this->session->currentFrame = (isset($vars['__pdb_CurrentFrame'])) ? $vars['__pdb_CurrentFrame'] : end($this->session->environments);
unset($vars['__pdb_CurrentFrame']);
$this->session->currentFrame->update($line, $vars);
if ($this->session->hasBreakpoint($scriptName, $line)) {
$stepNext = $this->handleRequests();
pdb_Logger::logDebug("continue");
$this->session->currentFrame->stepNext = $stepNext != pdb_JSDebugger::GO ? $stepNext : false;
}
$this->ignoreInterrupt = false;
pdb_Logger::logDebug("endStep: $scriptName @ $line");
}
}
/**
* Convenience function called by the executor
*/
function pdb_getDefinedVars($vars1, $vars2) {
if(isset($vars2)) $vars1['pbd_This'] = $vars2;
unset($vars1['__pdb_Code']); // see pdb_Message::doEval()
return $vars1;
}
/**
* Convenience function called by the executor
*/
function pdb_startCall($scriptName) {
global $dbg;
return $dbg->startCall($scriptName);
}
/**
* Convenience function called by the executor
*/
function pdb_startInclude($scriptName) {
global $dbg;
return $dbg->startInclude($scriptName);
}
/**
* Convenience function called by the executor
*/
function pdb_endInclude() {
global $dbg;
$dbg->endInclude();
}
/**
* Convenience function called by the executor
*/
function pdb_step($scriptName, $line, $vars) {
global $dbg;
$dbg->step($scriptName, $line, $vars);
}
if (PDB_DEBUG==2) {
$parser = new pdb_Parser("test.php", file_get_contents("test.php"));
echo $parser->parseScript();
exit (2);
}
/* * The JavaScript part, invoked after the debugger has been included() * */
if (!isset($_SERVER['HTTP_XPDB_DEBUGGER'])) {
session_start();
if (!PDB_DISABLE_JAVA && function_exists("java_get_base") && java_server_name()) java_session();
header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate( "D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-Type: text/html");
?>
<html>
<head>
<title>
PHPDebugger version 1.0
</title>
<style type="text/css">
#navigationBar {
display: block;
position: relative;
background: #efefef;
width: 100%;
height: auto;
overflow: hidden;
margin-bottom: 2px;
}
#run {
height: 13px;
width: 17px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAANCAYAAABPeYUaAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwcXGXdF1DwAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABEUlEQVQoz62SoWvDUBDGfx0Rry6VzzUyg4lEVgYmRulfMVUKVWOqTFVWDULVbNxsTSETg8jOzm+QwcSL28ECmwhJGpqwwnrmfXfv7nvf3b2e+TQ//NMsgPRlQfoeQ14E9TBAe0uC9QyAeBoeQfK6IZjuqmC89tHeEoDFxP+TzKqQJK0JksPNlQ/QSWYBiJQVKShd+4DJa+f68hyA0f0M7fR5nKyaSiQTlHwgatB4JXkzB+q8C12RJfNwr522Vr4hy7PjtgOgbAWZKs6SRASt+gfZ8bPBcQck83B/Jl/Fre3S8AGlarx5Kuazu33o2I4atUq1LYi27cUNEj0cE925VdBxxxWOttJZXFrvFN/+jBPYL4uJYFb2zCiIAAAAAElFTkSuQmCC') no-repeat;
}
#terminate {
height: 13px;
width: 13px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYrNECrm4EAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAwUlEQVQoz52SLQ7CQBCFvyaI4nYlciWSI3CEFkVQGAyOcBU0ClCARCKRHGFlN0HsuK4D0RRasWnKJOPel/fmJ/Ev/6ZnDQD89YzcL51iNc3R2ayC5HZkslx3Qs/97gcBEEBOh7jLfNGOh5RY8egQd7HiQcoG9HULPRZRwthagvdR4chapBUPQELVsZKAL8HUkBZApVVHN5FWuhoKzlEYg06HUaYwhuBcO55RGjbxWynANWdSWc5jte3+iCwHIPnn9z7J30SR7ayFNQAAAABJRU5ErkJggg==') no-repeat;
}
#stepInto {
height: 13px;
width: 17px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAANCAYAAABPeYUaAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYtD6f61SMAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAA6ElEQVQoz2N8//r9fwYKAQuMcWy6JlYFmq4lDIIqyYQNOTZdk8Gr8jpWBdvaNRkUPz9nkDSswWkII8w72Fyi6JjMoGmRw7Ct3ZDBKvM6Ye9gU3RsuiaDpkkywTBhIqjizwfiAxbdBQhDfqCIYXMxVkN+fGdgCCqaCzXkPYNXJoS9ri+ZeO84FV1nWNYUDfEKFC9rimZwKrpOWph41d1nWNaWzcDw5zvDsrZsBq+6+/ijOHn+MQbBzxBF73kVGeYmWiHSSZMiigHY1LIwMDAw/Di/lOHaC4giQYljDAxIhqC7AJtaRmrkHQBYX2Q4HZvQSwAAAABJRU5ErkJggg==') no-repeat;
}
#stepOver {
height: 13px;
width: 17px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAANCAYAAABPeYUaAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYsOAZcQW0AAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABSklEQVQoz62TP0jDQBTGv5QMdSgYcEjGgEvHdsyYsW6Kg27SKeJki1PpEAShqJPYKTilHUS3dOyYbu1mhpZmERqIcIEOyRA4h9qaeCcK+uA43uPj9/7cO4GEhOKPJmYdMrMQTJ5A3nxGKO2okCsHkHbr30PIzII/slA9vMO2XGWEUTDG+PEMyXIBpdJiIWuAbjiIXkcYXJUZiHZ0A91wMOzuoVhS8hWRkFDHlCmN55RMbeqYMiUhYY5jypRMbUrjOaMpbGhpBLffgGZ43OFphge33wDSiD+TJAaQJqubY243016a5GKa4UFYP/HAVFFr+1zI8LaM/dNLoKh8BpMFnu9b0M8zkJ9sYKo4vrgGxC0gjdHrNDdJC79dqFrbR6/TZAAA+JXUH1xIy5WIlFRYJ1quoq9ti7ysycTGS/CxqbILZCC8uQn/8XfeAUbdtbmYIYl8AAAAAElFTkSuQmCC') no-repeat;
}
#stepOut {
height: 13px;
width: 17px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAANCAYAAABPeYUaAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYsF62NfDQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABAUlEQVQoz62Tv2vCQBTHP5GsDoJDV8f8C44ZM+Y/EOnSgoOCQ4YOxVE6BH9MoZMdM3TI6CLcJNzmLULGCg4p6HBgoB0SFH9gKvYtj7v3fR/ufe/OSNbJD3dG6RaxGFuIsXUfhB04j0OEfwwyi/q+ZI94NjlsVG2cpyGRb1FvKQCMa54kywAZ9XE9eV78FoSjZ+yWun4S+dnH9aao+QAVBQC43hS2ktDvYLfVXz3RqCjYN5wCiiEpkOos5+vw7RhQbGyqIU2yDNhddfs70TlIFwxsAjTfBZVNnN1IuUbQqJ+i9nFJawJoOWGxykSVBwE5xPFiPl5rOC/xAXlBa/zH3/kFlslu4rTXaTUAAAAASUVORK5CYII=') no-repeat;
}
#output {
height: 13px;
width: 13px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
visibility: visible;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLCQYlB4EnoCoAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABCklEQVQoz42Rv0oDQRCHv4MJbCCFgoUHvkBKXyGPEDufwUokhdFGokWwt7IRbISkTHmvcIUPcUKK3eJgp1g4i92Ld4gxWw2z329+8ye7vF81pcs59J0fVUjpcsZaHCwq3QQBD8Ddcv6vYDF7BDxCACMGgPFov8iIgQACChKTVw9rvCrqPK52+FopPjodCBA0Og1H0el5Nv1VXcNPPDQGHAhBMcnpZrlOJFi1aK1orXhVNm/zxGnbXnRaXE//nEchcm17ZpB+ggImIaaDx9gMaBfhQeD95bVfWiLQi4W48vzkmM1ndfBx89OczG5t001ePBVUX1UPWt1OesLMbm2zA4Puhk3n7LucxQLfZ4Norb3ftQMAAAAASUVORK5CYII=') no-repeat;
}
#backView {
height: 13px;
width: 16px;
display: inline-block;
position: relative;
margin: 1px 10px 1px 10px;
visibility: visible;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAANCAYAAACgu+4kAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwc3GnvIoSQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABH0lEQVQoz5WToU4DQRCGvzZLspUn+wpIJLLyJDiQEBLMJZDAA1QgTlRUU1tXCY+A5BGoPHFiKkhukm4yiD3CNr3S9k8mu/l3Z+af2dme1GJ04HM6hBPP2f2S/9DvIj/KjNG4gUbZh36Xc15GURr2B3Abzi8Z+cQABTyqkdu8BTjP+WMV91KLSS22eMDMGjOrzNZfZuvKzCSxJlnN3p4wqcVclD3kYlJBWEJQCACrJLNvVwXnwWVoSErQbwUEwgq0+ZMa2JYfBuAV1aSJo7EwvzsFmpj515y2/WjNKbim5SN66Ry8P2dcTRexDGBWXDNwHSoc5GPZfoW8FGZFxs30FYCBi9xRc3BZCrPiNoZ2/rg5SIPMi+GO0030dv2FQ/EDM7CYPt7DsBMAAAAASUVORK5CYII=') no-repeat;
}
.normal {
background: transparent;
}
.selected {
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYQB8PJFa8AAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABNElEQVQoz4WPsUsCYRjGf8YNNzTo7vJBDgUNHTSc4KBbro6ORy5KU5tN0VhjS+FfEDXaEFxbY9cQuQSfQ3BCwyck3At9YIOieZo98MAL7/vjed6MMWYMcH6aQxUqePsBaqvKOm0A6PcQpaDoh4QPdcL7E8xQr4EsmC9BLKg8NA8hm72kc+Xx9Hi2GhIryMgAIHZibw9aDZDRBZ3rIs9RZ7neTDK3C1RKUC336L0cc3tTR/fDFGTByLLdTagegMp36d7VAHAWQuSPzy0Mh5BM987vxSoojiGKQBUCgkYzBQGSzOdkBNEr4Pj45QBvtza7XkhCILGg+6A1FEttPL+F67oL6RPIcZFveJse72wHBEdtctncyhcz5tOM40GM1iHxR4jnN1F5L1U8DRkzFhGwTGo4/KsfXjWDCQ6TmRMAAAAASUVORK5CYII=') no-repeat;
}
.breakpointSet {
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kLBwYOGJqAJ4UAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAA+0lEQVQoz5XSMUvDUBSG4bcXhyM4pFsudBE6GEfB5UKGZLOjq5uCIE7iPyjdxEXQoZC/4OgipIOQbqZDMW6OcbsZBO8Q0MEWkWJJ3vl7lsPpWGu/WOQqy8s44X2S8ukcmyL4Uczu6QnidZczOktUPqY8HB/Bh2OlLWEwTtAHg19kXwvuQwM1/7cBh08Z3Z0ABZCena8HAPViB6hymlHNcppUzXLKaYaq5gVtquYFitq1QtQO5fWDVsbrBygdGqTnNwLS89GhQSFCfJc0QvHNLYj8nFyHBjMcrQVmOEJH8d+PALD5M/nVNW+TFJwDEbajmODiEr2/t/pGbfoGcP1aToLr9OAAAAAASUVORK5CYII=') no-repeat;
}
#navigationBar {
display: block;
position: fixed;
top: 0;
left: 0;
height: 20px;
width: 100%;
z-index: 100;
}
#code {
display: block;
position: absolute;
left: 92px;
top: 22px;
z-index: 50;
}
.breakpoint {
display: inline;
position: absolute;
left: -92px;
width: 90px;
height: 13px;
background: #efefef;
overflow: hidden;
}
.linenumber {
display: inline-block;
position: relative;
width: 59px;
height: 13px;
text-align: right;
margin-right: 5px;
float: right;
color: black;
}
.currentlineIndicator {
display: inline-block;
position: relative;
width: 13px;
height: 13px;
}
.breakpointIndicator {
display: inline-block;
position: relative;
width: 13px;
height: 13px;
}
</style>
<script type="text/javascript">
var http = createRequestObject();
var httpCtrl = createRequestObject();
var serverID = <?php echo pdb_JSDebuggerClient::getServerID(); ?>;
var scriptName = "<?php echo pdb_JSDebuggerClient::getDebugScriptName(); ?>";
var currentScriptName = "";
var cwd = "<?php echo urlencode(getcwd()); ?>";
var debuggerURL = "<?php echo pdb_JSDebuggerClient::getDebuggerURL(); ?>";
var date = "<?php echo gmdate( 'D, d M Y H:i:s').' GMT'; ?>";
function getServerID() {
return serverID;
}
function setServerID(port) {
serverID = port;
}
function createRequestObject() {
var req;
var browser = navigator.appName;
if (browser ==" Microsoft Internet Explorer") {
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
req = new XMLHttpRequest();
}
return req;
}
function doCmd(text) {
switch(text.cmd) {
case 'stepNext':
case 'stepOver':
case 'go':
case 'switchView':
case 'backView':
case 'begin':
case 'stepOut': getStatusCB(text); break;
case 'output': showOutputCB(text); break;
case 'status': showStatusCB(text); break;
case 'extendedStatus': showExtendedStatusCB(text); break;
case 'setBreakpoint': setBreakpointCB(text); break;
case 'unsetBreakpoint': unsetBreakpointCB(text); break;
case 'end': endCB(text); break;
default: alert("illegal cmd: " + text.cmd); break;
}
}
function sendCmd(cmd) {
var url = debuggerURL;
data = cmd+"&serverID="+getServerID();
http.open("POST", url, true);
http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
http.setRequestHeader("Last-Modified", date);
http.setRequestHeader("Pragma", "no-cache");
http.setRequestHeader("Expires", "Sat, 1 Jan 2005 00:00:00 GMT");
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-Length", data.length);
http.setRequestHeader("XPDB-DEBUGGER", 0);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
doCmd(eval(http.responseText));
}
}
http.send(data);
}
function startServer() {
var url = debuggerURL;
data = "<?php echo pdb_JSDebuggerClient::getPostData(); ?>";
method = "<?php echo $_SERVER['REQUEST_METHOD']; ?>";
httpCtrl.open(method, url, true);
httpCtrl.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
httpCtrl.setRequestHeader("Last-Modified", date);
httpCtrl.setRequestHeader("Pragma", "no-cache");
httpCtrl.setRequestHeader("Expires", "Sat, 1 Jan 2005 00:00:00 GMT");
httpCtrl.setRequestHeader("Content-Length", data.length);
httpCtrl.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpCtrl.setRequestHeader("XPDB-DEBUGGER", getServerID());
httpCtrl.onreadystatechange = function() {
if(httpCtrl.readyState == 4 && httpCtrl.status == 200) {
// alert("debugger exited. Debugger debug output: " +httpCtrl.responseText);
document.getElementById("code").innerHTML = httpCtrl.responseText;
}
}
httpCtrl.send(data);
}
function stepNext() {
sendCmd("cmd=stepNext");
}
function stepOver() {
sendCmd("cmd=stepOver");
}
function stepOut() {
sendCmd("cmd=stepOut");
}
function getStatusCB(cmd) {
setServerID(cmd.serverID);
sendCmd("cmd=status");
}
function loaded() {
startServer();
sendCmd("cmd=begin&scriptName="+scriptName+"&cwd="+cwd);
}
function toggleBreakpoint(el, event) {
sendCmd("cmd=toggleBreakpoint&breakpoint="+el.id);
return false;
}
function setBreakpointCB(cmd) {
setServerID(cmd.serverID);
document.getElementById(cmd.breakpoint).lastChild.className="breakpointIndicator breakpointSet";
}
function unsetBreakpointCB(cmd) {
setServerID(cmd.serverID);
document.getElementById(cmd.breakpoint).lastChild.className="breakpointIndicator normal";
}
function showOutputCB(cmd) {
setServerID(cmd.serverID);
currentScriptName = "";
document.getElementById("code").innerHTML = cmd.output;
}
function doShowStatusCB(cmd) {
lines = document.getElementsByClassName("currentlineIndicator");
for (i=0; i<lines.length; i++) {
line = lines[i];
line.className = "currentlineIndicator normal";
}
for (i=0; i<cmd.breakpoints.length; i++) {
breakpoint = cmd.breakpoints[i];
document.getElementById(breakpoint).lastChild.className="breakpointIndicator breakpointSet";
}
currentLine = document.getElementById("bp_"+(cmd.line)).firstChild;
currentLine.className="currentlineIndicator selected";
code = document.getElementById("code");
codeLine = currentLine.parentNode;
scrollBarHeight = 30;
if ((codeLine.offsetTop - document.body.scrollTop + currentLine.clientHeight + scrollBarHeight + code.clientTop > document.body.clientHeight) ||
(codeLine.offsetTop - document.body.scrollTop + code.clientTop <= 0)) {
currentLine.scrollIntoView(false);
}
}
function showStatusCB(cmd) {
setServerID(cmd.serverID);
if (currentScriptName == cmd.scriptName)
doShowStatusCB(cmd);
else
sendCmd("cmd=extendedStatus"); // another round-trip
}
function showExtendedStatusCB(cmd) {
setServerID(cmd.serverID);
currentScriptName = cmd.scriptName;
document.getElementById("code").innerHTML = cmd.script;
document.title = cmd.scriptName;
doShowStatusCB(cmd);
}
function stepInto(el, event) {
sendCmd("cmd=stepNext");
return false;
}
function stepOver(el, event) {
sendCmd("cmd=stepOver");
return false;
}
function stepOut(el, event) {
sendCmd("cmd=stepOut");
return false;
}
function end(el, event) {
sendCmd("cmd=end");
return false;
}
function endCB(cmd) {
setServerID(cmd.serverID);
document.getElementById("code").innerHTML = "";
document.title = "PDB";
}
function go(el, event) {
sendCmd("cmd=go");
return false;
}
function switchView(data) {
sendCmd("cmd=switchView&scriptName="+data);
return false;
}
function backView(el, event) {
sendCmd("cmd=backView");
return false;
}
function output(el, event) {
sendCmd("cmd=output");
return false;
}
function mousemove(el, event) {
}
function trim(str) {
return str.replace(/^\s*/, "").replace(/\s*$/, "");
}
function mousedown(el, event) {
if (event.target.parentNode.className=="breakpoint") return true;
if (event.target && event.target.firstChild && event.target.firstChild.data) {
switchView(trim(event.target.firstChild.data));
}
return false;
}
</script>
<noscript>
Please enable JavaScript in your browser.
</noscript>
</head>
<body>
<div id="navigationBar">
<a id="run" onmousedown="return go(this, event);"></a>
<a id="terminate" onmousedown="return end(this, event);"></a>
<a id="stepInto" onmousedown="return stepInto(this, event);"></a>
<a id="stepOver" onmousedown="return stepOver(this, event);"></a>
<a id="stepOut" onmousedown="return stepOut(this, event);"></a>
<a id="output" onmousedown="return output(this, event);"></a>
<a id="backView" onmousedown="return backView(this, event);"></a>
</div>
<div onmousemove="return mousemove(this, event);" onmousedown="return mousedown(this, event);" id="code"><span>loading...</span>
</div>
</body>
<script type="text/javascript">
loaded();
</script>
</html>
<?php
exit (0);
} elseif (($serverID = $_SERVER['HTTP_XPDB_DEBUGGER']) != "0") {
/* * The back end part, invoked from JavaScript using a json call. $serverID is a uniq ID generated from JavaScript * */
header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate( "D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-Encoding: identity");
$dbg = new pdb_JSDebugger((int)$serverID);
$dbg->handleRequests();
pdb_Logger::debug("SERVER TERMINATED!");
exit(0);
} else {
/* * The front end part, invoked from JavaScript using json calls * */
header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate( "D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-Encoding: identity");
pdb_JSDebuggerClient::handleRequest ($_POST);
exit(0);
}
?>