[jboss-svn-commits] JBL Code SVN: r14938 - in labs/jbossrules/trunk: drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 7 17:11:23 EDT 2007
Author: ahtik
Date: 2007-09-07 17:11:22 -0400 (Fri, 07 Sep 2007)
New Revision: 14938
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java
Log:
JBRULES-1174: fixing suspend lifecycle that is randomly causing wrong line-numbers for source lookup
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -12,7 +12,7 @@
public class MVELConsequence
implements
Consequence,
- Serializable {
+ Serializable {
private static final long serialVersionUID = 400L;
private final Serializable expr;
@@ -31,16 +31,22 @@
null,
workingMemory,
null );
- CompiledExpression compexpr = (CompiledExpression)this.expr;
+ CompiledExpression compexpr = (CompiledExpression) this.expr;
//Receive breakpoints from debugger
MVELDebugHandler.prepare();
-
- if (MVELDebugHandler.isDebugMode()) {
- System.out.println(DebugTools.decompile(compexpr));
- MVEL.executeDebugger( compexpr, null, this.factory);
+
+ if ( MVELDebugHandler.isDebugMode() ) {
+ if ( MVELDebugHandler.verbose ) {
+ System.out.println( DebugTools.decompile( compexpr ) );
+ }
+ MVEL.executeDebugger( compexpr,
+ null,
+ this.factory );
} else {
- MVEL.executeExpression( compexpr, null, this.factory);
+ MVEL.executeExpression( compexpr,
+ null,
+ this.factory );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -21,6 +21,8 @@
private static Boolean debugMode = null;
+ public static final boolean verbose = false;
+
static {
MVELRuntime.setThreadDebugger(new MVELDebugger());
}
@@ -43,22 +45,30 @@
//int oldReturn = onBreakReturn;
//onBreakReturn = Debugger.CONTINUE;
//return oldReturn;
- System.out.println("Continuing with "+(onBreakReturn==Debugger.CONTINUE?"continue":"step-over"));
+ if (verbose) {
+ System.out.println("Continuing with "+(onBreakReturn==Debugger.CONTINUE?"continue":"step-over"));
+ }
return onBreakReturn;
}
protected final static void registerBreakpoint(String sourceName, int lineNumber) {
- System.out.println("Registering breakpoint for "+sourceName+":"+lineNumber);
+ if (verbose) {
+ System.out.println("Registering breakpoint for "+sourceName+":"+lineNumber);
+ }
MVELRuntime.registerBreakpoint( sourceName, lineNumber );
}
protected final static void clearAllBreakpoints() {
- System.out.println("Clearing all breakpoints");
+ if (verbose) {
+ System.out.println("Clearing all breakpoints");
+ }
MVELRuntime.clearAllBreakpoints();
}
protected final static void removeBreakpoint(String sourceName, int lineNumber) {
- System.out.println("Removing breakpoint from "+sourceName+":"+lineNumber);
+ if (verbose) {
+ System.out.println("Removing breakpoint from "+sourceName+":"+lineNumber);
+ }
MVELRuntime.removeBreakpoint( sourceName, lineNumber );
}
@@ -68,7 +78,9 @@
}
public int onBreak(Frame frame) {
- System.out.println("onBreak call for "+frame.getSourceName()+":"+frame.getLineNumber());
+ if (verbose) {
+ System.out.println("onBreak call for "+frame.getSourceName()+":"+frame.getLineNumber());
+ }
return MVELDebugHandler.onBreak(frame);
// This call is supposed to be catched by the remote debugger
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -703,7 +703,6 @@
DroolsThread th2 = (DroolsThread) tharr[i];
ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
- //MVEL It doesn't have to be always main. find a better way for detection
if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
t = th2real;
t2 = (DroolsThread) th2;
@@ -724,7 +723,6 @@
public void wonSuspendVote(Event event,
JDIDebugTarget target) {
- // TODO Auto-generated method stub
}
@@ -757,58 +755,49 @@
* @param line
* @return
*/
- public DroolsLineBreakpoint getDroolsBreakpoint(String source,
- int line) {
-
-
- DroolsLineBreakpoint backupBreakpoint = null;
-
+ public DroolsLineBreakpoint getDroolsBreakpoint(String source) {
+
+ if ( source == null ) {
+ return null;
+ }
+
Iterator iterator = getBreakpoints().iterator();
while ( iterator.hasNext() ) {
IJavaBreakpoint element = (IJavaBreakpoint) iterator.next();
- if ( element instanceof DroolsLineBreakpoint && ((DroolsLineBreakpoint)element).getDialectName().equals( MVELDialect.ID )) {
+ if ( element instanceof DroolsLineBreakpoint && ((DroolsLineBreakpoint) element).getDialectName().equals( MVELDialect.ID ) ) {
DroolsLineBreakpoint l = (DroolsLineBreakpoint) element;
try {
- if ( l == null || source == null ) {
- return null;
- }
-
int matchLine = l.getLineNumber();
String matchSource = l.getRuleName();
- if ( matchLine == line && source.equals( matchSource ) ) {
+
+ if ( source.equals( matchSource ) || l.getFileRuleMappings().containsKey( source ) ) {
return l;
}
-
- // Prepare for a backup breakpoint
- if (source.equals( matchSource ) || l.getFileRuleMappings().containsKey( source )) {
- backupBreakpoint = l;
- }
-
+
} catch ( CoreException e ) {
logError( e );
}
}
}
- return backupBreakpoint;
+ return null;
}
private void addRemoteBreakpoint(DroolsLineBreakpoint d) {
-
+
try {
- if (!d.isEnabled()) {
+ if ( !d.isEnabled() ) {
return; // No need to install disabled breakpoints
}
} catch ( CoreException e2 ) {
logError( e2 );
return; // No need to install breakpoints that are this much broken
}
-
+
Iterator handleriter = getVM().classesByName( "org.drools.base.mvel.MVELDebugHandler" ).iterator();
Object debugHandlerClass = handleriter.next();
-
int line;
String sourceName;
@@ -839,7 +828,7 @@
for ( int i = 0; i < tharr.length; i++ ) {
IThread th2 = tharr[i];
ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
- //MVEL It doesn't have to be always main. find a better way for detection. suspend count is most likely only at one thread so a bit more error-safe
+
if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
t = th2real;
t2 = (DroolsThread) th2;
@@ -895,7 +884,7 @@
for ( int i = 0; i < tharr.length; i++ ) {
IThread th2 = tharr[i];
ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
- //MVEL It doesn't have to be always main. find a better way for detection. suspend count is most likely only at one thread so a bit more error-safe
+
if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
t = th2real;
t2 = (DroolsThread) th2;
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -40,539 +40,600 @@
public class DroolsStackFrame extends JDIStackFrame {
- private static final String CONSEQUENCE_SIGNATURE = "(Lorg/drools/spi/KnowledgeHelper";
+ private static final String CONSEQUENCE_SIGNATURE = "(Lorg/drools/spi/KnowledgeHelper";
- private DroolsThread fThread;
- private Location fLocation;
- private List fVariables;
- private boolean fRefreshVariables= true;
- private int fDepth = -2;
- private boolean initialized = true;
- private StackFrame fStackFrame;
- private ObjectReference fThisObject;
- private String fReceivingTypeName;
- private boolean fLocalsAvailable = true;
+ private DroolsThread fThread;
+ private Location fLocation;
+ private List fVariables;
+ private boolean fRefreshVariables = true;
+ private int fDepth = -2;
+ private boolean initialized = true;
+ private StackFrame fStackFrame;
+ private ObjectReference fThisObject;
+ private String fReceivingTypeName;
+ private boolean fLocalsAvailable = true;
- public DroolsStackFrame(DroolsThread thread, StackFrame frame, int depth) {
- super(thread, frame, depth);
- bind(frame, depth);
- }
-
- public boolean isExecutingRule() {
- try {
- if ("consequence".equals(getMethodName()) && getSignature().startsWith(CONSEQUENCE_SIGNATURE)) {
- return true;
- }
- } catch (DebugException exc) {
- DroolsEclipsePlugin.log(exc);
- }
- return false;
- }
-
- public RuleInfo getExecutingRuleInfo() {
- try {
- String methodName = getMethodName();
- String signature = getSignature();
- String type = getDeclaringTypeName();
- if ("consequence".equals(methodName) && signature.startsWith(CONSEQUENCE_SIGNATURE)) {
- return DroolsEclipsePlugin.getDefault().getRuleInfoByClass(type);
- }
-
- } catch (DebugException exc) {
- DroolsEclipsePlugin.log(exc);
- }
- return null;
- }
-
- public FunctionInfo getExecutingFunctionInfo() {
- try {
- return DroolsEclipsePlugin.getDefault()
- .getFunctionInfoByClass(getDeclaringTypeName());
- } catch (DebugException exc) {
- DroolsEclipsePlugin.log(exc);
- }
- return null;
- }
-
- public int getLineNumber() throws DebugException {
- synchronized (fThread) {
- RuleInfo ruleInfo = getExecutingRuleInfo();
- if (ruleInfo != null) {
+ public DroolsStackFrame(DroolsThread thread,
+ StackFrame frame,
+ int depth) {
+ super( thread,
+ frame,
+ depth );
+ bind( frame,
+ depth );
+ }
+
+ public boolean isExecutingRule() {
+ try {
+ if ( "consequence".equals( getMethodName() ) && getSignature().startsWith( CONSEQUENCE_SIGNATURE ) ) {
+ return true;
+ }
+ } catch ( DebugException exc ) {
+ DroolsEclipsePlugin.log( exc );
+ }
+ return false;
+ }
+
+ public RuleInfo getExecutingRuleInfo() {
+ try {
+ String methodName = getMethodName();
+ String signature = getSignature();
+ String type = getDeclaringTypeName();
+ if ( "consequence".equals( methodName ) && signature.startsWith( CONSEQUENCE_SIGNATURE ) ) {
+ return DroolsEclipsePlugin.getDefault().getRuleInfoByClass( type );
+ }
+
+ } catch ( DebugException exc ) {
+ DroolsEclipsePlugin.log( exc );
+ }
+ return null;
+ }
+
+ public FunctionInfo getExecutingFunctionInfo() {
+ try {
+ return DroolsEclipsePlugin.getDefault().getFunctionInfoByClass( getDeclaringTypeName() );
+ } catch ( DebugException exc ) {
+ DroolsEclipsePlugin.log( exc );
+ }
+ return null;
+ }
+
+ public int getLineNumber() throws DebugException {
+ synchronized ( fThread ) {
+ RuleInfo ruleInfo = getExecutingRuleInfo();
+ if ( ruleInfo != null ) {
return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
- }
- FunctionInfo functionInfo = getExecutingFunctionInfo();
- if (functionInfo != null) {
- return functionInfo.getDrlLineNumber() + (getInternalLineNumber() - functionInfo.getJavaLineNumber());
- }
- }
-
- return getInternalLineNumber();
- }
-
- private int getInternalLineNumber() throws DebugException {
- try {
- return fLocation.lineNumber();
- } catch (RuntimeException e) {
- if (getThread().isSuspended()) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_line_number, new String[] {e.toString()}), e);
- }
- }
- return -1;
- }
+ }
+ FunctionInfo functionInfo = getExecutingFunctionInfo();
+ if ( functionInfo != null ) {
+ return functionInfo.getDrlLineNumber() + (getInternalLineNumber() - functionInfo.getJavaLineNumber());
+ }
+ }
- public IVariable[] getVariables() throws DebugException {
- IVariable[] variables = super.getVariables();
- List result = new ArrayList((variables.length - 1)/2);
- for (int i = 0; i < variables.length; i++) {
- String name = variables[i].getName();
- if (!(name.equals("drools")) && !(name.endsWith("__Handle__"))) {
- result.add(variables[i]);
- }
- }
- return (IVariable[]) result.toArray(new IVariable[result.size()]);
- }
-
- protected List getVariables0() throws DebugException {
- synchronized (fThread) {
- if (fVariables == null) {
-
- // throw exception if native method, so variable view will update
- // with information message
- if (isNative()) {
- requestFailed(JDIDebugModelMessages.JDIStackFrame_Variable_information_unavailable_for_native_methods, null);
- }
-
- Method method= getUnderlyingMethod();
- fVariables= new ArrayList();
- // #isStatic() does not claim to throw any exceptions - so it is not try/catch coded
- if (method.isStatic()) {
- // add statics
- List allFields= null;
- ReferenceType declaringType = method.declaringType();
- try {
- allFields= declaringType.allFields();
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_fields,new String[] {e.toString()}), e);
- // execution will not reach this line, as
- // #targetRequestFailed will throw an exception
- return Collections.EMPTY_LIST;
- }
- if (allFields != null) {
- Iterator fields= allFields.iterator();
- while (fields.hasNext()) {
- Field field= (Field) fields.next();
- if (field.isStatic()) {
- fVariables.add(new JDIFieldVariable((JDIDebugTarget)getDebugTarget(), field, declaringType));
- }
- }
- Collections.sort(fVariables, new Comparator() {
- public int compare(Object a, Object b) {
- JDIFieldVariable v1= (JDIFieldVariable)a;
- JDIFieldVariable v2= (JDIFieldVariable)b;
- try {
- return v1.getName().compareToIgnoreCase(v2.getName());
- } catch (DebugException de) {
- logError(de);
- return -1;
- }
- }
- });
- }
- } else {
- // add "this"
- ObjectReference t= getUnderlyingThisObject();
- if (t != null) {
- fVariables.add(new DroolsThisVariable((JDIDebugTarget)getDebugTarget(), t));
- }
- }
- // add locals
- Iterator variables= getUnderlyingVisibleVariables().iterator();
- while (variables.hasNext()) {
- LocalVariable var= (LocalVariable) variables.next();
- fVariables.add(new DroolsLocalVariable(this, var));
- }
- } else if (fRefreshVariables) {
- updateVariables();
- }
- fRefreshVariables = false;
- return fVariables;
- }
- }
-
- protected JDIStackFrame bind(StackFrame frame, int depth) {
- if (initialized) {
- synchronized (fThread) {
- if (fDepth == -2) {
+ return getInternalLineNumber();
+ }
+
+ private int getInternalLineNumber() throws DebugException {
+ try {
+ return fLocation.lineNumber();
+ } catch ( RuntimeException e ) {
+ if ( getThread().isSuspended() ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_line_number,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+ return -1;
+ }
+
+ public IVariable[] getVariables() throws DebugException {
+ IVariable[] variables = super.getVariables();
+ List result = new ArrayList( (variables.length - 1) / 2 );
+ for ( int i = 0; i < variables.length; i++ ) {
+ String name = variables[i].getName();
+ if ( !(name.equals( "drools" )) && !(name.endsWith( "__Handle__" )) ) {
+ result.add( variables[i] );
+ }
+ }
+ return (IVariable[]) result.toArray( new IVariable[result.size()] );
+ }
+
+ protected List getVariables0() throws DebugException {
+ synchronized ( fThread ) {
+ if ( fVariables == null ) {
+
+ // throw exception if native method, so variable view will update
+ // with information message
+ if ( isNative() ) {
+ requestFailed( JDIDebugModelMessages.JDIStackFrame_Variable_information_unavailable_for_native_methods,
+ null );
+ }
+
+ Method method = getUnderlyingMethod();
+ fVariables = new ArrayList();
+ // #isStatic() does not claim to throw any exceptions - so it is not try/catch coded
+ if ( method.isStatic() ) {
+ // add statics
+ List allFields = null;
+ ReferenceType declaringType = method.declaringType();
+ try {
+ allFields = declaringType.allFields();
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_fields,
+ new String[]{e.toString()} ),
+ e );
+ // execution will not reach this line, as
+ // #targetRequestFailed will throw an exception
+ return Collections.EMPTY_LIST;
+ }
+ if ( allFields != null ) {
+ Iterator fields = allFields.iterator();
+ while ( fields.hasNext() ) {
+ Field field = (Field) fields.next();
+ if ( field.isStatic() ) {
+ fVariables.add( new JDIFieldVariable( (JDIDebugTarget) getDebugTarget(),
+ field,
+ declaringType ) );
+ }
+ }
+ Collections.sort( fVariables,
+ new Comparator() {
+ public int compare(Object a,
+ Object b) {
+ JDIFieldVariable v1 = (JDIFieldVariable) a;
+ JDIFieldVariable v2 = (JDIFieldVariable) b;
+ try {
+ return v1.getName().compareToIgnoreCase( v2.getName() );
+ } catch ( DebugException de ) {
+ logError( de );
+ return -1;
+ }
+ }
+ } );
+ }
+ } else {
+ // add "this"
+ ObjectReference t = getUnderlyingThisObject();
+ if ( t != null ) {
+ fVariables.add( new DroolsThisVariable( (JDIDebugTarget) getDebugTarget(),
+ t ) );
+ }
+ }
+ // add locals
+ Iterator variables = getUnderlyingVisibleVariables().iterator();
+ while ( variables.hasNext() ) {
+ LocalVariable var = (LocalVariable) variables.next();
+ fVariables.add( new DroolsLocalVariable( this,
+ var ) );
+ }
+ } else if ( fRefreshVariables ) {
+ updateVariables();
+ }
+ fRefreshVariables = false;
+ return fVariables;
+ }
+ }
+
+ protected JDIStackFrame bind(StackFrame frame,
+ int depth) {
+ if ( initialized ) {
+ synchronized ( fThread ) {
+ if ( fDepth == -2 ) {
// first initialization
fStackFrame = frame;
fDepth = depth;
fLocation = frame.location();
return this;
- } else if (depth == -1) {
+ } else if ( depth == -1 ) {
// mark as invalid
fDepth = -1;
fStackFrame = null;
return null;
- } else if (fDepth == depth) {
+ } else if ( fDepth == depth ) {
Location location = frame.location();
Method method = location.method();
- if (method.equals(fLocation.method())) {
+ if ( method.equals( fLocation.method() ) ) {
try {
- if (method.declaringType().defaultStratum().equals("Java") || //$NON-NLS-1$
- equals(getSourceName(location), getSourceName(fLocation))) {
+ if ( method.declaringType().defaultStratum().equals( "Java" ) || //$NON-NLS-1$
+ equals( getSourceName( location ),
+ getSourceName( fLocation ) ) ) {
// TODO: what about receiving type being the same?
fStackFrame = frame;
fLocation = location;
clearCachedData();
return this;
}
- } catch (DebugException e) {
+ } catch ( DebugException e ) {
}
}
}
- // invalidate this franme
- bind(null, -1);
+ // invalidate this franme
+ bind( null,
+ -1 );
// return a new frame
- return createNewDroolsFrame(frame, depth);
+ return createNewDroolsFrame( frame,
+ depth );
}
} else {
return null;
}
}
- protected DroolsStackFrame createNewDroolsFrame(StackFrame frame, int depth) {
- return DroolsThread.createCustomFrame( fThread, depth, frame );
+ protected DroolsStackFrame createNewDroolsFrame(StackFrame frame,
+ int depth) {
+ return DroolsThread.createCustomFrame( fThread,
+ depth,
+ frame );
}
-
- public IThread getThread() {
- return fThread;
- }
- public Method getUnderlyingMethod() {
- synchronized (fThread) {
- return fLocation.method();
- }
- }
-
- protected List getUnderlyingVisibleVariables() throws DebugException {
- synchronized (fThread) {
- List variables= Collections.EMPTY_LIST;
- try {
- variables= getUnderlyingStackFrame().visibleVariables();
- } catch (AbsentInformationException e) {
- setLocalsAvailable(false);
- } catch (NativeMethodException e) {
- setLocalsAvailable(false);
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_visible_variables_2,new String[] {e.toString()}), e);
- }
- return variables;
- }
- }
+ public IThread getThread() {
+ return fThread;
+ }
- protected ObjectReference getUnderlyingThisObject() throws DebugException {
- synchronized (fThread) {
- if ((fStackFrame == null || fThisObject == null) && !isStatic()) {
- try {
- fThisObject = getUnderlyingStackFrame().thisObject();
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_this,new String[] {e.toString()}), e);
- // execution will not reach this line, as
- // #targetRequestFailed will throw an exception
- return null;
- }
- }
- return fThisObject;
- }
- }
-
- public String getDeclaringTypeName() throws DebugException {
- synchronized (fThread) {
- try {
- if (isObsolete()) {
- return JDIDebugModelMessages.JDIStackFrame__unknown_declaring_type__1;
- }
- return JDIReferenceType.getGenericName(getUnderlyingMethod().declaringType());
- } catch (RuntimeException e) {
- if (getThread().isSuspended()) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_declaring_type, new String[] {e.toString()}), e);
- }
- return JDIDebugModelMessages.JDIStackFrame__unknown_declaring_type__1;
- }
- }
- }
-
- public String getSourceName() throws DebugException {
- synchronized (fThread) {
- return getSourceName(fLocation);
- }
- }
+ public Method getUnderlyingMethod() {
+ synchronized ( fThread ) {
+ return fLocation.method();
+ }
+ }
- public boolean isObsolete() {
- if (!JDIDebugPlugin.isJdiVersionGreaterThanOrEqual(new int[] {1,4}) || !((JDIDebugTarget)getDebugTarget()).hasHCROccurred()) {
- // If no hot code replace has occurred, this frame
- // cannot be obsolete.
- return false;
- }
- // if this frame's thread is not suspended, the obsolete status cannot
- // change until it suspends again
- synchronized (fThread) {
- if (getThread().isSuspended()) {
- return getUnderlyingMethod().isObsolete();
- }
- return false;
- }
- }
-
- protected boolean exists() {
- synchronized (fThread) {
- return fDepth != -1;
- }
- }
-
- protected StackFrame getUnderlyingStackFrame() throws DebugException {
- synchronized (fThread) {
- if (fStackFrame == null) {
- if (fDepth == -1) {
- throw new DebugException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IJavaStackFrame.ERR_INVALID_STACK_FRAME, JDIDebugModelMessages.JDIStackFrame_25, null));
- }
- if (fThread.isSuspended()) {
- // re-index stack frames - See Bug 47198
- fThread.computeStackFrames();
- if (fDepth == -1) {
- // If depth is -1, then this is an invalid frame
- throw new DebugException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IJavaStackFrame.ERR_INVALID_STACK_FRAME, JDIDebugModelMessages.JDIStackFrame_25, null));
- }
- } else {
- throw new DebugException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IJavaThread.ERR_THREAD_NOT_SUSPENDED, JDIDebugModelMessages.JDIStackFrame_25, null));
- }
- }
- return fStackFrame;
- }
- }
+ protected List getUnderlyingVisibleVariables() throws DebugException {
+ synchronized ( fThread ) {
+ List variables = Collections.EMPTY_LIST;
+ try {
+ variables = getUnderlyingStackFrame().visibleVariables();
+ } catch ( AbsentInformationException e ) {
+ setLocalsAvailable( false );
+ } catch ( NativeMethodException e ) {
+ setLocalsAvailable( false );
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_visible_variables_2,
+ new String[]{e.toString()} ),
+ e );
+ }
+ return variables;
+ }
+ }
- protected void setUnderlyingStackFrame(StackFrame frame) {
- synchronized (fThread) {
- fStackFrame = frame;
- if (frame == null) {
- fRefreshVariables = true;
- }
- }
- }
-
- protected void setThread(JDIThread thread) {
- fThread = (DroolsThread) thread;
- }
+ protected ObjectReference getUnderlyingThisObject() throws DebugException {
+ synchronized ( fThread ) {
+ if ( (fStackFrame == null || fThisObject == null) && !isStatic() ) {
+ try {
+ fThisObject = getUnderlyingStackFrame().thisObject();
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_this,
+ new String[]{e.toString()} ),
+ e );
+ // execution will not reach this line, as
+ // #targetRequestFailed will throw an exception
+ return null;
+ }
+ }
+ return fThisObject;
+ }
+ }
- public String getSourcePath(String stratum) throws DebugException {
- synchronized (fThread) {
- try {
- return fLocation.sourcePath(stratum);
- } catch (AbsentInformationException e) {
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_path, new String[] {e.toString()}), e);
- }
- }
- return null;
- }
+ public String getDeclaringTypeName() throws DebugException {
+ synchronized ( fThread ) {
+ try {
+ if ( isObsolete() ) {
+ return JDIDebugModelMessages.JDIStackFrame__unknown_declaring_type__1;
+ }
+ return JDIReferenceType.getGenericName( getUnderlyingMethod().declaringType() );
+ } catch ( RuntimeException e ) {
+ if ( getThread().isSuspended() ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_declaring_type,
+ new String[]{e.toString()} ),
+ e );
+ }
+ return JDIDebugModelMessages.JDIStackFrame__unknown_declaring_type__1;
+ }
+ }
+ }
- public String getSourcePath() throws DebugException {
- synchronized (fThread) {
- try {
- return fLocation.sourcePath();
- } catch (AbsentInformationException e) {
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_path, new String[] {e.toString()}), e);
- }
- }
- return null;
- }
+ public String getSourceName() throws DebugException {
+ synchronized ( fThread ) {
+ return getSourceName( fLocation );
+ }
+ }
- public int getLineNumber(String stratum) throws DebugException {
- synchronized (fThread) {
- try {
- return fLocation.lineNumber(stratum);
- } catch (RuntimeException e) {
- if (getThread().isSuspended()) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_line_number, new String[] {e.toString()}), e);
- }
- }
- }
- return -1;
- }
+ public boolean isObsolete() {
+ if ( !JDIDebugPlugin.isJdiVersionGreaterThanOrEqual( new int[]{1, 4} ) || !((JDIDebugTarget) getDebugTarget()).hasHCROccurred() ) {
+ // If no hot code replace has occurred, this frame
+ // cannot be obsolete.
+ return false;
+ }
+ // if this frame's thread is not suspended, the obsolete status cannot
+ // change until it suspends again
+ synchronized ( fThread ) {
+ if ( getThread().isSuspended() ) {
+ return getUnderlyingMethod().isObsolete();
+ }
+ return false;
+ }
+ }
- public String getSourceName(String stratum) throws DebugException {
- synchronized (fThread) {
- try {
- return fLocation.sourceName(stratum);
- } catch (AbsentInformationException e) {
- } catch (NativeMethodException e) {
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_name, new String[] {e.toString()}), e);
- }
- }
- return null;
- }
+ protected boolean exists() {
+ synchronized ( fThread ) {
+ return fDepth != -1;
+ }
+ }
- protected void updateVariables() throws DebugException {
- if (fVariables == null) {
- return;
- }
+ protected StackFrame getUnderlyingStackFrame() throws DebugException {
+ synchronized ( fThread ) {
+ if ( fStackFrame == null ) {
+ if ( fDepth == -1 ) {
+ throw new DebugException( new Status( IStatus.ERROR,
+ JDIDebugPlugin.getUniqueIdentifier(),
+ IJavaStackFrame.ERR_INVALID_STACK_FRAME,
+ JDIDebugModelMessages.JDIStackFrame_25,
+ null ) );
+ }
+ if ( fThread.isSuspended() ) {
+ // re-index stack frames - See Bug 47198
+ fThread.computeStackFrames();
+ if ( fDepth == -1 ) {
+ // If depth is -1, then this is an invalid frame
+ throw new DebugException( new Status( IStatus.ERROR,
+ JDIDebugPlugin.getUniqueIdentifier(),
+ IJavaStackFrame.ERR_INVALID_STACK_FRAME,
+ JDIDebugModelMessages.JDIStackFrame_25,
+ null ) );
+ }
+ } else {
+ throw new DebugException( new Status( IStatus.ERROR,
+ JDIDebugPlugin.getUniqueIdentifier(),
+ IJavaThread.ERR_THREAD_NOT_SUSPENDED,
+ JDIDebugModelMessages.JDIStackFrame_25,
+ null ) );
+ }
+ }
+ return fStackFrame;
+ }
+ }
- Method method= getUnderlyingMethod();
- int index= 0;
- if (!method.isStatic()) {
- // update "this"
- ObjectReference thisObject;
- try {
- thisObject= getUnderlyingThisObject();
- } catch (DebugException exception) {
- if (!getThread().isSuspended()) {
- thisObject= null;
- } else {
- throw exception;
- }
- }
- DroolsThisVariable oldThisObject= null;
- if (!fVariables.isEmpty() && fVariables.get(0) instanceof DroolsThisVariable) {
- oldThisObject= (DroolsThisVariable) fVariables.get(0);
- }
- if (thisObject == null && oldThisObject != null) {
- // removal of 'this'
- fVariables.remove(0);
- index= 0;
- } else {
- if (oldThisObject == null && thisObject != null) {
- // creation of 'this'
- oldThisObject= new DroolsThisVariable((JDIDebugTarget)getDebugTarget(),thisObject);
- fVariables.add(0, oldThisObject);
- index= 1;
- } else {
- if (oldThisObject != null) {
- // 'this' still exists, replace with new 'this' if a different receiver
- if (!oldThisObject.retrieveValue().equals(thisObject)) {
- fVariables.remove(0);
- fVariables.add(0, new DroolsThisVariable((JDIDebugTarget)getDebugTarget(),thisObject));
- }
- index= 1;
- }
- }
- }
- }
+ protected void setUnderlyingStackFrame(StackFrame frame) {
+ synchronized ( fThread ) {
+ fStackFrame = frame;
+ if ( frame == null ) {
+ fRefreshVariables = true;
+ }
+ }
+ }
- List locals= null;
- try {
- locals= getUnderlyingStackFrame().visibleVariables();
- } catch (AbsentInformationException e) {
- locals= Collections.EMPTY_LIST;
- } catch (NativeMethodException e) {
- locals= Collections.EMPTY_LIST;
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_visible_variables,new String[] {e.toString()}), e);
- // execution will not reach this line, as
- // #targetRequestFailed will throw an exception
- return;
- }
- int localIndex= -1;
- while (index < fVariables.size()) {
- Object var= fVariables.get(index);
- if (var instanceof JDILocalVariable) {
- DroolsLocalVariable local= (DroolsLocalVariable) fVariables.get(index);
- localIndex= locals.indexOf(local.getLocal());
- if (localIndex >= 0) {
- // update variable with new underling JDI LocalVariable
- local.setLocal((LocalVariable) locals.get(localIndex));
- locals.remove(localIndex);
- index++;
- } else {
- // remove variable
- fVariables.remove(index);
- }
- } else {
- //field variable of a static frame
- index++;
- }
- }
+ protected void setThread(JDIThread thread) {
+ fThread = (DroolsThread) thread;
+ }
- // add any new locals
- Iterator newOnes= locals.iterator();
- while (newOnes.hasNext()) {
- DroolsLocalVariable local= new DroolsLocalVariable(this, (LocalVariable) newOnes.next());
- fVariables.add(local);
- }
- }
-
- protected void setVariables(List variables) {
- fVariables = variables;
- }
-
- public String getReceivingTypeName() throws DebugException {
- if (fStackFrame == null || fReceivingTypeName == null) {
- try {
- if (isObsolete()) {
- fReceivingTypeName=JDIDebugModelMessages.JDIStackFrame__unknown_receiving_type__2;
- } else {
- ObjectReference thisObject = getUnderlyingThisObject();
- if (thisObject == null) {
- fReceivingTypeName = getDeclaringTypeName();
- } else {
- fReceivingTypeName = JDIReferenceType.getGenericName(thisObject.referenceType());
- }
- }
- } catch (RuntimeException e) {
- if (getThread().isSuspended()) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_receiving_type, new String[] {e.toString()}), e);
- }
- return JDIDebugModelMessages.JDIStackFrame__unknown_receiving_type__2;
- }
- }
- return fReceivingTypeName;
- }
+ public String getSourcePath(String stratum) throws DebugException {
+ synchronized ( fThread ) {
+ try {
+ return fLocation.sourcePath( stratum );
+ } catch ( AbsentInformationException e ) {
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_path,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+ return null;
+ }
- private String getSourceName(Location location) throws DebugException {
- try {
- return location.sourceName();
- } catch (AbsentInformationException e) {
- return null;
- } catch (NativeMethodException e) {
- return null;
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_name, new String[] {e.toString()}), e);
- }
- return null;
- }
-
- private boolean equals(Object o1, Object o2) {
- if (o1 == null) {
- return o2 == null;
- } else {
- return o1.equals(o2);
- }
- }
-
- private void clearCachedData() {
- fThisObject= null;
- fReceivingTypeName= null;
- }
-
- private void setLocalsAvailable(boolean available) {
- if (available != fLocalsAvailable) {
- fLocalsAvailable = available;
- fireChangeEvent(DebugEvent.STATE);
- }
- }
+ public String getSourcePath() throws DebugException {
+ synchronized ( fThread ) {
+ try {
+ return fLocation.sourcePath();
+ } catch ( AbsentInformationException e ) {
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_path,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+ return null;
+ }
- public boolean wereLocalsAvailable() {
- return fLocalsAvailable;
- }
-
- public IJavaVariable[] getLocalVariables() throws DebugException {
- List list = getUnderlyingVisibleVariables();
- IJavaVariable[] locals = new IJavaVariable[list.size()];
- for (int i = 0; i < list.size(); i++) {
- locals[i] = new DroolsLocalVariable(this, (LocalVariable)list.get(i));
- }
- return locals;
- }
+ public int getLineNumber(String stratum) throws DebugException {
+ synchronized ( fThread ) {
+ try {
+ return fLocation.lineNumber( stratum );
+ } catch ( RuntimeException e ) {
+ if ( getThread().isSuspended() ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_line_number,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+ }
+ return -1;
+ }
+ public String getSourceName(String stratum) throws DebugException {
+ synchronized ( fThread ) {
+ try {
+ return fLocation.sourceName( stratum );
+ } catch ( AbsentInformationException e ) {
+ } catch ( NativeMethodException e ) {
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_name,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+ return null;
+ }
+
+ protected void updateVariables() throws DebugException {
+ if ( fVariables == null ) {
+ return;
+ }
+
+ Method method = getUnderlyingMethod();
+ int index = 0;
+ if ( !method.isStatic() ) {
+ // update "this"
+ ObjectReference thisObject;
+ try {
+ thisObject = getUnderlyingThisObject();
+ } catch ( DebugException exception ) {
+ if ( !getThread().isSuspended() ) {
+ thisObject = null;
+ } else {
+ throw exception;
+ }
+ }
+ DroolsThisVariable oldThisObject = null;
+ if ( !fVariables.isEmpty() && fVariables.get( 0 ) instanceof DroolsThisVariable ) {
+ oldThisObject = (DroolsThisVariable) fVariables.get( 0 );
+ }
+ if ( thisObject == null && oldThisObject != null ) {
+ // removal of 'this'
+ fVariables.remove( 0 );
+ index = 0;
+ } else {
+ if ( oldThisObject == null && thisObject != null ) {
+ // creation of 'this'
+ oldThisObject = new DroolsThisVariable( (JDIDebugTarget) getDebugTarget(),
+ thisObject );
+ fVariables.add( 0,
+ oldThisObject );
+ index = 1;
+ } else {
+ if ( oldThisObject != null ) {
+ // 'this' still exists, replace with new 'this' if a different receiver
+ if ( !oldThisObject.retrieveValue().equals( thisObject ) ) {
+ fVariables.remove( 0 );
+ fVariables.add( 0,
+ new DroolsThisVariable( (JDIDebugTarget) getDebugTarget(),
+ thisObject ) );
+ }
+ index = 1;
+ }
+ }
+ }
+ }
+
+ List locals = null;
+ try {
+ locals = getUnderlyingStackFrame().visibleVariables();
+ } catch ( AbsentInformationException e ) {
+ locals = Collections.EMPTY_LIST;
+ } catch ( NativeMethodException e ) {
+ locals = Collections.EMPTY_LIST;
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_visible_variables,
+ new String[]{e.toString()} ),
+ e );
+ // execution will not reach this line, as
+ // #targetRequestFailed will throw an exception
+ return;
+ }
+ int localIndex = -1;
+ while ( index < fVariables.size() ) {
+ Object var = fVariables.get( index );
+ if ( var instanceof JDILocalVariable ) {
+ DroolsLocalVariable local = (DroolsLocalVariable) fVariables.get( index );
+ localIndex = locals.indexOf( local.getLocal() );
+ if ( localIndex >= 0 ) {
+ // update variable with new underling JDI LocalVariable
+ local.setLocal( (LocalVariable) locals.get( localIndex ) );
+ locals.remove( localIndex );
+ index++;
+ } else {
+ // remove variable
+ fVariables.remove( index );
+ }
+ } else {
+ //field variable of a static frame
+ index++;
+ }
+ }
+
+ // add any new locals
+ Iterator newOnes = locals.iterator();
+ while ( newOnes.hasNext() ) {
+ DroolsLocalVariable local = new DroolsLocalVariable( this,
+ (LocalVariable) newOnes.next() );
+ fVariables.add( local );
+ }
+ }
+
+ protected void setVariables(List variables) {
+ fVariables = variables;
+ }
+
+ public String getReceivingTypeName() throws DebugException {
+ if ( fStackFrame == null || fReceivingTypeName == null ) {
+ try {
+ if ( isObsolete() ) {
+ fReceivingTypeName = JDIDebugModelMessages.JDIStackFrame__unknown_receiving_type__2;
+ } else {
+ ObjectReference thisObject = getUnderlyingThisObject();
+ if ( thisObject == null ) {
+ fReceivingTypeName = getDeclaringTypeName();
+ } else {
+ fReceivingTypeName = JDIReferenceType.getGenericName( thisObject.referenceType() );
+ }
+ }
+ } catch ( RuntimeException e ) {
+ if ( getThread().isSuspended() ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_receiving_type,
+ new String[]{e.toString()} ),
+ e );
+ }
+ return JDIDebugModelMessages.JDIStackFrame__unknown_receiving_type__2;
+ }
+ }
+ return fReceivingTypeName;
+ }
+
+ private String getSourceName(Location location) throws DebugException {
+ try {
+ return location.sourceName();
+ } catch ( AbsentInformationException e ) {
+ return null;
+ } catch ( NativeMethodException e ) {
+ return null;
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIStackFrame_exception_retrieving_source_name,
+ new String[]{e.toString()} ),
+ e );
+ }
+ return null;
+ }
+
+ private boolean equals(Object o1,
+ Object o2) {
+ if ( o1 == null ) {
+ return o2 == null;
+ } else {
+ return o1.equals( o2 );
+ }
+ }
+
+ protected void clearCachedData() {
+ fThisObject = null;
+ fReceivingTypeName = null;
+ }
+
+ private void setLocalsAvailable(boolean available) {
+ if ( available != fLocalsAvailable ) {
+ fLocalsAvailable = available;
+ fireChangeEvent( DebugEvent.STATE );
+ }
+ }
+
+ public boolean wereLocalsAvailable() {
+ return fLocalsAvailable;
+ }
+
+ public IJavaVariable[] getLocalVariables() throws DebugException {
+ List list = getUnderlyingVisibleVariables();
+ IJavaVariable[] locals = new IJavaVariable[list.size()];
+ for ( int i = 0; i < list.size(); i++ ) {
+ locals[i] = new DroolsLocalVariable( this,
+ (LocalVariable) list.get( i ) );
+ }
+ return locals;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -246,25 +246,28 @@
}
public synchronized void stepOver() throws DebugException {
-
+
// Detection for active stackframe
- if (!(getTopStackFrame() instanceof MVELStackFrame)) {
+ if ( !(getTopStackFrame() instanceof MVELStackFrame) ) {
super.stepOver();
return;
}
//MVEL step over
- if ( !canStepOver() ) {
+ MVELStackFrame mvelStack = (MVELStackFrame) getTopStackFrame();
+
+ if ( !canStepOver() || !mvelStack.canStepOver() ) {
return;
}
-
+
if ( !setRemoteOnBreakReturn( Debugger.STEP ) ) {
return;
}
- setRunning( true );
preserveStackFrames();
+ setRunning( true );
+
try {
getUnderlyingThread().resume();
} catch ( RuntimeException e ) {
@@ -314,4 +317,9 @@
setRemoteOnBreakReturn( Debugger.CONTINUE );
super.resume();
}
+
+ public void setInvokingMethod(boolean invoking) {
+ super.setInvokingMethod( invoking );
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -10,21 +10,20 @@
import org.drools.eclipse.DRLInfo.RuleInfo;
import org.drools.eclipse.debug.DebugUtil;
import org.drools.eclipse.debug.VariableWrapper;
-import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
-import org.eclipse.jdi.internal.StackFrameImpl;
+import org.eclipse.jdi.internal.ObjectReferenceImpl;
import org.eclipse.jdt.debug.core.IJavaClassObject;
import org.eclipse.jdt.debug.core.IJavaFieldVariable;
import org.eclipse.jdt.debug.core.IJavaObject;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
import org.eclipse.jdt.debug.core.IJavaValue;
-import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
-import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
+import org.eclipse.jdt.internal.debug.core.model.JDIStackFrame;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.ArrayReference;
@@ -53,80 +52,87 @@
*/
public class MVELStackFrame extends DroolsStackFrame {
+ private int cacheLineNumber = -1;
+ private int cacheBreakpointLineNumber = -1;
+ private String cacheMVELName = null;
+ private IVariable[] cacheVariables = null;
+
+ private boolean evaluating = false;
+
/**
* Dummy type with changed stratum to force debugger's LaunchView to show proper stackframe name
*/
- private static final IJavaReferenceType REF_TYPE = new IJavaReferenceType() {
+ private static final IJavaReferenceType REF_TYPE = new IJavaReferenceType() {
- public String[] getAllFieldNames() throws DebugException {
- return null;
- }
+ public String[] getAllFieldNames() throws DebugException {
+ return null;
+ }
- public String[] getAvailableStrata() throws DebugException {
- return null;
- }
+ public String[] getAvailableStrata() throws DebugException {
+ return null;
+ }
- public IJavaObject getClassLoaderObject() throws DebugException {
- return null;
- }
+ public IJavaObject getClassLoaderObject() throws DebugException {
+ return null;
+ }
- public IJavaClassObject getClassObject() throws DebugException {
- return null;
- }
+ public IJavaClassObject getClassObject() throws DebugException {
+ return null;
+ }
- public String[] getDeclaredFieldNames() throws DebugException {
- return null;
- }
+ public String[] getDeclaredFieldNames() throws DebugException {
+ return null;
+ }
- public String getDefaultStratum() throws DebugException {
- return "MVEL";
- }
+ public String getDefaultStratum() throws DebugException {
+ return "MVEL";
+ }
- public IJavaFieldVariable getField(String name) throws DebugException {
- return null;
- }
+ public IJavaFieldVariable getField(String name) throws DebugException {
+ return null;
+ }
- public String getGenericSignature() throws DebugException {
- return null;
- }
+ public String getGenericSignature() throws DebugException {
+ return null;
+ }
- public String getSourceName() throws DebugException {
- return null;
- }
+ public String getSourceName() throws DebugException {
+ return null;
+ }
- public String[] getSourceNames(String stratum) throws DebugException {
- return null;
- }
+ public String[] getSourceNames(String stratum) throws DebugException {
+ return null;
+ }
- public String[] getSourcePaths(String stratum) throws DebugException {
- return null;
- }
+ public String[] getSourcePaths(String stratum) throws DebugException {
+ return null;
+ }
- public String getName() throws DebugException {
- return null;
- }
+ public String getName() throws DebugException {
+ return null;
+ }
- public String getSignature() throws DebugException {
- return null;
- }
+ public String getSignature() throws DebugException {
+ return null;
+ }
- public IDebugTarget getDebugTarget() {
- return null;
- }
+ public IDebugTarget getDebugTarget() {
+ return null;
+ }
- public ILaunch getLaunch() {
- return null;
- }
+ public ILaunch getLaunch() {
+ return null;
+ }
- public String getModelIdentifier() {
- return null;
- }
+ public String getModelIdentifier() {
+ return null;
+ }
- public Object getAdapter(Class adapter) {
- return null;
- }
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
- }; ;
+ };
public MVELStackFrame(DroolsThread thread,
StackFrame frame,
@@ -135,84 +141,96 @@
frame,
depth );
- try {
- Iterator i = thread.getUnderlyingThread().frames().iterator();
- while ( i.hasNext() ) {
- StackFrameImpl o = (StackFrameImpl) i.next();
- }
- } catch ( IncompatibleThreadStateException e ) {
- DroolsEclipsePlugin.log( e );
- }
-
}
public IVariable[] getVariables() throws DebugException {
- List result = new ArrayList( 0 );
+ if ( !isSuspended() ) {
+ return null;
+ }
- Method method = getUnderlyingMethod(); // onBreak
- ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
+ if ( cacheVariables != null ) {
+ return cacheVariables;
+ }
+ evaluating = true;
try {
+ List result = new ArrayList( 0 );
- Object var = method.variables().get( 0 );
- LocalVariable v2 = (LocalVariable) var;
- DroolsLocalVariable frameLocal = new DroolsLocalVariable( this,
- v2 );
+ Method method = getUnderlyingMethod(); // onBreak
+ ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
- IValue knownVars = DebugUtil.getValueByExpression( "return getFactory().getKnownVariables().toArray(new String[0]);",
+ try {
+
+ Object var = method.variables().get( 0 );
+ LocalVariable v2 = (LocalVariable) var;
+ DroolsLocalVariable frameLocal = new DroolsLocalVariable( this,
+ v2 );
+
+ IValue knownVars = DebugUtil.getValueByExpression( "return getFactory().getKnownVariables().toArray(new String[0]);",
+ frameLocal.getValue() );
+
+ IValue factory = DebugUtil.getValueByExpression( "return getFactory();",
+ frameLocal.getValue() );
+
+ IValue vars2 = DebugUtil.getValueByExpression( "return getFactory().getKnownVariables();",
frameLocal.getValue() );
- IValue factory = DebugUtil.getValueByExpression( "return getFactory();",
- frameLocal.getValue() );
+ JDIObjectValue vvv = (JDIObjectValue) knownVars;
- JDIObjectValue vvv = (JDIObjectValue) knownVars;
+ if ( vvv != null && ((ArrayReference) vvv.getUnderlyingObject()).length() > 0 ) {
+ ArrayReference arr = (ArrayReference) vvv.getUnderlyingObject();
- if ( vvv != null ) {
- ArrayReference arr = (ArrayReference) vvv.getUnderlyingObject();
- Iterator varIter = arr.getValues().iterator();
+ Iterator varIter = arr.getValues().iterator();
- while ( varIter.hasNext() ) {
- final String varName = ((StringReference) varIter.next()).value();
- IJavaValue val = (IJavaValue) DebugUtil.getValueByExpression( "return getVariableResolver(\"" + varName + "\").getValue();",
- factory );
- if ( val != null ) {
- final ObjectReference valRef = ((JDIObjectValue) val).getUnderlyingObject();
- VariableWrapper local = new VariableWrapper( varName,
- val );
+ while ( varIter.hasNext() ) {
+ final String varName = ((StringReference) varIter.next()).value();
- local.setPublic( true );
- result.add( local );
- } else {
- DroolsEclipsePlugin.log( new Exception( "Unable to get value for variable named '" + varName + "'" ) );
+ IJavaValue val = (IJavaValue) DebugUtil.getValueByExpression( "return getVariableResolver(\"" + varName + "\").getValue();",
+ factory );
+ if ( val != null ) {
+ final ObjectReference valRef = ((JDIObjectValue) val).getUnderlyingObject();
+ VariableWrapper local = new VariableWrapper( varName,
+ val );
+
+ local.setPublic( true );
+ result.add( local );
+ } else {
+ DroolsEclipsePlugin.log( new Exception( "Unable to get value for variable named '" + varName + "' suspend=" + isSuspended() ) );
+ }
}
+
}
+ IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
+ cacheVariables = vararr;
+ return vararr;
+
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
}
IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
- return vararr;
- } catch ( Throwable t ) {
- DroolsEclipsePlugin.log( t );
- }
+ Arrays.sort( vararr,
+ new Comparator() {
- IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
-
- Arrays.sort( vararr,
- new Comparator() {
-
- public int compare(Object var1,
- Object var2) {
- try {
- return ((IVariable) var1).getName().compareTo( ((IVariable) var2).getName() );
- } catch ( DebugException e ) {
- return 0;
+ public int compare(Object var1,
+ Object var2) {
+ try {
+ return ((IVariable) var1).getName().compareTo( ((IVariable) var2).getName() );
+ } catch ( DebugException e ) {
+ return 0;
+ }
}
- }
- } );
- return vararr;
+ } );
+ cacheVariables = vararr;
+ return vararr;
+ } finally {
+ evaluating = false;
+ evalEnd();
+ }
}
private boolean internalHasNext(Value iter) throws InvalidTypeException,
@@ -278,38 +296,46 @@
public int getLineNumber() throws DebugException {
- DroolsDebugTarget t = (DroolsDebugTarget) getDebugTarget();
+ if ( cacheLineNumber != -1 ) {
+ return cacheLineNumber;
+ }
- int lineNr = getBreakpointLineNumber();
- String sourceName = getMVELName();
-
- DroolsLineBreakpoint bpoint = (DroolsLineBreakpoint) t.getDroolsBreakpoint( sourceName,
- lineNr );
-
- if ( bpoint == null ) {
+ if ( !isSuspended() ) {
return -1;
}
- int line;
-
+ evaluating = true;
try {
- line = Integer.parseInt(bpoint.getFileRuleMappings().get( sourceName ).toString());
- } catch (Throwable t2) {
- DroolsEclipsePlugin.log( t2 );
- return -1;
- }
+ DroolsDebugTarget t = (DroolsDebugTarget) getDebugTarget();
- int fragmentLine = getBreakpointLineNumber(); // 4->5 for step over
+ //int lineNr = getBreakpointLineNumber();
+ String sourceName = getMVELName();
-
-/* int delta = 0;
- try {
- delta = fragmentLine - bpoint.getLineNumber();
- } catch ( CoreException e ) {
- DroolsEclipsePlugin.log( e );
+ DroolsLineBreakpoint bpoint = (DroolsLineBreakpoint) t.getDroolsBreakpoint( sourceName );
+
+ if ( bpoint == null ) {
+ return -1;
+ }
+
+ int line;
+
+ try {
+ line = Integer.parseInt( bpoint.getFileRuleMappings().get( sourceName ).toString() );
+ } catch ( Throwable t2 ) {
+ DroolsEclipsePlugin.log( t2 );
+ return -1;
+ }
+
+ int fragmentLine = getBreakpointLineNumber(); // 4->5 for step over
+
+ int res = line + fragmentLine;
+
+ cacheLineNumber = res;
+ return res;
+ } finally {
+ evaluating = false;
+ evalEnd();
}
-*/ int res = line + fragmentLine;
- return res;
}
public RuleInfo getExecutingRuleInfo() {
@@ -325,32 +351,71 @@
}
public int getBreakpointLineNumber() {
+
+ if ( cacheBreakpointLineNumber != -1 ) {
+ return cacheBreakpointLineNumber;
+ }
+
+ if ( !isSuspended() ) {
+ return -1;
+ }
+
+ evaluating = true;
try {
- Object o = getRemoteVar( "lineNumber" );
- if ( o == null ) {
- return -1;
+ try {
+ Object o = getRemoteVar( "lineNumber" );
+ if ( o == null ) {
+ return -1;
+ }
+ IntegerValue val = (IntegerValue) o;
+ int realval = val.value();
+ cacheBreakpointLineNumber = realval;
+ return realval;
+ } catch ( Throwable e ) {
+ DroolsEclipsePlugin.log( e );
}
- IntegerValue val = (IntegerValue) o;
- return val.value();
- } catch ( Throwable e ) {
- DroolsEclipsePlugin.log( e );
+ return -1;
+ } finally {
+ evaluating = false;
+ evalEnd();
}
- return -1;
}
public String getMVELName() {
+
+ if ( cacheMVELName != null ) {
+ return cacheMVELName;
+ }
+
+ if ( !isSuspended() ) {
+ return null;
+ }
+
+ evaluating = true;
try {
- Object rem = getRemoteVar( "sourceName" );
- if ( rem == null ) {
- return null;
+ try {
+ Object rem = getRemoteVar( "sourceName" );
+ if ( rem == null ) {
+ return null;
+ }
+ StringReference res = (StringReference) rem;
+ String realres = res.value();
+ cacheMVELName = realres;
+ return realres;
+ } catch ( Throwable e ) {
+ DroolsEclipsePlugin.log( e );
}
- StringReference res = (StringReference) rem;
- return res.value();
- } catch ( Throwable e ) {
- DroolsEclipsePlugin.log( e );
+
+ return "Unavailable";
+ } finally {
+ evaluating = false;
+ evalEnd();
}
+ }
- return "Unavailable";
+ private void evalEnd() {
+ fireChangeEvent( DebugEvent.STATE );
+ //fireChangeEvent( DebugEvent.CONTENT );
}
private Object getRemoteVar(String methodName) throws AbsentInformationException,
@@ -362,27 +427,31 @@
//frame arg
Method method = getUnderlyingMethod(); // onBreak
- ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
+ //ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
LocalVariable var = (LocalVariable) method.variables().get( 0 );//frame
- JDILocalVariable jdivar = new JDILocalVariable( this,
- (LocalVariable) var );
-
ClassType frameType = (ClassType) var.type();
- IValue value = jdivar.getValue();
- if ( value instanceof JDINullValue ) {
- return null;
- }
- ObjectReference o = (ObjectReference) ((JDIObjectValue) value).getUnderlyingObject();
+ StackFrame frame = getUnderlyingStackFrame();
+ Value value = frame.getValue( var );
+ //getThread().getTopStackFrame().get
+ //IValue value = jdivar.getValue();
+ ObjectReferenceImpl o = (ObjectReferenceImpl) value;
+
+ /* if ( value instanceof JDINullValue ) {
+ return null;
+ }
+ */
+
+ //ObjectReference o = (ObjectReference) ((JDIObjectValue) value).getUnderlyingObject();
if ( o == null ) {
return null;
}
+
Field field = frameType.fieldByName( methodName );
Value val = o.getValue( field );
-
return val;
}
@@ -395,7 +464,7 @@
}
public boolean canStepOver() {
- return true;
+ return exists() && !isObsolete() && !evaluating;
}
public boolean canDropToFrame() {
@@ -417,5 +486,41 @@
public String getSourceName() throws DebugException {
return getMVELName();
}
-
+
+ protected JDIStackFrame bind(StackFrame frame,
+ int depth) {
+ return super.bind( frame,
+ depth );
+ }
+
+ protected void clearCachedData() {
+ super.clearCachedData();
+ clearFrameCache();
+ if ( !isSuspended() ) {
+ initMVELinfo();
+ }
+ }
+
+ private void initMVELinfo() {
+ try {
+ getLineNumber();
+ } catch ( DebugException e ) {
+ // no luck this time. will be initialized later
+ }
+ getBreakpointLineNumber();
+ getMVELName();
+ try {
+ getVariables();
+ } catch ( DebugException e1 ) {
+ // no luck this time. will be initialized later
+ }
+ }
+
+ private void clearFrameCache() {
+ cacheLineNumber = -1;
+ cacheBreakpointLineNumber = -1;
+ cacheMVELName = null;
+ cacheVariables = null;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java 2007-09-07 17:16:48 UTC (rev 14937)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java 2007-09-07 21:11:22 UTC (rev 14938)
@@ -9,49 +9,49 @@
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant;
-class MVELSourceLookupParticipant extends JavaSourceLookupParticipant{
- public void dispose() {
- //do nothing
- }
+class MVELSourceLookupParticipant extends JavaSourceLookupParticipant {
+ public void dispose() {
+ //do nothing
+ }
- public Object[] findSourceElements(Object object) throws CoreException {
- if (object instanceof MVELStackFrame) {
- MVELStackFrame frame = (MVELStackFrame) object;
+ public Object[] findSourceElements(Object object) throws CoreException {
+ if ( object instanceof MVELStackFrame ) {
+ MVELStackFrame frame = (MVELStackFrame) object;
- int lineNumber = frame.getBreakpointLineNumber();
+ //int lineNumber = frame.getBreakpointLineNumber();
String mvelName = frame.getMVELName();
-
- IDebugTarget target = frame.getDebugTarget();
- if (target instanceof DroolsDebugTarget) {
- DroolsDebugTarget droolsTarget = (DroolsDebugTarget)target;
- Object bpoint = droolsTarget.getDroolsBreakpoint(mvelName, lineNumber);
- return new Object[] {bpoint};
- }
- }
- return null;
- }
- public String getSourceName(Object object) throws CoreException {
- if (object instanceof MVELStackFrame) {
- MVELStackFrame frame = (MVELStackFrame) object;
- RuleInfo ruleInfo = frame.getExecutingRuleInfo();
- if (ruleInfo != null) {
+ IDebugTarget target = frame.getDebugTarget();
+ if ( target instanceof DroolsDebugTarget ) {
+ DroolsDebugTarget droolsTarget = (DroolsDebugTarget) target;
+ Object bpoint = droolsTarget.getDroolsBreakpoint( mvelName );
+ return new Object[]{bpoint};
+ }
+ }
+ return null;
+ }
+
+ public String getSourceName(Object object) throws CoreException {
+ if ( object instanceof MVELStackFrame ) {
+ MVELStackFrame frame = (MVELStackFrame) object;
+ RuleInfo ruleInfo = frame.getExecutingRuleInfo();
+ if ( ruleInfo != null ) {
String sourcePath = ruleInfo.getSourcePathName();
- return sourcePath;
- }
- FunctionInfo functionInfo = frame.getExecutingFunctionInfo();
- if (functionInfo != null) {
- return functionInfo.getSourcePathName();
- }
- }
- return super.getSourceName(object);
- }
+ return sourcePath;
+ }
+ FunctionInfo functionInfo = frame.getExecutingFunctionInfo();
+ if ( functionInfo != null ) {
+ return functionInfo.getSourcePathName();
+ }
+ }
+ return super.getSourceName( object );
+ }
- public void init(ISourceLookupDirector director) {
- //do nothing
- }
+ public void init(ISourceLookupDirector director) {
+ //do nothing
+ }
- public void sourceContainersChanged(ISourceLookupDirector director) {
- //do nothing
- }
+ public void sourceContainersChanged(ISourceLookupDirector director) {
+ //do nothing
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list