/** * tests that a breakpoint is hit with multiple inclusion filters set * * @throws Exception */ public void testMultiInclusiveScopedExceptionHit() throws Exception { String typeName = "ThrowsNPE"; IJavaExceptionBreakpoint ex = createExceptionBreakpoint("java.lang.NullPointerException", true, false); ex.setInclusionFilters(new String[] {"ThrowsNPE", "Breakpoints"}); IJavaThread thread = null; try { thread = launchToBreakpoint(typeName); assertNotNull("Did not suspend", thread); assertEquals("Should have suspended at NPE", ex, thread.getBreakpoints()[0]); ex.delete(); } finally { terminateAndRemove(thread); removeAllBreakpoints(); } }
/** * tests the hit count of an exception breakpoint * * @throws Exception */ public void testHitCountException() throws Exception { String typeName = "HitCountException"; IJavaExceptionBreakpoint ex = createExceptionBreakpoint("java.lang.NullPointerException", true, true); ex.setHitCount(2); IJavaThread thread = null; try { thread = launchToBreakpoint(typeName); IJavaStackFrame frame = (IJavaStackFrame) thread.getTopStackFrame(); assertEquals("Should have been suspended at linenumber", 35, frame.getLineNumber()); ex.delete(); } finally { terminateAndRemove(thread); removeAllBreakpoints(); } }
/** * tests that breakpoint suspends on uncaught exceptions * * @throws Exception */ public void testUncaughtException() throws Exception { String typeName = "HitCountException"; IJavaExceptionBreakpoint ex = createExceptionBreakpoint("java.lang.NullPointerException", false, true); IJavaThread thread = null; try { thread = launchToBreakpoint(typeName); assertNotNull("Breakpoint not hit within timeout period", thread); IBreakpoint hit = getBreakpoint(thread); assertNotNull("suspended, but not by breakpoint", hit); assertEquals("suspended, but not by exception breakpoint", ex, hit); IJavaStackFrame frame = (IJavaStackFrame) thread.getTopStackFrame(); assertTrue( "Should have been suspended at line number 35, not " + frame.getLineNumber(), frame.getLineNumber() == 35); ex.delete(); } finally { terminateAndRemove(thread); removeAllBreakpoints(); } }
/** @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { return fThread.isSuspended(); }
/** @see org.eclipse.debug.core.model.IDebugElement#getLaunch() */ public ILaunch getLaunch() { return fThread.getLaunch(); }
/** @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() */ public IDebugTarget getDebugTarget() { return fThread.getDebugTarget(); }
/** @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier() */ public String getModelIdentifier() { return fThread.getModelIdentifier(); }
/** * Update the information for this thread. * * @return <code>true</code> if the contended monitor or the owned monitors changed. */ private boolean update() { boolean changed = false; synchronized (this) { if (!fToUpdate) { return false; } try { // update the contended monitor IJavaObject contendedMonitor = fThread.getContendedMonitor(); if (contendedMonitor == null) { changed = fContendedMonitor != null; fContendedMonitor = null; } else { changed = fContendedMonitor == null || !contendedMonitor.equals(fContendedMonitor.getMonitor()); fContendedMonitor = ThreadMonitorManager.getDefault().getJavaMonitor(contendedMonitor); } // update the owned monitors IJavaObject[] ownedMonitors = fThread.getOwnedMonitors(); if (ownedMonitors == null || ownedMonitors.length == 0) { // no owned monitor, not much to do changed = fOwnedMonitors != null && fOwnedMonitors.length != 0; fOwnedMonitors = new JavaMonitor[0]; } else { JavaMonitor[] tmp = new JavaMonitor[ownedMonitors.length]; ThreadMonitorManager threadMonitorManager = ThreadMonitorManager.getDefault(); if (changed || fOwnedMonitors.length != ownedMonitors.length) { // if we know it changed, we can just create the new list. for (int i = 0; i < ownedMonitors.length; i++) { tmp[i] = threadMonitorManager.getJavaMonitor(ownedMonitors[i]); } changed = true; } else { // we need to check in the new list contains the same monitors as the // previous list int sameMonitor = 0; for (int i = 0; i < ownedMonitors.length; i++) { for (int j = 0; j < fOwnedMonitors.length; j++) { if (ownedMonitors[i].equals(fOwnedMonitors[i].getMonitor())) { sameMonitor++; break; } } tmp[i] = threadMonitorManager.getJavaMonitor(ownedMonitors[i]); } changed = sameMonitor != ownedMonitors.length; } fOwnedMonitors = tmp; } } catch (DebugException e) { Throwable cause = e.getStatus().getException(); if (!(cause instanceof IncompatibleThreadStateException)) { // IncompatibleThreadStateException are expected from Sun VMs // if the thread is not suspended. // For all other exceptions, null the values. fContendedMonitor = null; changed = fOwnedMonitors != null && fOwnedMonitors.length != 0; fOwnedMonitors = new JavaMonitor[0]; } } finally { fToUpdate = false; } } if (changed) { fireChangeEvent(DebugEvent.CONTENT); } return changed; }