diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java index 2521d34126f..14e135519ef 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java @@ -184,9 +184,10 @@ public class ExpressionManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIVarCreate var = factory.createMIVarCreate(code); @@ -204,6 +205,7 @@ public class ExpressionManager extends Manager { } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java index 6d495e7cd37..487b8b7e0c1 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java @@ -254,9 +254,10 @@ public class RegisterManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIVarCreate var = factory.createMIVarCreate(regName); @@ -269,8 +270,12 @@ public class RegisterManager extends Manager { } catch (MIException e) { throw new MI2CDIException(e); } finally { + try { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + } finally { + target.releaseTarget(); + } } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java index ea75cc50402..03e0be4e9a9 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java @@ -424,13 +424,15 @@ public class SourceManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); return getDetailTypeName(target, variable); } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } public String getDetailTypeName(Target target, String typename) throws CDIException { @@ -460,13 +462,15 @@ public class SourceManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); return getTypeName(target, variable); } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java index db8e78fa226..9bff31b2a62 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java @@ -175,9 +175,10 @@ public class VariableManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); MISession miSession = target.getMISession(); RxThread rxThread = miSession.getRxThread(); rxThread.setEnableConsole(false); @@ -196,6 +197,7 @@ public class VariableManager extends Manager { rxThread.setEnableConsole(true); target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } else { throw new CDIException(CdiResources.getString("cdi.VariableManager.Unknown_type")); //$NON-NLS-1$ @@ -367,9 +369,10 @@ public class VariableManager extends Manager { Target target = (Target)argDesc.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(stack.getThread(), false); - ((Thread)stack.getThread()).setCurrentStackFrame(stack, false); + target.lockTarget(); try { + target.setCurrentThread(stack.getThread(), false); + ((Thread)stack.getThread()).setCurrentStackFrame(stack, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIVarCreate var = factory.createMIVarCreate(name); @@ -388,6 +391,7 @@ public class VariableManager extends Manager { } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } return argument; @@ -398,9 +402,10 @@ public class VariableManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); int depth = frame.getThread().getStackFrameCount(); @@ -429,6 +434,7 @@ public class VariableManager extends Manager { } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } return (ICDIArgumentDescriptor[]) argObjects.toArray(new ICDIArgumentDescriptor[0]); } @@ -489,9 +495,10 @@ public class VariableManager extends Manager { Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + target.lockTarget(); try { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); int level = frame.getLevel(); @@ -514,6 +521,7 @@ public class VariableManager extends Manager { } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } return (ICDILocalVariableDescriptor[]) varObjects.toArray(new ICDILocalVariableDescriptor[0]); } @@ -530,9 +538,10 @@ public class VariableManager extends Manager { Target target = (Target)varDesc.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); - target.setCurrentThread(stack.getThread(), false); - ((Thread)stack.getThread()).setCurrentStackFrame(stack, false); + target.lockTarget(); try { + target.setCurrentThread(stack.getThread(), false); + ((Thread)stack.getThread()).setCurrentStackFrame(stack, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIVarCreate var = factory.createMIVarCreate(name); @@ -551,6 +560,7 @@ public class VariableManager extends Manager { } finally { target.setCurrentThread(currentThread, false); currentThread.setCurrentStackFrame(currentFrame, false); + target.releaseTarget(); } } return local; diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java index dcad7a5931d..f508a6e67ed 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.mi.core.cdi.model; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; + import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIAddressLocation; import org.eclipse.cdt.debug.core.cdi.ICDICondition; @@ -87,6 +88,45 @@ import org.eclipse.cdt.debug.mi.core.output.MIThreadSelectInfo; */ public class Target extends SessionObject implements ICDITarget { + public class Lock { + + java.lang.Thread heldBy; + int count; + + public Lock() { + + } + + public synchronized void aquire() { + if (heldBy == null || heldBy == java.lang.Thread.currentThread()) { + heldBy = java.lang.Thread.currentThread(); + count++; + } else { + while (true) { + try { + wait(); + } catch (InterruptedException e) { + } + if (heldBy == null) { + heldBy = java.lang.Thread.currentThread(); + count++; + return; + } + } + } + } + + public synchronized void release() { + if (heldBy == null || heldBy != java.lang.Thread.currentThread()) { + throw new IllegalStateException("Thread does not own lock"); + } + if(--count == 0) { + heldBy = null; + notifyAll(); + } + } + } + MISession miSession; ICDITargetConfiguration fConfiguration; Thread[] noThreads = new Thread[0]; @@ -95,13 +135,22 @@ public class Target extends SessionObject implements ICDITarget { String fEndian = null; boolean suspended = true; boolean deferBreakpoints = true; - + Lock lock = new Lock(); + public Target(Session s, MISession mi) { super(s); miSession = mi; currentThreads = noThreads; } + public void lockTarget() { + lock.aquire(); + } + + public void releaseTarget() { + lock.release(); + } + public MISession getMISession() { return miSession; } @@ -116,7 +165,7 @@ public class Target extends SessionObject implements ICDITarget { public ICDITarget getTarget() { return this; } - + /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#setCurrentThread(ICDIThread) */ @@ -127,7 +176,7 @@ public class Target extends SessionObject implements ICDITarget { throw new CDIException(CdiResources.getString("cdi.model.Target.Unknown_thread")); //$NON-NLS-1$ } } - + public void setCurrentThread(ICDIThread cthread, boolean doUpdate) throws CDIException { if (cthread instanceof Thread) { setCurrentThread((Thread)cthread, doUpdate); @@ -163,7 +212,7 @@ public class Target extends SessionObject implements ICDITarget { currentThreadId = info.getNewThreadId(); // @^&#@^$*^$ - // GDB reset the currentFrame to some other level 0 when switching thread. + // GDB reset the currentFrame to some other level 0 when switching thread. // we need to reposition the current stack level. MIFrame miFrame = info.getFrame(); if (miFrame != null) { @@ -176,7 +225,7 @@ public class Target extends SessionObject implements ICDITarget { Session session = (Session)getSession(); // Resetting threads may change the value of - // some variables like Register. Call an update() + // some variables like Register. Call an update() // To generate changeEvents. if (doUpdate) { RegisterManager regMgr = session.getRegisterManager(); @@ -192,7 +241,7 @@ public class Target extends SessionObject implements ICDITarget { // We should be allright now. if (currentThreadId != id) { - // thread is gone. Generate a Thread destroyed. + // thread is gone. Generate a Thread destroyed. miSession.fireEvent(new MIThreadExitEvent(miSession, id)); throw new CDIException(CdiResources.getString("cdi.model.Target.Cannot_switch_to_thread") + id); //$NON-NLS-1$ } @@ -205,7 +254,7 @@ public class Target extends SessionObject implements ICDITarget { Thread[] oldThreads = currentThreads; // If we use "info threads" in getCThreads() this - // will be overwritten. However if we use -stack-list-threads + // will be overwritten. However if we use -stack-list-threads // it does not provide to the current thread currentThreadId = newThreadId; @@ -280,11 +329,11 @@ public class Target extends SessionObject implements ICDITarget { // HACK/FIXME: gdb/mi thread-list-ids does not // show any newly create thread, we workaround by // issuing "info threads" instead. - //MIThreadListIds tids = factory.createMIThreadListIds(); - //MIThreadListIdsInfo info = tids.getMIThreadListIdsInfo(); + // MIThreadListIds tids = factory.createMIThreadListIds(); + // MIThreadListIdsInfo info = tids.getMIThreadListIdsInfo(); miSession.postCommand(tids); CLIInfoThreadsInfo info = tids.getMIInfoThreadsInfo(); - int [] ids; + int[] ids; String[] names; if (info == null) { ids = new int[0]; @@ -310,7 +359,7 @@ public class Target extends SessionObject implements ICDITarget { cthreads = new Thread[]{new Thread(this, 0)}; } currentThreadId = info.getCurrentThread(); - //FIX: When attaching there is no thread selected + // FIX: When attaching there is no thread selected // We will choose the first one as a workaround. if (currentThreadId == 0 && cthreads.length > 0) { currentThreadId = cthreads[0].getId(); @@ -416,10 +465,9 @@ public class Target extends SessionObject implements ICDITarget { } } catch (MIException e) { throw new MI2CDIException(e); - } + } } - /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#stepIntoInstruction() */ @@ -442,7 +490,7 @@ public class Target extends SessionObject implements ICDITarget { } catch (MIException e) { throw new MI2CDIException(e); } - + } /** @@ -466,7 +514,7 @@ public class Target extends SessionObject implements ICDITarget { } } catch (MIException e) { throw new MI2CDIException(e); - } + } } /** @@ -529,14 +577,14 @@ public class Target extends SessionObject implements ICDITarget { } } } else if (location instanceof ICDIAddressLocation) { - ICDIAddressLocation addrLocation = (ICDIAddressLocation) location; - if (! addrLocation.getAddress().equals(BigInteger.ZERO)) { + ICDIAddressLocation addrLocation = (ICDIAddressLocation)location; + if (!addrLocation.getAddress().equals(BigInteger.ZERO)) { loc = "*0x" + addrLocation.getAddress().toString(16); //$NON-NLS-1$ } } // Throw an exception we do know where to go if (loc == null) { - throw new CDIException (CdiResources.getString("cdi.mode.Target.Bad_location")); //$NON-NLS-1$ + throw new CDIException(CdiResources.getString("cdi.mode.Target.Bad_location")); //$NON-NLS-1$ } MIExecUntil until = factory.createMIExecUntil(loc); try { @@ -547,7 +595,7 @@ public class Target extends SessionObject implements ICDITarget { } } catch (MIException e) { throw new MI2CDIException(e); - } + } } /** @@ -580,7 +628,7 @@ public class Target extends SessionObject implements ICDITarget { ((EventManager)getSession().getEventManager()).allowProcessingEvents(false); suspend(); } finally { - ((EventManager)getSession().getEventManager()).allowProcessingEvents(true); + ((EventManager)getSession().getEventManager()).allowProcessingEvents(true); } } CommandFactory factory = miSession.getCommandFactory(); @@ -651,7 +699,7 @@ public class Target extends SessionObject implements ICDITarget { } } catch (MIException e) { throw new MI2CDIException(e); - } + } } /** @@ -676,14 +724,14 @@ public class Target extends SessionObject implements ICDITarget { } } } else if (location instanceof ICDIAddressLocation) { - ICDIAddressLocation addrLocation = (ICDIAddressLocation) location; - if (! addrLocation.getAddress().equals(BigInteger.ZERO)) { + ICDIAddressLocation addrLocation = (ICDIAddressLocation)location; + if (!addrLocation.getAddress().equals(BigInteger.ZERO)) { loc = "*0x" + addrLocation.getAddress().toString(16); //$NON-NLS-1$ } } // Throw an exception we do know where to go if (loc == null) { - throw new CDIException (CdiResources.getString("cdi.mode.Target.Bad_location")); //$NON-NLS-1$ + throw new CDIException(CdiResources.getString("cdi.mode.Target.Bad_location")); //$NON-NLS-1$ } CLIJump jump = factory.createCLIJump(loc); @@ -871,10 +919,10 @@ public class Target extends SessionObject implements ICDITarget { */ public void deleteAllBreakpoints() throws CDIException { BreakpointManager bMgr = ((Session)getSession()).getBreakpointManager(); - bMgr.deleteAllBreakpoints(this); + bMgr.deleteAllBreakpoints(this); } - /* + /* * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#createCondition(int, java.lang.String, String) */ public ICDICondition createCondition(int ignoreCount, String expression) { @@ -1090,14 +1138,14 @@ public class Target extends SessionObject implements ICDITarget { if (fConfiguration == null) { if (miSession.isProgramSession()) { fConfiguration = new TargetConfiguration(this); - } else if (miSession.isAttachSession()){ + } else if (miSession.isAttachSession()) { fConfiguration = new TargetConfiguration(this); } else if (miSession.isCoreSession()) { fConfiguration = new CoreFileConfiguration(this); } else { - fConfiguration = new TargetConfiguration(this); + fConfiguration = new TargetConfiguration(this); } - } + } return fConfiguration; } @@ -1119,12 +1167,12 @@ public class Target extends SessionObject implements ICDITarget { if (varDesc instanceof RegisterDescriptor) { Session session = (Session)getTarget().getSession(); RegisterManager mgr = session.getRegisterManager(); - return mgr.createRegister((RegisterDescriptor)varDesc); + return mgr.createRegister((RegisterDescriptor)varDesc); } - return null; + return null; } - public void deferBreakpoints( boolean defer ) { + public void deferBreakpoints(boolean defer) { this.deferBreakpoints = defer; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java index 6e3c9fcfcb8..a8488ad6055 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java @@ -109,8 +109,9 @@ public class Thread extends CObject implements ICDIThread { currentFrames = new ArrayList(); Target target = (Target)getTarget(); ICDIThread currentThread = target.getCurrentThread(); - target.setCurrentThread(this, false); + target.lockTarget(); try { + target.setCurrentThread(this, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIStackListFrames frames = factory.createMIStackListFrames(); @@ -131,6 +132,7 @@ public class Thread extends CObject implements ICDIThread { //System.out.println(e); } finally { target.setCurrentThread(currentThread, false); + target.releaseTarget(); } // assign the currentFrame if it was not done yet. if (currentFrame == null) { @@ -152,8 +154,9 @@ public class Thread extends CObject implements ICDIThread { if (stackdepth == 0) { Target target = (Target)getTarget(); ICDIThread currentThread = target.getCurrentThread(); - target.setCurrentThread(this, false); + target.lockTarget(); try { + target.setCurrentThread(this, false); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); MIStackInfoDepth depth = factory.createMIStackInfoDepth(); @@ -184,6 +187,7 @@ public class Thread extends CObject implements ICDIThread { throw new MI2CDIException(e); } finally { target.setCurrentThread(currentThread, false); + target.releaseTarget(); } } return stackdepth; @@ -197,8 +201,9 @@ public class Thread extends CObject implements ICDIThread { currentFrames = new ArrayList(); Target target = (Target) getTarget(); ICDIThread currentThread = target.getCurrentThread(); - target.setCurrentThread(this, false); + target.lockTarget(); try { + target.setCurrentThread(this, false); int depth = getStackFrameCount(); int upperBound; // try to get the largest subset. @@ -230,6 +235,7 @@ public class Thread extends CObject implements ICDIThread { //System.out.println(e); } finally { target.setCurrentThread(currentThread, false); + target.releaseTarget(); } // take time to assign the currentFrame, if it is in the set if (currentFrame == null) { @@ -268,7 +274,6 @@ public class Thread extends CObject implements ICDIThread { } } - try { Target target = (Target)getTarget(); MISession mi = target.getMISession(); CommandFactory factory = mi.getCommandFactory(); @@ -277,29 +282,33 @@ public class Thread extends CObject implements ICDIThread { int miLevel = getStackFrameCount() - frameLevel; MIStackSelectFrame frame = factory.createMIStackSelectFrame(miLevel); // Set ourself as the current thread first. - target.setCurrentThread(this, doUpdate); - mi.postCommand(frame); - MIInfo info = frame.getMIInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ - } - currentFrame = stackframe; - // Resetting stackframe may change the value of - // some variables like registers. Call an update() - // To generate changeEvents. - if (doUpdate) { - Session session = (Session) target.getSession(); - RegisterManager regMgr = session.getRegisterManager(); - if (regMgr.isAutoUpdate()) { - regMgr.update(target); + target.lockTarget(); + try { + target.setCurrentThread(this, doUpdate); + mi.postCommand(frame); + MIInfo info = frame.getMIInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ } - VariableManager varMgr = session.getVariableManager(); - if (varMgr.isAutoUpdate()) { - varMgr.update(target); + currentFrame = stackframe; + // Resetting stackframe may change the value of + // some variables like registers. Call an update() + // To generate changeEvents. + if (doUpdate) { + Session session = (Session) target.getSession(); + RegisterManager regMgr = session.getRegisterManager(); + if (regMgr.isAutoUpdate()) { + regMgr.update(target); + } + VariableManager varMgr = session.getVariableManager(); + if (varMgr.isAutoUpdate()) { + varMgr.update(target); + } } - } } catch (MIException e) { throw new MI2CDIException(e); + } finally { + target.releaseTarget(); } } @@ -314,8 +323,13 @@ public class Thread extends CObject implements ICDIThread { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteStep#stepInto(int) */ public void stepInto(int count) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().stepInto(count); + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().stepInto(count); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /** @@ -329,8 +343,13 @@ public class Thread extends CObject implements ICDIThread { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteStep#stepIntoInstruction(int) */ public void stepIntoInstruction(int count) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().stepIntoInstruction(count); + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().stepIntoInstruction(count); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /** @@ -344,9 +363,13 @@ public class Thread extends CObject implements ICDIThread { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteStep#stepOver(int) */ public void stepOver(int count) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().stepOver(count); - + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().stepOver(count); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /** @@ -360,8 +383,13 @@ public class Thread extends CObject implements ICDIThread { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteStep#stepOverInstruction(int) */ public void stepOverInstruction(int count) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().stepOverInstruction(count); + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().stepOverInstruction(count); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /** @@ -382,9 +410,14 @@ public class Thread extends CObject implements ICDIThread { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteStep#stepUntil(org.eclipse.cdt.debug.core.cdi.ICDILocation) */ public void stepUntil(ICDILocation location) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().stepUntil(location); - } + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().stepUntil(location); + } finally { + ((Target)getTarget()).releaseTarget(); + } +} /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#isSuspended() @@ -412,26 +445,38 @@ public class Thread extends CObject implements ICDIThread { */ public void resume(boolean passSignal) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().resume(passSignal); + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().resume(passSignal); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteResume#resume(org.eclipse.cdt.debug.core.cdi.ICDILocation) */ public void resume(ICDILocation location) throws CDIException { - // TODO Auto-generated method stub - ((Target)getTarget()).setCurrentThread(this); - getTarget().resume(location); - + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().resume(location); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteResume#resume(org.eclipse.cdt.debug.core.cdi.model.ICDISignal) */ public void resume(ICDISignal signal) throws CDIException { - ((Target)getTarget()).setCurrentThread(this); - getTarget().resume(signal); - + ((Target)getTarget()).lockTarget(); + try { + ((Target)getTarget()).setCurrentThread(this); + getTarget().resume(signal); + } finally { + ((Target)getTarget()).releaseTarget(); + } } /** diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java index abf91c666cd..68fbe22b2e5 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java @@ -240,17 +240,18 @@ public abstract class VariableDescriptor extends CObject implements ICDIVariable StackFrame currentFrame = currentThread.getCurrentStackFrame(); StackFrame frame = (StackFrame)getStackFrame(); Thread thread = (Thread)getThread(); - if (frame != null) { - target.setCurrentThread(frame.getThread(), false); - ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); - } else if (thread != null) { - target.setCurrentThread(thread, false); - } - MISession mi = target.getMISession(); - CommandFactory factory = mi.getCommandFactory(); - String exp = "sizeof(" + getTypeName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - MIDataEvaluateExpression evaluate = factory.createMIDataEvaluateExpression(exp); + target.lockTarget(); try { + if (frame != null) { + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + } else if (thread != null) { + target.setCurrentThread(thread, false); + } + MISession mi = target.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + String exp = "sizeof(" + getTypeName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + MIDataEvaluateExpression evaluate = factory.createMIDataEvaluateExpression(exp); mi.postCommand(evaluate); MIDataEvaluateExpressionInfo info = evaluate.getMIDataEvaluateExpressionInfo(); if (info == null) { @@ -260,11 +261,15 @@ public abstract class VariableDescriptor extends CObject implements ICDIVariable } catch (MIException e) { throw new MI2CDIException(e); } finally { - if (frame != null) { - target.setCurrentThread(currentThread, false); - currentThread.setCurrentStackFrame(currentFrame, false); - } else if (thread != null) { - target.setCurrentThread(currentThread, false); + try { + if (frame != null) { + target.setCurrentThread(currentThread, false); + currentThread.setCurrentStackFrame(currentFrame, false); + } else if (thread != null) { + target.setCurrentThread(currentThread, false); + } + } finally { + target.releaseTarget(); } } }