Fix breakpoint handling

This commit is contained in:
James Roseborough
2007-08-11 05:29:56 +00:00
parent add892968d
commit 79d5642bfd
2 changed files with 28 additions and 17 deletions

View File

@@ -25,22 +25,27 @@ public class DebugStackState extends StackState implements DebugRequestListener
public void debugHooks( int pc ) { public void debugHooks( int pc ) {
if ( exiting ) if ( exiting )
throw new java.lang.RuntimeException("exiting"); throw new java.lang.RuntimeException("exiting");
if ( ! suspended )
return;
synchronized ( this ) { synchronized ( this ) {
// vm is in suspended state, although it might also
// be stepping to the next instruction at the same time. // anytime the line doesn't change we keep going
// in either case we need the current line number
int[] li = calls[cc].closure.p.lineinfo; int[] li = calls[cc].closure.p.lineinfo;
int line = (li!=null && li.length>pc? li[pc]: -1); int line = (li!=null && li.length>pc? li[pc]: -1);
if ( stepping ) { if ( lastline == line )
if ( lastline == line ) return;
return;
stepping = false;
}
// save line in case next op is a step // save line in case next op is a step
lastline = line; lastline = line;
if ( stepping )
stepping = false;
// check for a break point if we aren't suspended already
if ( ! suspended ) {
if ( breakpoints.containsKey(line) )
suspended = true;
else
return;
}
// wait for a state change // wait for a state change
while ( suspended && (!exiting) && (!stepping) ) { while ( suspended && (!exiting) && (!stepping) ) {
@@ -146,12 +151,12 @@ public class DebugStackState extends StackState implements DebugRequestListener
public String callgraph() { public String callgraph() {
int n = cc; int n = cc;
if ( n < 0 || n >= calls.length ) if ( n < 0 || n >= calls.length )
return "<empty>"; return "";
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for ( int i=0; i<n; i++ ) { for ( int i=0; i<=n; i++ ) {
CallInfo ci = calls[i]; CallInfo ci = calls[i];
// TODO: fill this out with proper format, names, etc. // TODO: fill this out with proper format, names, etc.
sb.append( String.valueOf(ci) ); sb.append( String.valueOf(ci.closure.p) );
sb.append( "\n" ); sb.append( "\n" );
} }
return sb.toString(); return sb.toString();

View File

@@ -24,6 +24,7 @@ public class DebugStackStateTest extends TestCase {
// suspend the vm right away // suspend the vm right away
state.suspend(); state.suspend();
state.set( 14 );
// start the call processing in its own thread // start the call processing in its own thread
new Thread() { new Thread() {
@@ -36,10 +37,10 @@ public class DebugStackStateTest extends TestCase {
} }
}.start(); }.start();
// step for 25 steps // step for 5 steps
for ( int i=0; i<10; i++ ) { for ( int i=0; i<5; i++ ) {
state.step(); state.step();
Thread.sleep(1000); Thread.sleep(500);
System.out.println("--- callgraph="+state.callgraph() ); System.out.println("--- callgraph="+state.callgraph() );
System.out.println("--- stack="+state.stack() ); System.out.println("--- stack="+state.stack() );
System.out.println("--- variable(1,0)="+state.variable(1,0) ); System.out.println("--- variable(1,0)="+state.variable(1,0) );
@@ -47,5 +48,10 @@ public class DebugStackStateTest extends TestCase {
// resume the vm // resume the vm
state.resume(); state.resume();
Thread.sleep(500);
System.out.println("--- callgraph="+state.callgraph() );
state.resume();
Thread.sleep(500);
System.out.println("--- callgraph="+state.callgraph() );
} }
} }