| Method from org.apache.bsf.dbline.JsDb Detail: |
public void addBreakpoint(String buffername,
int lineno) throws RemoteException {
Buffer buffer = findBufferWithShortName(buffername);
if (buffer != null) {
BreakPoint bp = new BreakPoint();
bp.m_lineno = lineno;
bp.m_buffer = buffer;
buffer.addBreakpoint(bp);
gBsfManager.placeBreakpointAtLine(bp.m_id, buffer.getURI(),
lineno);
System.out.println("Breakpoint " + bp.m_id + " at "
+ (bp.m_lineno + 1));
}
}
|
public Buffer addBuffer(String filename,
String uri) {
Buffer buffer = findBufferWithURI(uri);
if (buffer == null) buffer = Buffer.factory(filename, uri);
if (buffer != null) {
m_buffers.addElement(buffer);
System.out.println("Loaded buffer: " + uri);
}
return buffer;
}
|
public boolean cmdParser(String line) throws RemoteException {
String cmd, args;
StringTokenizer cmdTokenizer = new StringTokenizer(line, " ", false);
if (cmdTokenizer.hasMoreTokens()) {
cmd = cmdTokenizer.nextToken();
cmd = cmd.trim();
cmd = cmd.toLowerCase();
if (cmd.equals("load")) {
return parseLoad(cmdTokenizer);
}
else if (cmd.equals("put")) {
if (m_inCallback) {
args = line.substring(line.indexOf(" "));
parsePut(args);
}
else System.out.println("Not in a callback...");
}
else if (cmd.equals("usage") || cmd.equals("help")) {
showUsage();
}
else if (cmd.equals("step")) {
if (m_inCallback) return parseStep(cmdTokenizer);
else System.out.println("Not in a callback...");
}
else if (cmd.equals("br")) {
return parseBreakpoint(cmdTokenizer);
}
else if (cmd.equals("rm")) {
return parseRemoveBreakpoint(cmdTokenizer);
}
else if (cmd.equals("set_entry_exit")) {
return parseSetEntryExit(cmdTokenizer);
}
else if (cmd.equals("exec")) {
if (m_inCallback) return parseExec(cmdTokenizer);
else System.out.println("Not in a callback...");
}
else if (cmd.equals("up")) {
if (m_inCallback) up();
else System.out.println("Not in a callback...");
}
else if (cmd.equals("down")) {
if (m_inCallback) down();
else System.out.println("Not in a callback...");
}
else if (cmd.equals("run")) {
if (m_inCallback) {
m_jse.run();
return true;
}
else System.out.println("Not in a callback...");
}
else if (cmd.equals("show")) {
return parseShow(cmdTokenizer);
}
else if (cmd.equals("list")) {
return parseList(cmdTokenizer);
}
else if (cmd.equals("thrinfo")) {
if (m_inCallback) showThrInfo();
else System.out.println("Not in a callback...");
}
else if (cmd.equals("quit")) {
exitDebugger(0);
}
else if (cmd.equals("")) {
// Ignore bogus user input.
}
else System.out.println("Unrecognized command: " + cmd +
"\nTo see valid commands, type usage");
}
return false;
}
|
public void createdEngine(JsEngine engine) throws RemoteException {
m_jse = engine;
m_jse.setDebugger(callbacks);
undefined = m_jse.getUndefinedValue();
}
|
public void deletedEngine(JsEngine engine) {
if (m_jse == engine || m_jse.equals(engine)) m_jse = null;
}
|
public void down() {
m_currentDepth--;
if (m_currentDepth < 0) m_currentDepth = 0;
}
|
public static void exitDebugger(int status) {
inCallback(false);
BSFConnect.disconnect();
exitStatus = status;
running = false;
}
|
public void handleBreakpointHit(JsContext top) throws RemoteException {
int d, lineno;
JsContext cx;
String name;
Buffer buffer;
JsEngine jse = top.getEngine();
if (m_jse != jse) throw new Error();
m_stackDepth = m_jse.getContextCount();
System.out.println("\n stack depth="+m_stackDepth);
if (m_stackDepth < = 0)
throw new RemoteException("Error: Stack cannot be empty.");
m_stack = new Context[m_stackDepth];
for (d = 0; d < m_stackDepth; d++) {
cx = m_jse.getContext(d);
name = cx.getSourceName();
buffer = findBufferWithURI(name);
m_stack[d] = new Context(cx, buffer);
}
m_currentDepth = 0;
lineno = m_stack[0].getCurrentLine();
name = m_stack[0].getBufferName();
System.out.println(" in JSP " + name + " at line " + (lineno + 1));
inCallback(true);
}
initialize the engine. put the manager into the context -> manager
map hashtable too. |
public void handleEngineStopped(JsContext cx) {
}
|
public void handleExceptionThrown(JsContext top,
Object exception) throws RemoteException {
int d, lineno;
String name;
JsContext cx;
Buffer buffer;
JsEngine jse = top.getEngine();
if (m_jse != jse) throw new Error();
m_stackDepth = m_jse.getContextCount();
m_stack = new Context[m_stackDepth];
for (d = 0; d < m_stackDepth; d++) {
cx = m_jse.getContext(d);
name = cx.getSourceName();
buffer = findBufferWithURI(name);
m_stack[d] = new Context(cx, buffer);
}
m_currentDepth = 0;
lineno = m_stack[0].getCurrentLine();
name = m_stack[0].getBufferName();
System.out.println("Exception thrown at line " + name
+ ":" + (lineno + 1) + " reached.");
inCallback(true);
}
|
public void handleSteppingDone(JsContext top) throws RemoteException {
int d, lineno;
JsContext cx;
String name;
Buffer buffer;
JsEngine jse = top.getEngine();
if (m_jse != jse) throw new Error();
m_stackDepth = m_jse.getContextCount();
System.out.println("\n stack depth="+m_stackDepth);
if (m_stackDepth < = 0)
throw new RemoteException("Error: Stack cannot be empty.");
m_stack = new Context[m_stackDepth];
for (d = 0; d < m_stackDepth; d++) {
cx = m_jse.getContext(d);
name = cx.getSourceName();
buffer = findBufferWithURI(name);
m_stack[d] = new Context(cx, buffer);
}
m_currentDepth = 0;
lineno = m_stack[0].getCurrentLine();
name = m_stack[0].getBufferName();
System.out.println("Stepped to line " + name
+ ":" + (lineno + 1) + " reached.");
inCallback(true);
}
initialize the engine. put the manager into the context -> manager
map hashtable too. |
public void listBreakpoints() {
Enumeration e = m_buffers.elements(), ebp;
BreakPoint bp;
Buffer buffer;
while (e.hasMoreElements()) {
buffer = (Buffer) e.nextElement();
System.out.println("Buffer " + buffer.getName());
ebp = buffer.getBreakpoints();
while (ebp.hasMoreElements()) {
bp = (BreakPoint) ebp.nextElement();
System.out.println("Breakpoint " + bp.m_id
+ " at " + (bp.m_lineno + 1));
}
}
}
|
public void listBuffer() {
String line, name;
int d, start, end;
Context cx;
Buffer buffer;
if (m_stack == null) return;
cx = m_stack[m_currentDepth];
name = cx.getBufferName();
buffer = cx.getBuffer();
start = cx.getCurrentLine();
listBufferLines(buffer, start - 5, 10, cx);
}
|
public void listBuffer(String buffername,
int start) {
Buffer buffer = findBufferWithShortName(buffername);
Context cx = null;
int d;
if (buffer == null) return;
for (d = 0; d < m_stackDepth; d++) {
cx = m_stack[d];
if (buffer == cx.getBuffer()) break;
cx = null;
}
listBufferLines(buffer, start, 10, cx);
}
|
public void listBufferLines(Buffer buffer,
int start,
int count,
Context cx) {
String line;
int d, l;
if (start < 0) start = buffer.getCurrentLine();
for (l = start; l < start + count; l++) {
line = buffer.getLine(l);
if (line == null)
break;
if (cx != null && l == cx.getCurrentLine())
System.out.print("- > " + (l+1) + ":");
else
System.out.print(" " + (l+1) + ":");
System.out.println(line);
}
buffer.setCurrentLine(l);
}
|
public void listBuffers() {
Enumeration e = m_buffers.elements();
Buffer buffer;
while (e.hasMoreElements()) {
buffer = (Buffer) e.nextElement();
System.out.println(buffer.getName());
}
}
|
public void listFrames() {
int d;
Context cx;
for (d = m_currentDepth; d < m_stackDepth; d++) {
cx = m_stack[d];
System.out.print(cx.getBufferName());
System.out.println(":" + (cx.getCurrentLine() + 1));
}
}
|
public static void main(String[] args) {
try {
Object lock = new Object();
String host =
System.getProperty("org.apache.bsf.dbline.hostName");
while (gBsfManager == null && exitStatus == 0) {
try {
gBsfManager =
BSFConnect.connect(host, -1);
} catch (ProtocolException pe) {
System.out.println(pe.getMessage());
exitStatus = 1;
continue;
} catch (ConnectException ce) {
System.out.println(ce.getMessage());
exitStatus = 2;
continue;
} catch (Throwable re) {
gBsfManager = null;
}
if (gBsfManager != null) {
new JsDb(args);
}
else {
System.out.println("Manager not there yet, sleeping.");
synchronized (lock) {
try {
lock.wait(10000);
} catch (InterruptedException ie) {
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
return;
}
if (exitStatus > 0) System.exit(exitStatus);
}
|
public boolean parseCmd(String line) throws RemoteException {
boolean resume = cmdParser(line);
if (m_inCallback) {
try {
m_jse.poll();
} catch (RemoteException ex) {
resume = true;
}
}
return resume;
}
Parses a command line.
Returns true if input needs to be suspended,
that is, if the command was to resume execution
in the debugged engine. |
JsObjectProxy proxyObject(JsObject obj) {
if (obj == null) return null;
JsObjectProxy proxy = (JsObjectProxy) m_proxies.get(obj);
if (proxy == null) {
Integer oid;
proxy = new JsObjectProxy(obj);
m_proxies.put(obj, proxy);
oid = new Integer(proxy.getOid());
m_rot.put(oid, proxy);
}
return proxy;
}
This returns a proxy object for a remote JsObject.
The debugger maintains a hashtable of its proxies
keyed on JsObject. |
public String readCmd() {
int count = 0;
char c, chars[] = new char[JSDB_CMD_LEN];
if (m_inCallback) System.out.print(" > ");
else System.out.print("< ");
while (count < JSDB_CMD_LEN) {
try {
c = (char) System.in.read();
chars[count++] = c;
if (c == '\n")
break;
} catch (IOException ex) {
return null;
}
}
if (count == JSDB_CMD_LEN) {
System.out.println("\nLine too long.\n");
return null;
}
return new String(chars, 0, count);
}
|
public void run() {
String cmd;
boolean resume = false;
running = true;
while (running) {
cmd = readCmd();
try {
if (cmd != null) resume = parseCmd(cmd);
if (resume) inCallback(false);
} catch (Throwable t) {
System.err.println("\nError while parsing/executing command.");
t.printStackTrace();
}
}
System.exit(exitStatus);
}
|
public void showCurrentFrame() throws RemoteException {
int d, n, index;
Context cx = m_stack[m_currentDepth];
JsContext jscx = cx.getJsContext();
JsObject scope = jscx.getScope(), args;
boolean notAfunction = false;
Object ids[], value;
String name;
JsObjectProxy proxy;
System.out.print("\nCurrent frame: " + cx.getBufferName());
System.out.println(":" + cx.getCurrentLine());
System.out.println("\nProperties in scope: ");
while (scope != null) {
proxy = proxyObject(scope);
displayProperties(proxy, false);
scope = scope.getScope();
}
}
|
public void showObject(Integer oid,
boolean all) throws RemoteException {
JsObjectProxy proxy = (JsObjectProxy) m_rot.get(oid);
if (proxy == null) System.out.println("Unknown object < "
+ oid + " > !");
else displayProperties(proxy, all);
}
|
public void showPrototype(Integer oid,
boolean all) throws RemoteException {
JsObjectProxy proxy = (JsObjectProxy) m_rot.get(oid);
if (proxy == null) System.out.println("Unknown object < "
+ oid + " > !");
else displayPrototype(proxy, all);
}
|
public void showScope(Integer oid,
boolean all) throws RemoteException {
JsObjectProxy proxy = (JsObjectProxy) m_rot.get(oid);
if (proxy == null) System.out.println("Unknown object < "
+ oid + " > !");
else displayScope(proxy, all);
}
|
public void showThrInfo() {
try {
System.out.println("Thread: " + m_jse.getThread());
System.out.println("ThreadGroup: " + m_jse.getThreadGroup());
} catch (RemoteException ex) {
ex.printStackTrace();
return;
}
}
|
public void up() {
m_currentDepth++;
if (m_currentDepth >= m_stackDepth) m_currentDepth = m_stackDepth - 1;
}
|