Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] MI patch/fixes

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.153
diff -u -r1.153 ChangeLog
--- ChangeLog	6 Aug 2003 21:14:27 -0000	1.153
+++ ChangeLog	7 Aug 2003 03:25:52 -0000
@@ -1,5 +1,27 @@
 2003-08-06 Alain Magloire
 
+	Dealing with casting: Casting a field of a structure did not
+	work properly for example:
+		struct foo { int bar; } foobar;
+	To cast the field bar, we need to construct the full qualified
+	name "foobar.bar".
+	Unfortunately for C++ things are hectic in the GDB/MI world
+	the childre of structure are not the fields.  So we try to
+	deal with it too.
+
+	* src/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java:
+	New constructor, new method getLanguage() to deal with
+	different type of languages ex: C vs C++.
+	* src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java:
+	Clean up and added a bunch of set/getXXX() methods instead of
+	accessing directly the fields.
+	* src/og/eclipse/cdt/debug/mi/core/cdi/VariableManager.java:
+	Clean the methods use for casting and format the indentation.
+	* src/org/eclipse/cdt/debug/mi/core/command/MIVarInfoExpression.java:
+	Added parsing method.
+
+2003-08-06 Alain Magloire
+
 	* src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java:
 	Implement isEditable method.
 
Index: src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java,v
retrieving revision 1.35
diff -u -r1.35 VariableManager.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java	6 Aug 2003 19:52:27 -0000	1.35
+++ src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java	7 Aug 2003 03:25:52 -0000
@@ -13,7 +13,6 @@
 import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentObject;
-import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
 import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
