diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index d7ba1da3876..c335132ea63 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,15 @@ +2004-05-28 Alain Magloire + + Fix to PR 60020. + GDB returns the children when a pointer + points to a structure. + Also ignore the keyword "const" when parsing. + + * cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java + * src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java + 2004-05-18 Alain Magloire Remove dependencies on the compatibility plugin 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 e039661e774..de4a0fe1133 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 @@ -42,11 +42,13 @@ import org.eclipse.cdt.debug.mi.core.command.MIDataDisassemble; import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowDirectories; import org.eclipse.cdt.debug.mi.core.command.MIPType; +import org.eclipse.cdt.debug.mi.core.command.MIWhatis; import org.eclipse.cdt.debug.mi.core.output.MIAsm; import org.eclipse.cdt.debug.mi.core.output.MIDataDisassembleInfo; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowDirectoriesInfo; import org.eclipse.cdt.debug.mi.core.output.MIPTypeInfo; import org.eclipse.cdt.debug.mi.core.output.MISrcAsm; +import org.eclipse.cdt.debug.mi.core.output.MIWhatisInfo; /** @@ -240,7 +242,12 @@ public class SourceManager extends Manager implements ICDISourceManager { } gdbType = ((GDBDerivedType)gdbType).getChild(); } else { - aType = toCDIType(target, gdbType.toString()); + //try { + aType = toCDIType(target, gdbType.toString()); + //} catch (CDIException e) { + // String ptype = getDetailTypeName(gdbType.toString()); + // aType = getType(target, ptype); + //} gdbType = null; } if (type instanceof DerivedType) { @@ -426,4 +433,21 @@ public class SourceManager extends Manager implements ICDISourceManager { } } + public String getTypeName(String variable) throws CDIException { + try { + Session session = (Session) getSession(); + MISession mi = session.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIWhatis whatis = factory.createMIWhatis(variable); + mi.postCommand(whatis); + MIWhatisInfo info = whatis.getMIWhatisInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + return info.getType(); + } catch (MIException e) { + throw new MI2CDIException(e); + } + } + } 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 949597d104e..0dcc00e64e6 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 @@ -165,7 +165,7 @@ public class Variable extends VariableObject implements ICDIVariable { for (int i = 0; i < vars.length; i++) { String fn= getFullName(); String childName = vars[i].getExp(); - String childTypename = null; + ICDIType childType = null; boolean childFake = false; ICDIType t = getType(); if (t instanceof ICDIArrayType) { @@ -174,7 +174,22 @@ public class Variable extends VariableObject implements ICDIVariable { int index = castingIndex + i; childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } else if (t instanceof ICDIPointerType) { - fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + ICDIType subType = ((ICDIPointerType)t).getComponentType(); + if (subType instanceof ICDIStructType) { + if (isCPPLanguage()) { + if (!isFake() + || (isFake() && !(name.equals("private") || name.equals("public") || name.equals("protected")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + childFake = true; + childType = t; + } else { + fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$ + } + } else { // If not C++ language + fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$ + } + } else { + fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } } else if (t instanceof ICDIStructType) { if (isCPPLanguage()) { // For C++ in GDB the children of the @@ -196,7 +211,7 @@ public class Variable extends VariableObject implements ICDIVariable { if (!isFake() || (isFake() && !(name.equals("private") || name.equals("public") || name.equals("protected")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ childFake = true; - childTypename = getTypeName(); + childType = t; } else { fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -205,9 +220,9 @@ public class Variable extends VariableObject implements ICDIVariable { } } Variable v = new Variable(getTarget(), childName, fn, getStackFrame(), getPosition(), getStackDepth(), vars[i]); - if (childTypename != null) { + if (childType != null) { // Hack to reset the typename to a known value - v.typename = childTypename; + v.type = childType; } v.setIsFake(childFake); children[i] = v; @@ -222,20 +237,6 @@ public class Variable extends VariableObject implements ICDIVariable { return miVar.getNumChild(); } - /** - * We overload the VariableObject since the gdb-varobject already knows - * the type and its probably more accurate. - * - * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getTypeName() - */ - public String getTypeName() throws CDIException { - // We overload here not to use the whatis command. - if (typename == null) { - typename = miVar.getType(); - } - return typename; - } - /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java index dbeb7613f92..419e584b6c2 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java @@ -22,12 +22,9 @@ import org.eclipse.cdt.debug.mi.core.cdi.MI2CDIException; import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.SourceManager; import org.eclipse.cdt.debug.mi.core.cdi.model.type.IncompleteType; -import org.eclipse.cdt.debug.mi.core.cdi.model.type.Type; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.MIDataEvaluateExpression; -import org.eclipse.cdt.debug.mi.core.command.MIWhatis; import org.eclipse.cdt.debug.mi.core.output.MIDataEvaluateExpressionInfo; -import org.eclipse.cdt.debug.mi.core.output.MIWhatisInfo; import org.eclipse.cdt.debug.mi.core.cdi.CdiResources; /** @@ -46,7 +43,7 @@ public class VariableObject extends CObject implements ICDIVariableObject { String qualifiedName = null; String fullName = null; - Type type = null; + ICDIType type = null; String typename = null; String sizeof = null; @@ -159,7 +156,7 @@ public class VariableObject extends CObject implements ICDIVariableObject { ICDITarget target = getTarget(); Session session = (Session) (target.getSession()); SourceManager sourceMgr = (SourceManager) session.getSourceManager(); - String nametype = getTypeName(); + String nametype = sourceMgr.getTypeName(getQualifiedName()); try { type = sourceMgr.getType(target, nametype); } catch (CDIException e) { @@ -168,6 +165,15 @@ public class VariableObject extends CObject implements ICDIVariableObject { String ptype = sourceMgr.getDetailTypeName(nametype); type = sourceMgr.getType(target, ptype); } catch (CDIException ex) { + // Some version of gdb does not work woth the name of the class + // ex: class data foo --> ptype data --> fails + // ex: class data foo --> ptype foo --> succeed + try { + String ptype = sourceMgr.getDetailTypeName(getQualifiedName()); + type = sourceMgr.getType(target, ptype); + } catch (CDIException e2) { + // give up. + } } } if (type == null) { @@ -236,21 +242,8 @@ public class VariableObject extends CObject implements ICDIVariableObject { */ public String getTypeName() throws CDIException { if (typename == null) { - try { - ICDITarget target = getTarget(); - Session session = (Session) (target.getSession()); - MISession mi = session.getMISession(); - CommandFactory factory = mi.getCommandFactory(); - MIWhatis whatis = factory.createMIWhatis(getQualifiedName()); - mi.postCommand(whatis); - MIWhatisInfo info = whatis.getMIWhatisInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ - } - typename = info.getType(); - } catch (MIException e) { - throw new MI2CDIException(e); - } + ICDIType theType = getType(); + typename = theType.getTypeName(); } return typename; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java index 181ba65d21f..80d9de47b1f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java @@ -6,6 +6,8 @@ package org.eclipse.cdt.debug.mi.core; +import java.util.regex.Pattern; + /** * GDB Type Parser. * The code was lifted from: The C Programming Language @@ -53,6 +55,7 @@ public class GDBTypeParser { if (s == null) { s = new String(); } + s = Pattern.compile("\\bconst\\b").matcher(s).replaceAll(""); s = s.trim(); // Initialize. @@ -70,10 +73,13 @@ public class GDBTypeParser { // Hack for GDB, the typename can be something like // class A : public B, C { ... } * - // We are only interreste in "class A" + // We are only interested in "class A" + // Carefull for class A::data int column = dataType.indexOf(':'); if (column > 0) { - dataType = dataType.substring(0, column); + if ((column + 1) < dataType.length() && dataType.charAt(column + 1) != ':') { + dataType = dataType.substring(0, column); + } } genericType = new GDBType(dataType); @@ -220,7 +226,7 @@ public class GDBTypeParser { // GDB hack accept ':' ',' part of the GDB hacks // when doing ptype gdb returns "class A : public C { ..}" boolean isCIdentifierPart(int c) { - if ((c >= '0' && c <= 9) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') { + if ((c >= '0' && c <= 9) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == ':') { return true; } return false;