1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fix for 221224: debugger mi target locking problems

Patch contributed by Alena Laskavaia <elaskavaia@qnx.com>
This commit is contained in:
Anton Leherbauer 2008-03-13 08:59:36 +00:00
parent 8d07be5f20
commit da521c277c
7 changed files with 235 additions and 308 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi;
@ -184,7 +185,7 @@ public class ExpressionManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -203,11 +204,8 @@ public class ExpressionManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Giuseppe Montalto, STMicroelectronics - bug 174988
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi;
@ -255,7 +256,7 @@ public class RegisterManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -271,11 +272,8 @@ 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();
}
}
}
@ -284,7 +282,7 @@ public class RegisterManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -301,11 +299,8 @@ 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();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi;
@ -424,17 +425,14 @@ public class SourceManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
return getDetailTypeName(target, variable);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
}
@ -465,17 +463,14 @@ public class SourceManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
return getTypeName(target, variable);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,7 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alena Laskavaia (QNX) - Bug 197986
* Alena Laskavaia (QNX) - Bug 197986, Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi;
@ -177,7 +177,7 @@ public class VariableManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -194,14 +194,11 @@ public class VariableManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
MISession miSession = target.getMISession();
RxThread rxThread = miSession.getRxThread();
rxThread.setEnableConsole(true);
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
} else {
@ -374,7 +371,7 @@ public class VariableManager extends Manager {
Target target = (Target)argDesc.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(stack.getThread(), false);
((Thread)stack.getThread()).setCurrentStackFrame(stack, false);
@ -394,11 +391,8 @@ public class VariableManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
}
@ -410,7 +404,7 @@ public class VariableManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -440,11 +434,8 @@ public class VariableManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
return (ICDIArgumentDescriptor[]) argObjects.toArray(new ICDIArgumentDescriptor[0]);
@ -506,7 +497,7 @@ public class VariableManager extends Manager {
Target target = (Target)frame.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(frame.getThread(), false);
((Thread)frame.getThread()).setCurrentStackFrame(frame, false);
@ -530,11 +521,8 @@ public class VariableManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
return (ICDILocalVariableDescriptor[]) varObjects.toArray(new ICDILocalVariableDescriptor[0]);
@ -552,7 +540,7 @@ public class VariableManager extends Manager {
Target target = (Target)varDesc.getTarget();
Thread currentThread = (Thread)target.getCurrentThread();
StackFrame currentFrame = currentThread.getCurrentStackFrame();
target.lockTarget();
synchronized(target.getLock()) {
try {
target.setCurrentThread(stack.getThread(), false);
((Thread)stack.getThread()).setCurrentStackFrame(stack, false);
@ -572,11 +560,8 @@ public class VariableManager extends Manager {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} finally {
target.releaseTarget();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Ken Ryall (Nokia) - 175532 support the address to source location API
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi.model;
@ -100,45 +101,6 @@ import org.eclipse.cdt.debug.mi.core.output.MIThreadSelectInfo;
*/
public class Target extends SessionObject implements ICDITarget, ICDIBreakpointManagement2, ICDIAddressToSource, ICDIMemorySpaceManagement {
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];
@ -147,7 +109,7 @@ public class Target extends SessionObject implements ICDITarget, ICDIBreakpointM
String fEndian = null;
boolean suspended = true;
boolean deferBreakpoints = true;
Lock lock = new Lock();
final private Object lock = new Object();
final static String CODE_MEMORY_SPACE = "code"; //$NON-NLS-1$
final static String DATA_MEMORY_SPACE = "data"; //$NON-NLS-1$
@ -158,13 +120,37 @@ public class Target extends SessionObject implements ICDITarget, ICDIBreakpointM
currentThreads = noThreads;
}
public void lockTarget() {
lock.aquire();
/**
* Return lock object for target. Replacement for <code>lockTarget</code> and
* <code>releaseTarget</code> methods.
* <p>
* Use as synchronization object:
* </p>
* new code:
*
* <pre>
* synchronized (target.getLock()) {
* ...
* }
* </pre>
*
* old code:
*
* <pre>
* target.lockTarget();
* try {
* ...
* } finally {
* target.releaseTarget();
* }
* </pre>
*
* @since 5.0
*/
public Object getLock() {
return lock;
}
public void releaseTarget() {
lock.release();
}
public MISession getMISession() {
return miSession;
@ -271,15 +257,14 @@ public class Target extends SessionObject implements ICDITarget, ICDIBreakpointM
// If we use "info threads" in getCThreads() this
// will be overwritten. However if we use -stack-list-threads
// it does not provide to the current thread
lockTarget();
synchronized (lock) {
try {
// get the new Threads.
currentThreadId = newThreadId;
currentThreads = getCThreads();
} catch (CDIException e) {
currentThreads = noThreads;
} finally {
releaseTarget();
}
}
// Fire CreatedEvent for new threads.
@ -338,10 +323,10 @@ public class Target extends SessionObject implements ICDITarget, ICDIBreakpointM
*/
public Thread[] getCThreads() throws CDIException {
Thread[] cthreads = noThreads;
try {
lockTarget();
synchronized (lock) {
RxThread rxThread = miSession.getRxThread();
rxThread.setEnableConsole(false);
try {
CommandFactory factory = miSession.getCommandFactory();
CLIInfoThreads tids = factory.createCLIInfoThreads();
// HACK/FIXME: gdb/mi thread-list-ids does not
@ -386,9 +371,8 @@ public class Target extends SessionObject implements ICDITarget, ICDIBreakpointM
// Do not throw anything in this case.
throw new CDIException(e.getMessage());
} finally {
RxThread rxThread = miSession.getRxThread();
rxThread.setEnableConsole(true);
releaseTarget();
}
}
return cthreads;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi.model;
@ -109,7 +110,7 @@ public class Thread extends CObject implements ICDIThread {
currentFrames = new ArrayList();
Target target = (Target)getTarget();
ICDIThread currentThread = target.getCurrentThread();
target.lockTarget();
synchronized (target.getLock()) {
try {
target.setCurrentThread(this, false);
MISession mi = target.getMISession();
@ -131,10 +132,7 @@ public class Thread extends CObject implements ICDIThread {
//throw e;
//System.out.println(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
} finally {
target.releaseTarget();
}
}
// assign the currentFrame if it was not done yet.
@ -157,7 +155,7 @@ public class Thread extends CObject implements ICDIThread {
if (stackdepth == 0) {
Target target = (Target)getTarget();
ICDIThread currentThread = target.getCurrentThread();
target.lockTarget();
synchronized (target.getLock()) {
try {
target.setCurrentThread(this, false);
MISession mi = target.getMISession();
@ -189,13 +187,7 @@ public class Thread extends CObject implements ICDIThread {
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
} catch (MI2CDIException e) {
target.releaseTarget();
throw e;
} finally {
target.releaseTarget();
}
}
}
@ -210,7 +202,7 @@ public class Thread extends CObject implements ICDIThread {
currentFrames = new ArrayList();
Target target = (Target) getTarget();
ICDIThread currentThread = target.getCurrentThread();
target.lockTarget();
synchronized (target.getLock()) {
try {
target.setCurrentThread(this, false);
int depth = getStackFrameCount();
@ -243,10 +235,7 @@ public class Thread extends CObject implements ICDIThread {
//throw e;
//System.out.println(e);
} finally {
try {
target.setCurrentThread(currentThread, false);
} finally {
target.releaseTarget();
}
}
// take time to assign the currentFrame, if it is in the set
@ -294,7 +283,7 @@ public class Thread extends CObject implements ICDIThread {
int miLevel = getStackFrameCount() - frameLevel;
MIStackSelectFrame frame = factory.createMIStackSelectFrame(miLevel);
// Set ourself as the current thread first.
target.lockTarget();
synchronized (target.getLock()) {
try {
target.setCurrentThread(this, doUpdate);
mi.postCommand(frame);
@ -319,8 +308,7 @@ public class Thread extends CObject implements ICDIThread {
}
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
target.releaseTarget();
}
}
}
@ -335,12 +323,10 @@ 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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().stepInto(count);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.stepInto(count);
}
}
@ -355,12 +341,10 @@ 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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().stepIntoInstruction(count);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.stepIntoInstruction(count);
}
}
@ -375,12 +359,10 @@ 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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().stepOver(count);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.stepOver(count);
}
}
@ -395,12 +377,10 @@ 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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().stepOverInstruction(count);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.stepOverInstruction(count);
}
}
@ -422,12 +402,10 @@ 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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().stepUntil(location);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.stepUntil(location);
}
}
@ -457,24 +435,20 @@ public class Thread extends CObject implements ICDIThread {
*/
public void resume(boolean passSignal) throws CDIException {
((Target)getTarget()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().resume(passSignal);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.resume(passSignal);
}
}
/* (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 {
((Target)getTarget()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().resume(location);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.resume(location);
}
}
@ -482,12 +456,10 @@ public class Thread extends CObject implements ICDIThread {
* @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()).lockTarget();
try {
((Target)getTarget()).setCurrentThread(this);
getTarget().resume(signal);
} finally {
((Target)getTarget()).releaseTarget();
Target target = (Target)getTarget();
synchronized(target.getLock()) {
target.setCurrentThread(this);
target.resume(signal);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alena Laskavaia (QNX) - Bug 221224
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi.model;
@ -240,7 +241,7 @@ public abstract class VariableDescriptor extends CObject implements ICDIVariable
StackFrame currentFrame = currentThread.getCurrentStackFrame();
StackFrame frame = (StackFrame)getStackFrame();
Thread thread = (Thread)getThread();
target.lockTarget();
synchronized(target.getLock()) {
try {
if (frame != null) {
target.setCurrentThread(frame.getThread(), false);
@ -261,15 +262,12 @@ public abstract class VariableDescriptor extends CObject implements ICDIVariable
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
try {
if (frame != null) {
target.setCurrentThread(currentThread, false);
currentThread.setCurrentStackFrame(currentFrame, false);
} else if (thread != null) {
target.setCurrentThread(currentThread, false);
}
} finally {
target.releaseTarget();
}
}
}