@@ -92,11 +91,13 @@
 		int depth = v.getStackDepth();
 		Variable[] vars = getVariables();
 		for (int i = 0; i < vars.length; i++) {
-			if (vars[i].getName().equals(name) &&
-			    vars[i].casting_index == v.casting_index &&
-			    vars[i].casting_length == v.casting_length &&
-			    ((vars[i].casting_type == null && v.casting_type == null) ||
-			     (vars[i].casting_type != null && v.casting_type != null && vars[i].casting_type.equals(v.casting_type)))) {
+			if (vars[i].getName().equals(name)
+				&& vars[i].getCastingArrayStart() == v.getCastingArrayStart()
+				&& vars[i].getCastingArrayEnd() == v.getCastingArrayEnd()
+				&& ((vars[i].getCastingType() == null && v.getCastingType() == null)
+					|| (vars[i].getCastingType() != null
+						&& v.getCastingType() != null
+						&& vars[i].getCastingType().equals(v.getCastingType())))) {
 				ICDIStackFrame frame = vars[i].getStackFrame();
 				if (stack == null && frame == null) {
 					return vars[i];
@@ -123,49 +124,29 @@
 	 * Check the type
 	 */
 	public void checkType(String type) throws CDIException {
-		try {
-				MISession mi = ((Session)getSession()).getMISession();
+		if (type != null && type.length() > 0) {
+			try {
+				MISession mi = ((Session) getSession()).getMISession();
 				CommandFactory factory = mi.getCommandFactory();
 				MIPType ptype = factory.createMIPType(type);
 				mi.postCommand(ptype);
 				MIPTypeInfo info = ptype.getMIPtypeInfo();
 				if (info == null) {
-						throw new CDIException("No answer");
+					throw new CDIException("No answer");
 				}
-		} catch (MIException e) {
+			} catch (MIException e) {
 				throw new MI2CDIException(e);
-		}
-	}
-
-	public static String encodeVariable(VariableObject varObj) {
-		StringBuffer buffer = new StringBuffer();
-		if (varObj.casting_length > 0 || varObj.casting_index > 0) {
-			buffer.append("*(");
-			buffer.append('(');
-			if (varObj.casting_type != null && varObj.casting_type.length() > 0) {
-				buffer.append('(').append(varObj.casting_type).append(')');
-			}
-			buffer.append(varObj.getName());
-			buffer.append(')');
-			if (varObj.casting_index != 0) {
-					buffer.append('+').append(varObj.casting_index);
-			}
-			buffer.append(')');
-			buffer.append('@').append(varObj.casting_length - varObj.casting_index);
-		} else if (varObj.casting_type != null && varObj.casting_type.length() > 0) {
-			buffer.append('(').append(varObj.casting_type).append(')');
-			buffer.append('(').append(varObj.getName()).append(')');
+			}
 		} else {
-			buffer.append(varObj.getName());
+			throw new CDIException("Unkown type");
 		}
-		return buffer.toString();
 	}
 
 	/**
 	 * Tell gdb to remove the underlying var-object also.
 	 */
 	void removeMIVar(MIVar miVar) throws CDIException {
-		Session session = (Session)getSession();
+		Session session = (Session) getSession();
 		MISession mi = session.getMISession();
 		CommandFactory factory = mi.getCommandFactory();
 		MIVarDelete var = factory.createMIVarDelete(miVar.getVarName());
@@ -198,18 +179,18 @@
 	public ICDIArgument createArgument(ICDIArgumentObject a) throws CDIException {
 		ArgumentObject argObj = null;
 		if (a instanceof ArgumentObject) {
-			argObj = (ArgumentObject)a;
+			argObj = (ArgumentObject) a;
 		}
 		if (argObj != null) {
 			Variable variable = findVariable(argObj);
 			Argument argument = null;
 			if (variable != null && variable instanceof Argument) {
-				argument = (Argument)variable;
+				argument = (Argument) variable;
 			}
 			if (argument == null) {
-				String name = encodeVariable(argObj);
+				String name = argObj.getQualifiedName();
 				ICDIStackFrame stack = argObj.getStackFrame();
-				Session session = (Session)getSession();
+				Session session = (Session) getSession();
 				ICDIThread currentThread = null;
 				ICDIStackFrame currentFrame = null;
 				if (stack != null) {
@@ -239,14 +220,13 @@
 			}
 			return argument;
 		}
-		throw  new CDIException("Wrong variable type");
+		throw new CDIException("Wrong variable type");
 	}
 
 	/**
 	 * @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getArgumentObject(ICDIStackFrame, String)
 	 */
-	public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name)
-		throws CDIException {
+	public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name) throws CDIException {
 		ICDIArgumentObject[] argsObjects = getArgumentObjects(stack);
 		for (int i = 0; i < argsObjects.length; i++) {
 			if (argsObjects[i].getName().equals(name)) {
@@ -261,7 +241,7 @@
 	 */
 	public ICDIArgumentObject[] getArgumentObjects(ICDIStackFrame frame) throws CDIException {
 		List argObjects = new ArrayList();
-		Session session = (Session)getSession();
+		Session session = (Session) getSession();
 		ICDITarget currentTarget = session.getCurrentTarget();
 		ICDIThread currentThread = currentTarget.getCurrentThread();
 		ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame();
@@ -273,8 +253,7 @@
 			int level = frame.getLevel();
 			// Need the GDB/MI view of leve which the reverse i.e. Highest frame is 0
 			int miLevel = depth - level;
-			MIStackListArguments listArgs =
-			factory.createMIStackListArguments(false, miLevel, miLevel);
+			MIStackListArguments listArgs = factory.createMIStackListArguments(false, miLevel, miLevel);
 			MIArg[] args = null;
 			mi.postCommand(listArgs);
 			MIStackListArgumentsInfo info = listArgs.getMIStackListArgumentsInfo();
@@ -288,8 +267,7 @@
 			if (args != null) {
 				ICDITarget tgt = frame.getThread().getTarget();
 				for (int i = 0; i < args.length; i++) {
-					ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(),
-					 frame, args.length - i, level);
+					ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(), frame, args.length - i, level);
 					argObjects.add(arg);
 				}
 			}
@@ -298,7 +276,7 @@
 		} finally {
 			currentThread.setCurrentStackFrame(currentFrame);
 		}
-		return (ICDIArgumentObject[])argObjects.toArray(new ICDIArgumentObject[0]);
+		return (ICDIArgumentObject[]) argObjects.toArray(new ICDIArgumentObject[0]);
 	}
 
 	/**
@@ -342,51 +320,20 @@
 	/**
 	 * @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getVariableObjectAsArray(ICDIVariableObject, String, int, int)
 	 */
-	public ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject object, String type, int start, int length) throws CDIException {
+	public ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject object, String type, int start, int length)
+		throws CDIException {
 		VariableObject obj = null;
 		if (object instanceof VariableObject) {
-			obj = (VariableObject)object;
+			obj = (VariableObject) object;
 		}
 		if (obj != null) {
 			// Check if the type is valid.
-			if (type != null && type.length() > 0) {
-				try {
-					MISession mi = ((Session)getSession()).getMISession();
-					CommandFactory factory = mi.getCommandFactory();
-					MIPType ptype = factory.createMIPType(type);
-					mi.postCommand(ptype);
-					MIPTypeInfo info = ptype.getMIPtypeInfo();
-					if (info == null) {
-						throw new CDIException("No answer");
-					}
-				} catch (MIException e) {
-					throw new MI2CDIException(e);
-				}
-			}
-
-			// Should we provide a getRegisterObjectAsArray ?
-			StringBuffer buffer = new StringBuffer();
-			if (obj instanceof ICDIRegisterObject) {
-				buffer.append("$" + obj.getName());
-			} else {
-				buffer.append(obj.getName());
-			}
-			VariableObject vo = new VariableObject(obj, buffer.toString());
-
-			// Carry the the old casting type over
-			buffer.setLength(0);
-			if (obj.casting_type != null && obj.casting_type.length() > 0) {
-				buffer.append("(").append(obj.casting_type).append(")");
-			}
-			if (type != null && type.length() > 0) {
-				buffer.append(type);
-			}
-			vo.casting_type = buffer.toString();
-
-			// Carry any other info to the new VariableObject
-			vo.casting_index = obj.casting_index + start;
-			vo.casting_length = obj.casting_length + length;
-
+			checkType(type);
+			VariableObject vo = new VariableObject(obj.getTarget(),
+			 obj.getQualifiedName(), obj.getStackFrame(), obj.getPosition(), obj.getStackDepth());
+			vo.setCastingType(type);
+			vo.setCastingArrayStart(start);
+			vo.setCastingArrayEnd(length);
 			return vo;
 		}
 		throw new CDIException("Unknown variable object");
@@ -398,34 +345,20 @@
 	public ICDIVariableObject getVariableObjectAsType(ICDIVariableObject object, String type) throws CDIException {
 		VariableObject obj = null;
 		if (object instanceof VariableObject) {
-			obj = (VariableObject)object;
+			obj = (VariableObject) object;
 		}
 		if (obj != null) {
-			StringBuffer buffer = new StringBuffer();
-			if (type != null && type.length() > 0) {
-				// Check if the type is valid.
-				try {
-					MISession mi = ((Session)getSession()).getMISession();
-					CommandFactory factory = mi.getCommandFactory();
-					MIPType ptype = factory.createMIPType(type);
-					mi.postCommand(ptype);
-					MIPTypeInfo info = ptype.getMIPtypeInfo();
-					if (info == null) {
-						throw new CDIException("No answer");
-					}
-				} catch (MIException e) {
-					throw new MI2CDIException(e);
-				}
-				buffer.append('(').append(type).append(')');
-			}
-			buffer.append('(');
-			if (obj instanceof ICDIRegisterObject) {
-				buffer.append("$" + obj.getName());
-			} else {
-				buffer.append(obj.getName());
-			}
-			buffer.append(')');
-			return new VariableObject(obj, buffer.toString());
+			// throw an exception if not a good type.
+			checkType(type);
+			VariableObject vo =
+				new VariableObject(
+					obj.getTarget(),
+					obj.getQualifiedName(),
+					obj.getStackFrame(),
+					obj.getPosition(),
+					obj.getStackDepth());
+			vo.setCastingType(type);
+			return vo;
 		}
 		throw new CDIException("Unknown variable object");
 	}
@@ -435,7 +368,7 @@
 	 */
 	public ICDIVariableObject[] getLocalVariableObjects(ICDIStackFrame frame) throws CDIException {
 		List varObjects = new ArrayList();
-		Session session = (Session)getSession();
+		Session session = (Session) getSession();
 		ICDITarget currentTarget = session.getCurrentTarget();
 		ICDIThread currentThread = currentTarget.getCurrentThread();
 		ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame();
@@ -455,8 +388,7 @@
 			if (args != null) {
 				ICDITarget tgt = frame.getThread().getTarget();
 				for (int i = 0; i < args.length; i++) {
-					VariableObject varObj = new VariableObject(tgt, args[i].getName(),
-						 frame, args.length - i, level);
+					VariableObject varObj = new VariableObject(tgt, args[i].getName(), frame, args.length - i, level);
 					varObjects.add(varObj);
 				}
 			}
@@ -465,7 +397,7 @@
 		} finally {
 			currentThread.setCurrentStackFrame(currentFrame, false);
 		}
-		return (ICDIVariableObject[])varObjects.toArray(new ICDIVariableObject[0]);
+		return (ICDIVariableObject[]) varObjects.toArray(new ICDIVariableObject[0]);
 	}
 
 	/**
@@ -486,13 +418,13 @@
 	public ICDIVariable createVariable(ICDIVariableObject v) throws CDIException {
 		VariableObject varObj = null;
 		if (v instanceof VariableObject) {
-			varObj = (VariableObject)v;
+			varObj = (VariableObject) v;
 		}
 		if (varObj != null) {
 			Variable variable = findVariable(varObj);
 			if (variable == null) {
-				String name = encodeVariable(varObj);
-				Session session = (Session)getSession();
+				String name = varObj.getQualifiedName();
+				Session session = (Session) getSession();
 				ICDIStackFrame stack = varObj.getStackFrame();
 				ICDIThread currentThread = null;
 				ICDIStackFrame currentFrame = null;
@@ -532,9 +464,9 @@
 	public void destroyVariable(ICDIVariable var) throws CDIException {
 		if (var instanceof Variable) {
 			// Fire  a destroyEvent ?
-			Variable variable = (Variable)var;
+			Variable variable = (Variable) var;
 			MIVarDeletedEvent del = new MIVarDeletedEvent(variable.getMIVar().getVarName());
-			Session session = (Session)getSession();
+			Session session = (Session) getSession();
 			MISession mi = session.getMISession();
 			mi.fireEvent(del);
 		}
@@ -569,7 +501,7 @@
 		int high = 0;
 		int low = 0;
 		List eventList = new ArrayList();
-		Session session = (Session)getSession();
+		Session session = (Session) getSession();
 		MISession mi = session.getMISession();
 		CommandFactory factory = mi.getCommandFactory();
 		Variable[] vars = getVariables();
@@ -584,7 +516,7 @@
 					high = currentStack.getLevel();
 				}
 				if (high > 0) {
-						high--;
+					high--;
 				}
 				low = high - MAX_STACK_DEPTH;
 				if (low < 0) {
@@ -610,7 +542,7 @@
 					//throw new MI2CDIException(e);
 					eventList.add(new MIVarDeletedEvent(varName));
 				}
-				for (int j = 0 ; j < changes.length; j++) {
+				for (int j = 0; j < changes.length; j++) {
 					String n = changes[j].getVarName();
 					if (changes[j].isInScope()) {
 						eventList.add(new MIVarChangedEvent(n));
@@ -620,7 +552,7 @@
 				}
 			}
 		}
-		MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
+		MIEvent[] events = (MIEvent[]) eventList.toArray(new MIEvent[0]);
 		mi.fireEvents(events);
 	}
 
@@ -634,10 +566,11 @@
 	 * @param frames
 	 * @return
 	 */
-	boolean isVariableNeedsToBeUpdate(Variable variable, ICDIStackFrame current, ICDIStackFrame[] frames, int low) throws CDIException {
+	boolean isVariableNeedsToBeUpdate(Variable variable, ICDIStackFrame current, ICDIStackFrame[] frames, int low)
+		throws CDIException {
 		ICDIStackFrame varStack = variable.getStackFrame();
 		boolean inScope = false;
-		
+
 		// Something wrong and the program terminated bail out here.
 		if (current == null || frames == null) {
 			return false;
Index: src/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java,v
retrieving revision 1.17
diff -u -r1.17 Variable.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java	6 Aug 2003 21:14:17 -0000	1.17
+++ src/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java	7 Aug 2003 03:25:52 -0000
@@ -9,6 +9,8 @@
 import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
 import org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager;
 import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
+import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
+import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
 import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType;
@@ -50,12 +52,14 @@
 import org.eclipse.cdt.debug.mi.core.cdi.model.type.WCharValue;
 import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
 import org.eclipse.cdt.debug.mi.core.command.MIVarAssign;
+import org.eclipse.cdt.debug.mi.core.command.MIVarInfoExpression;
 import org.eclipse.cdt.debug.mi.core.command.MIVarListChildren;
 import org.eclipse.cdt.debug.mi.core.command.MIVarSetFormat;
 import org.eclipse.cdt.debug.mi.core.command.MIVarShowAttributes;
 import org.eclipse.cdt.debug.mi.core.event.MIVarChangedEvent;
 import org.eclipse.cdt.debug.mi.core.output.MIInfo;
 import org.eclipse.cdt.debug.mi.core.output.MIVar;
+import org.eclipse.cdt.debug.mi.core.output.MIVarInfoExpressionInfo;
 import org.eclipse.cdt.debug.mi.core.output.MIVarListChildrenInfo;
 import org.eclipse.cdt.debug.mi.core.output.MIVarShowAttributesInfo;
 
@@ -65,15 +69,20 @@
 
 	MIVar miVar;
 	Value value;
-	VariableObject varObj;
 	ICDIVariable[] children = new ICDIVariable[0];
 	Type type;
 	String editable = null;
+	String language;
+	boolean isFake = false;
 
 	public Variable(VariableObject obj, MIVar v) {
-		super(obj, obj.getName());
+		super(obj);
+		miVar = v;
+	}
+
+	public Variable(ICDITarget target, String n, String q, ICDIStackFrame stack, int pos, int depth, MIVar v) {
+		super(target, n, q, stack, pos, depth);
 		miVar = v;
-		varObj = obj;
 	}
 
 	public MIVar getMIVar() {
@@ -82,7 +91,7 @@
 
 	public Variable getChild(String name) {
 		for (int i = 0; i < children.length; i++) {
-			Variable variable = (Variable)children[i];
+			Variable variable = (Variable) children[i];
 			if (name.equals(variable.getMIVar().getVarName())) {
 				return variable;
 			} else {
@@ -96,6 +105,38 @@
 		return null;
 	}
 
+	String getLanguage() throws CDIException {
+		if (language == null) {
+			Session session = (Session) (getTarget().getSession());
+			MISession mi = session.getMISession();
+			CommandFactory factory = mi.getCommandFactory();
+			MIVarInfoExpression var = factory.createMIVarInfoExpression(getMIVar().getVarName());
+			try {
+				mi.postCommand(var);
+				MIVarInfoExpressionInfo info = var.getMIVarInfoExpressionInfo();
+				if (info == null) {
+					throw new CDIException("No answer");
+				}
+				language = info.getLanguage();
+			} catch (MIException e) {
+				throw new MI2CDIException(e);
+			}
+		}
+		return (language == null) ? "" : language;
+	}
+
+	boolean isCPPLanguage() throws CDIException {
+		return getLanguage().equalsIgnoreCase("C++");
+	}
+
+	void setIsFake(boolean f) {
+		isFake = f;
+	}
+
+	boolean isFake() {
+		return isFake;
+	}
+
 	public ICDIVariable[] getChildren() throws CDIException {
 		// Use the default timeout.
 		return getChildren(-1);
@@ -106,11 +147,10 @@
 	 * allow the override of the timeout.
 	 */
 	public ICDIVariable[] getChildren(int timeout) throws CDIException {
-		Session session = (Session)(getTarget().getSession());
+		Session session = (Session) (getTarget().getSession());
 		MISession mi = session.getMISession();
 		CommandFactory factory = mi.getCommandFactory();
-		MIVarListChildren var =
-			factory.createMIVarListChildren(getMIVar().getVarName());
+		MIVarListChildren var = factory.createMIVarListChildren(getMIVar().getVarName());
 		try {
 			if (timeout >= 0) {
 				mi.postCommand(var, timeout);
@@ -124,10 +164,53 @@
 			MIVar[] vars = info.getMIVars();
 			children = new Variable[vars.length];
 			for (int i = 0; i < vars.length; i++) {
-				VariableObject varObj = new VariableObject(getTarget(),
-				 vars[i].getExp(), getStackFrame(),
-				 getPosition(),getStackDepth());
-				children[i] = new Variable(varObj, vars[i]);
+				String qName = getQualifiedName();
+				String childTypename = null;
+				boolean childFake = false;
+				ICDIType t = getType();
+				if (t instanceof ICDIArrayType) {
+					qName = "(" + getQualifiedName() + ")[" + i + "]";
+				} else if (t instanceof ICDIPointerType) {
+					qName = "*(" + getQualifiedName() + ")";
+				} else if (t instanceof ICDIStructType) {
+					if (isCPPLanguage()) {
+						// For C++ in GDB the children of the
+						// the struture are the scope and the inherited classes.
+						// For example:
+						// class foo: public bar {
+						//   int x;
+						//   public: int y;
+						// } foobar;
+						// This will map to
+						// - foobar
+						//    + bar
+						//    - private
+						//       - x
+						//    - public
+						//       - y
+						// So we choose to ignore the first set of children
+						// but carry over to those "fake" variable the typename and the qualified name
+						if (isFake()) {
+							qName = "(" + getQualifiedName() + ")." + vars[i].getExp();
+						} else {
+							// So if the child is something like "public", "private" ...
+							// carrry over the parent qualified name and the typename
+							// also flag it as a fake variable.
+							qName = getQualifiedName();
+							childTypename = typename;
+							childFake = true;
+						}
+					} else {
+						qName = "(" + getQualifiedName() + ")." + vars[i].getExp();
+					}
+				}
+				Variable v = new Variable(getTarget(), vars[i].getExp(), qName, getStackFrame(), getPosition(), getStackDepth(), vars[i]);
+				if (childTypename != null) {
+					// Hack to reset the typename to a known value
+					v.typename = childTypename;
+				}
+				v.setIsFake(childFake);
+				children[i] = v;
 			}
 		} catch (MIException e) {
 			throw new MI2CDIException(e);
@@ -147,7 +230,10 @@
 	 */
 	public String getTypeName() throws CDIException {
 		// We overload here not to use the whatis command.
-		return miVar.getType();
+		if (typename == null) {
+			typename = miVar.getType();
+		}
+		return typename;
 	}
 
 	/**
@@ -185,7 +271,7 @@
 			} else if (t instanceof ICDIArrayType) {
 				value = new ArrayValue(this);
 			} else if (t instanceof ICDIStructType) {
-				value = new StructValue(this);	
+				value = new StructValue(this);
 			} else {
 				value = new Value(this);
 			}
@@ -204,7 +290,7 @@
 	 * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(String)
 	 */
 	public void setValue(String expression) throws CDIException {
-		Session session = (Session)(getTarget().getSession());
+		Session session = (Session) (getTarget().getSession());
 		MISession mi = session.getMISession();
 		CommandFactory factory = mi.getCommandFactory();
 		MIVarAssign var = factory.createMIVarAssign(miVar.getVarName(), expression);
@@ -226,20 +312,20 @@
 		// Changing values may have side effects i.e. affecting other variables
 		// if the manager is on autoupdate check all the other variables.
 		// Note: This maybe very costly.
-		if (this instanceof Register) {		
+		if (this instanceof Register) {
 			// If register was on autoupdate, update all the other registers
 			// assigning may have side effects i.e. affecting other registers.
 			ICDIRegisterManager mgr = session.getRegisterManager();
 			if (mgr.isAutoUpdate()) {
 				mgr.update();
-			}	
+			}
 		} else if (this instanceof Expression) {
 			// If expression was on autoupdate, update all the other expression
 			// assigning may have side effects i.e. affecting other expressions.
 			ICDIExpressionManager mgr = session.getExpressionManager();
 			if (mgr.isAutoUpdate()) {
 				mgr.update();
-			}	
+			}
 		} else {
 			// FIXME: Should we always call the Variable Manager ?
 			ICDIVariableManager mgr = session.getVariableManager();
@@ -256,7 +342,7 @@
 	 */
 	public boolean isEditable() throws CDIException {
 		if (editable == null) {
-			MISession mi = ((Session)(getTarget().getSession())).getMISession();
+			MISession mi = ((Session) (getTarget().getSession())).getMISession();
 			CommandFactory factory = mi.getCommandFactory();
 			MIVarShowAttributes var = factory.createMIVarShowAttributes(miVar.getVarName());
 			try {
@@ -278,7 +364,7 @@
 	 */
 	public void setFormat(int format) throws CDIException {
 		int fmt = Format.toMIFormat(format);
-		MISession mi = ((Session)(getTarget().getSession())).getMISession();
+		MISession mi = ((Session) (getTarget().getSession())).getMISession();
 		CommandFactory factory = mi.getCommandFactory();
 		MIVarSetFormat var = factory.createMIVarSetFormat(miVar.getVarName(), fmt);
 		try {
@@ -297,7 +383,7 @@
 	 */
 	public boolean equals(ICDIVariable var) {
 		if (var instanceof Variable) {
-			Variable variable = (Variable)var;
+			Variable variable = (Variable) var;
 			return miVar.getVarName().equals(variable.getMIVar().getVarName());
 		}
 		return super.equals(var);
Index: src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java,v
retrieving revision 1.7
diff -u -r1.7 VariableObject.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java	6 Aug 2003 21:14:06 -0000	1.7
+++ src/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java	7 Aug 2003 03:25:52 -0000
@@ -32,33 +32,56 @@
 public class VariableObject extends CObject implements ICDIVariableObject {
 
 	// Casting info.
-	public String casting_type;
-	public int casting_index;
-	public int casting_length;
-
-	Type type = null;
-	String typename = null;
-	String sizeof = null;
+	String castingType;
+	int castingIndex;
+	int castingLength;
 
 	String name;
 	int position;
 	ICDIStackFrame frame;
 	int stackdepth;
+	
+	String qualifiedName = null;
+	Type type = null;
+	String typename = null;
+	String sizeof = null;
 
-	public VariableObject(VariableObject obj, String n) {
+	/**
+	 * Copy constructor.
+	 * @param obj
+	 */
+	public VariableObject(VariableObject obj) {
 		super(obj.getTarget());
-		name = n;
+		name = obj.getName();
 		try {
 			frame = obj.getStackFrame();
 		} catch (CDIException e) {
 		}
 		position = obj.getPosition();
 		stackdepth = obj.getStackDepth();
-	}
+		castingIndex = obj.getCastingArrayStart();
+		castingLength = obj.getCastingArrayEnd();
+		castingType = obj.getCastingType();
+	}
+//	public VariableObject(VariableObject obj, String n) {
+//		super(obj.getTarget());
+//		name = n;
+//		try {
+//			frame = obj.getStackFrame();
+//		} catch (CDIException e) {
+//		}
+//		position = obj.getPosition();
+//		stackdepth = obj.getStackDepth();
+//	}
 
 	public VariableObject(ICDITarget target, String n, ICDIStackFrame stack, int pos, int depth) {
+		this(target, n, null, stack, pos, depth);
+	}
+
+	public VariableObject(ICDITarget target, String n, String q, ICDIStackFrame stack, int pos, int depth) {
 		super(target);
 		name = n;
+		qualifiedName = q;
 		frame = stack;
 		position = pos;
 		stackdepth = depth;
@@ -72,6 +95,57 @@
 		return stackdepth;
 	}
 
+	public void setCastingArrayStart(int start) {
+		castingIndex = start;
+	}
+	public int getCastingArrayStart() {
+		return castingIndex;
+	}
+
+	public void setCastingArrayEnd(int end) {
+		castingLength = end;
+	}
+	public int getCastingArrayEnd() {
+		return castingLength;
+	}
+
+	public void setCastingType(String t) {
+		castingType = t;
+	}
+	public String getCastingType() {
+		return castingType;
+	}
+	
+	/**
+	 * If the variable was a cast encode the string appropriately for GDB.
+	 * For example castin to an array is of 2 elements:
+	 *  (foo)@2
+	 * @return
+	 */
+	public String encodeVariable() {
+		StringBuffer buffer = new StringBuffer();
+		if (castingLength > 0 || castingIndex > 0) {
+			buffer.append("(");
+			//buffer.append('(');
+			if (castingType != null && castingType.length() > 0) {
+				buffer.append('(').append(castingType).append(')');
+			}
+			buffer.append(getName());
+			//buffer.append(')');
+			if (castingIndex != 0) {
+					buffer.append('+').append(castingIndex);
+			}
+			buffer.append(')');
+			buffer.append('@').append(castingLength - castingIndex);
+		} else if (castingType != null && castingType.length() > 0) {
+			buffer.append('(').append(castingType).append(')');
+			buffer.append('(').append(getName()).append(')');
+		} else {
+			buffer.append(getName());
+		}
+		return buffer.toString();
+	}
+
 	/**
 	 * @see org.eclipse.cdt.debug.core.cdi.ICDIVariableObject#getName()
 	 */
@@ -182,5 +256,16 @@
 		}
 		return typename;
 	}
+
+	/**
+	 * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getQualifiedName()
+	 */
+	public String getQualifiedName() throws CDIException {
+		if (qualifiedName == null) {
+			qualifiedName = encodeVariable();
+		}
+		return qualifiedName;
+	}
+
 
 }
Index: src/org/eclipse/cdt/debug/mi/core/command/MIVarInfoExpression.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIVarInfoExpression.java,v
retrieving revision 1.1
diff -u -r1.1 MIVarInfoExpression.java
--- src/org/eclipse/cdt/debug/mi/core/command/MIVarInfoExpression.java	30 Jul 2002 20:58:29 -0000	1.1
+++ src/org/eclipse/cdt/debug/mi/core/command/MIVarInfoExpression.java	7 Aug 2003 03:25:52 -0000
@@ -6,6 +6,11 @@
 
 package org.eclipse.cdt.debug.mi.core.command;
 
+import org.eclipse.cdt.debug.mi.core.MIException;
+import org.eclipse.cdt.debug.mi.core.output.MIInfo;
+import org.eclipse.cdt.debug.mi.core.output.MIOutput;
+import org.eclipse.cdt.debug.mi.core.output.MIVarInfoExpressionInfo;
+
 /**
  * 
  *     -var-info-expression NAME
@@ -22,4 +27,21 @@
 	public MIVarInfoExpression(String name) {
 		super("-var-info-expression", new String[]{name});
 	}
+	
+	public MIVarInfoExpressionInfo getMIVarInfoExpressionInfo() throws MIException {
+		return (MIVarInfoExpressionInfo)getMIInfo();
+	}
+
+	public MIInfo getMIInfo() throws MIException {
+		MIInfo info = null;
+		MIOutput out = getMIOutput();
+		if (out != null) {
+			info = new MIVarInfoExpressionInfo(out);
+			if (info.isError()) {
+				throwMIException(info, out);
+			}
+		}
+		return info;
+	}
+
 }



Back to the top