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
|
/*
* SPL - The SPL Programming Language
* Copyright (C) 2004, 2005, 2006 Clifford Wolf <clifford@clifford.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* mod_webdebug.spl: WebSPL Debugger
*/
/**
* A module that implements an SPL debugger that can be used with a Web
* Interface.
*
* Only load that module when you are in a save test environment do not let
* end-users access the debugger frontend!
*/
load "cgi";
load "task";
load "encode_xml";
var __webdebug_id_counter = 0;
var __webdebug_help_message = <:help>
:
: <h3>This is the WebSPL Debugger</h3>
:
: <font size="-1">
:
: <p>
: On the left hand side there is a tree-view of the current virtual machine
: state. Navigating thru it should be very intuitive. The colored letters next
: to the node name have the folowing meaning:
: </p>
:
: <table align="center" width="90%" cellpadding="0" cellspacing="0">
:
: <tr>
:
: <td width="15"><font color="#ff0000" size="-1">V</font></td>
: <td><font size="-1">has a value assigned</font></td>
:
: <td width="15"><font color="#00ff00" size="-1">S</font></td>
: <td><font size="-1">has child nodes (subs)</font></td>
:
: </tr><tr>
:
: <td width="15"><font color="#0000ff" size="-1">P</font></td>
: <td><font size="-1">pointer (reference)</font></td>
:
: <td width="15"><font color="#0000ff" size="-1">C</font></td>
: <td><font size="-1">has context pointer</font></td>
:
: </tr><tr>
:
: <td width="15"><font color="#ff00ff" size="-1">F</font></td>
: <td><font size="-1">function or method</font></td>
:
: <td width="15"><font color="#ff00ff" size="-1">R</font></td>
: <td><font size="-1">return pointer</font></td>
:
: </tr><tr>
:
: <td width="15"><font color="#00ffff" size="-1">H</font></td>
: <td><font size="-1">hosted namespace</font></td>
:
: <td width="15"><font color="#ffff00" size="-1">O</font></td>
: <td><font size="-1">class (object)</font></td>
:
: </tr><tr>
:
: <td width="15"><font color="#ffffff" size="-1">f</font></td>
: <td><font size="-1">function context</font></td>
:
: <td width="15"><font color="#ffffff" size="-1">o</font></td>
: <td><font size="-1">object context</font></td>
:
: </tr><tr>
:
: <td width="15"><font color="#ffffff" size="-1">l</font></td>
: <td><font size="-1">local context</font></td>
:
: <td width="15"><font color="#ffffff" size="-1">r</font></td>
: <td><font size="-1">root context</font></td>
:
: </tr>
:
: </table>
:
: <p>
: You can also run SPL code. Just enter the code in the form below. The code is
: always executed in the context of the node you have currently selected in the
: tree.
: </p>
:
: </font>
:
</help>;
function __webdebug_main() {
var show_tasks = 1;
var show_mods = 1;
var tree_open;
var info;
while (1)
{
if (declared cgi.param.c) {
write(<:>
: <html><head></head><body>
: <script><!--
: window.close();
: //--></script>
: </body></html>
</>);
task_kill();
}
if (declared cgi.param.s)
if (declared tree_open.[cgi.param.s])
delete tree_open.[cgi.param.s];
else
tree_open.[cgi.param.s] = undef;
if (declared cgi.param.i)
info = cgi.param.i;
if (declared cgi.param.o)
info = cgi.param.o;
if (declared cgi.param.r)
info = tree_open = undef;
if (declared cgi.param.m)
show_mods = !show_mods;
if (declared cgi.param.t)
show_tasks = !show_tasks;
if (declared cgi.param.x) {
__webdebug_gettree(tree_open, "${cgi.url}?sid=${cgi.sid}", info, show_tasks, show_mods);
write(<:>
: <html><head>
: <title>WebSPL Debug Window</title>
: </head><body bgcolor="#444444" link="#000000" vlink="#000000" alink="#666666">
:
: <table width="100%" height="100%">
: <tr><td valign="top" bgcolor="#cccccc">
: <h4>Executed SPL Code:</h4>
: <pre>${ xml::cgi.param.x }</pre>
:
: <p/> <p/>
: <div align="center">
: <form action="${cgi.url}" method="post">
: <input type="hidden" name="sid" value="${cgi.sid}">
: <input type="submit" value="Continue" />
: </form>
: </div>
:
: </td></tr>
: <tr><td valign="top" bgcolor="#cccccc">
: <h4>Output:</h4>
</>);
write(<:>
: ${ __webdebug_exec(cgi.param.x) }
: </td></tr>
: </table>
:
: </body></html>
</>);
} else
write(<:>
: <html><head>
: <title>WebSPL Debug Window</title>
: <style type="text/css"><!--
: a { text-decoration:none; }
: --></style>
: </head><body bgcolor="#444444" link="#000000" vlink="#000000" alink="#666666">
:
: <table width="100%" height="100%">
: <tr><td width="10%" valign="top" rowspan="2" bgcolor="#aaaaaa">
:
: <table height="100%" cellpadding="0">
: <tr><td valign="top">
:
: <h4>[ <a href="${cgi.url}?sid=${cgi.sid}&r=1">Reset</a> ]</h4>
: <tt><font size="-1">
: ${ __webdebug_gettree(tree_open, "${cgi.url}?sid=${cgi.sid}", info, show_tasks, show_mods) }
: </font></tt>
:
: </td></tr>
: <tr><td valign="bottom">
:
: <p/>
: <table cellpadding="0"><tr>
: <td><b>${ show_tasks ? "ON" : "OFF" } </b></td>
: <td><a href="${cgi.url}?sid=${cgi.sid}&t=1"><nobr>Show Tasks</nobr></a></td>
: </tr><tr>
: <td><b>${ show_mods ? "ON" : "OFF" } </b></td>
: <td><a href="${cgi.url}?sid=${cgi.sid}&m=1"><nobr>Show Modules</nobr></a></td>
: </tr></table>
:
: </td></tr>
: </table>
:
: </td>
:
: <td width="90%" height="250" valign="top" bgcolor="#cccccc">
: ${ defined info ? __webdebug_getinfo(info, "${cgi.url}?sid=${cgi.sid}") : __webdebug_help_message }
: </td></tr>
:
: <tr><td ${ defined info ? 'width="50%"' : '' } valign="top" bgcolor="#cccccc">
: <form action="${cgi.url}" method="post">
: <input type="hidden" name="sid" value="${cgi.sid}">
: <textarea name="x" style="width:100%;" rows="5">
: </textarea>
: <div align="right">
: <nobr><input type="submit" value="Run this SPL code!" />
: <input type="submit" name="c" value="Close Debugger" /></nobr>
: </div>
: </form>
: </td></tr>
:
: </table>
:
: </body></html>
</>);
task_pause();
}
}
/**
* Create a Web Deugger task and return the URI for it.
* E.g.:
*
* <script><!--
* window.open("${webdebug()}", "",
* "width=600,height=500,resizable=yes,scrollbars=yes");
* //--></script>
*/
function webdebug() {
var dbg_id = "webdebug_${__webdebug_id_counter}";
task_create(dbg_id, "while (1) { __webdebug_main(); }");
task_public(dbg_id);
return "${cgi.url}?sid=${cgi.sid_vm ~ ":" ~ dbg_id}";
}
|