From 4f83e760c3b32f2d43806c28a30c463e0c7f470a Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 8 Sep 2010 07:04:58 +0000 Subject: Bug 323630 - Expanding registers in the register view triggers an infinite recursion loop in Eclipse/CDI --- .../META-INF/MANIFEST.MF | 2 +- .../cdt/debug/mi/core/cdi/RegisterManager.java | 4 +- .../cdt/debug/mi/core/cdi/model/Variable.java | 21 ++++++-- .../debug/mi/core/cdi/model/type/ArrayValue.java | 58 ++++++++++++++++------ .../org.eclipse.cdt.gnu.debug-feature/feature.xml | 2 +- 5 files changed, 63 insertions(+), 24 deletions(-) (limited to 'debug') diff --git a/debug/org.eclipse.cdt.debug.mi.core/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.mi.core/META-INF/MANIFEST.MF index d9376777abb..d078a107614 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.mi.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.debug.mi.core; singleton:=true -Bundle-Version: 7.0.0.qualifier +Bundle-Version: 7.1.0.qualifier Bundle-Activator: org.eclipse.cdt.debug.mi.core.MIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin 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 372dc4d50c6..0af48e37390 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 QNX Software Systems and others. + * Copyright (c) 2000, 2010 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 @@ -449,10 +449,12 @@ public class RegisterManager extends Manager { private Register findRegister(RegisterDescriptor rd) throws CDIException { Target target = (Target)rd.getTarget(); String name = rd.getName(); + String fullName = rd.getFullName(); int position = rd.getPosition(); Register[] regs = getRegisters(target); for (int i = 0; i < regs.length; i++) { if (regs[i].getName().equals(name) + && regs[i].getFullName().equals(fullName) && regs[i].getCastingArrayStart() == rd.getCastingArrayStart() && regs[i].getCastingArrayEnd() == rd.getCastingArrayEnd() && VariableDescriptor.equalsCasting(regs[i], rd)) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java index 6e0665c7be8..03d7472d94f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java @@ -154,7 +154,12 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl return fMIVar; } - private String getHexAddress() throws CDIException { + /** + * @return The address of this variable as hex string if available, otherwise an empty string. + * @noreference This method is not intended to be referenced by clients outside CDT. + * @since 7.1 + */ + public String getHexAddress() throws CDIException { if (hexAddress != null) { return hexAddress; } @@ -162,8 +167,13 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl String qualName = "&(" + getQualifiedName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ VariableDescriptor desc = createDescriptor((Target)getTarget(), (Thread)getThread(), (StackFrame)getStackFrame(), getName(), qualName, getPosition(), getStackDepth()); Variable v = vm.createVariable( desc ); - v.setFormat(ICDIFormat.HEXADECIMAL); - hexAddress = v.getValue().getValueString(); + // make sure to avoid infinite recursion. see bug 323630 + if (v != this) { + v.setFormat(ICDIFormat.HEXADECIMAL); + hexAddress = v.getValue().getValueString(); + } else { + hexAddress = ""; //$NON-NLS-1$ + } return hexAddress; } @@ -361,7 +371,7 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl } else if (t instanceof ICDIReferenceType) { value = new ReferenceValue(this); } else if (t instanceof ICDIArrayType) { - value = new ArrayValue(this, getHexAddress()); + value = new ArrayValue(this); } else if (t instanceof ICDIStructType) { value = new StructValue(this); } else { @@ -510,7 +520,8 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor#getTypeName() */ - public String getTypeName() throws CDIException { + @Override + public String getTypeName() throws CDIException { if (fTypename == null) { fTypename = getMIVar().getType(); if (fTypename == null || fTypename.length() == 0) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java index ade3236a746..1e75abb6220 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2010 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 @@ -34,6 +34,16 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue, ICDIPoin private String hexAddress; + /** + * Construct the array value object given a variable + * + * @param v + * @since 7.1 + */ + public ArrayValue(Variable v) { + super(v); + } + /** * Construct the array value object given a variable and the * hexadecimal address of the variable. @@ -41,21 +51,35 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue, ICDIPoin * @param v * @param hexAddress */ - public ArrayValue(Variable v, String hexAddress) { - super(v); - if (hexAddress == null || hexAddress.trim().length()==0) { - return; - } else if (hexAddress.startsWith("0x") || hexAddress.startsWith("0X")) { //$NON-NLS-1$ //$NON-NLS-2$ - this.hexAddress = hexAddress.substring(2); + public ArrayValue(Variable v, String address) { + this(v); + hexAddress = address; + } + + /** + * Compute array address as string. + */ + private String getAddressString() throws CDIException { + if (hexAddress != null) + return hexAddress; + + String address = getVariable().getHexAddress(); + if (address == null) { + address = ""; //$NON-NLS-1$ + } + if (address.startsWith("0x") || address.startsWith("0X")) { //$NON-NLS-1$ //$NON-NLS-2$ + hexAddress = address.substring(2); } else { - this.hexAddress = hexAddress; + hexAddress = address; } + return hexAddress; } - + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getVariables() */ - public ICDIVariable[] getVariables() throws CDIException { + @Override + public ICDIVariable[] getVariables() throws CDIException { /* GDB is appallingly slow on array fetches. As as slow as 128 entries * per second on NT gdbs with slow processors. We need to set a timeout @@ -102,12 +126,14 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue, ICDIPoin * @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue#pointerValue() */ public BigInteger pointerValue() throws CDIException { - if (hexAddress == null) - return null; - try { - return new BigInteger(hexAddress, 16); - } catch (NumberFormatException e) { - return null; + String address = getAddressString(); + if (address.length() > 0 ){ + try { + return new BigInteger(address, 16); + } catch (NumberFormatException e) { + return null; + } } + return null; } } diff --git a/debug/org.eclipse.cdt.gnu.debug-feature/feature.xml b/debug/org.eclipse.cdt.gnu.debug-feature/feature.xml index 32e2aab00e7..680c8b75b81 100644 --- a/debug/org.eclipse.cdt.gnu.debug-feature/feature.xml +++ b/debug/org.eclipse.cdt.gnu.debug-feature/feature.xml @@ -2,7 +2,7 @@ -- cgit v1.2.3