Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Bug-fix: Variable wrong when doing recursive and watchpoint fixes.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.47
diff -u -r1.47 ChangeLog
--- ChangeLog	17 Dec 2002 18:57:29 -0000	1.47
+++ ChangeLog	2 Jan 2003 21:42:59 -0000
@@ -1,3 +1,37 @@
+2003-01-02 Alain Magloire
+
+	Bug when using recursive:
+	int recursive(int x) {
+		if (x > 10)
+			recursive(++x);
+		return 0;
+	}
+	
+	The Variable Manager is caching the MI/GDB var-obj for speed.
+	It is finding the object by looking at the name and the stack/thread,
+	for recursive calls, this is wrong and the code would be full in
+	thinking the variable "x"(see above) is the same object.  To make the distinction
+	we use the depth "-stack-info-depth" that will be use also in the equality
+	to make sure we identify an object uniquely.  In the recursive() case above
+	because the depth is different, a new "x" object will be created.  The downside
+	is that on certain platform doing deep recursive/stackframe, we have noticed
+	that "-stack-info-depth" can be very long, test done for gdb/QNX with
+	a stack depth of 1000.
+
+	* src/.../mi/core/cdi/VariableManager.java (getElement):
+	Use the depth when doing equal().
+	(createElement): Save the depth of the stack part of the Element.
+
+2003-01-02 Alain Magloire
+
+	GDB/MI uses some oob reasons that was not documented for the watchpoints
+		*stopped,reason="access-watchpoint-trigger"...
+		*stopped,reason="read-watchpoint-trigger",...
+	* src/.../mi/core/event/MIWatchpointTrigger.java (parse):
+	check for "hw-awpt" and "hw-rwpt".
+	* src/.../mi/core/RxThread.java (createEvents):
+	Check for "access-watchpoint-trigger", "read-watchpoint-trigger.
+
 2002-12-17 Alain Magloire
 
 	* src/.../mi/core/cdi/Register.java (setFormat): bug fix
Index: src/org/eclipse/cdt/debug/mi/core/RxThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java,v
retrieving revision 1.40
diff -u -r1.40 RxThread.java
--- src/org/eclipse/cdt/debug/mi/core/RxThread.java	5 Dec 2002 16:01:10 -0000	1.40
+++ src/org/eclipse/cdt/debug/mi/core/RxThread.java	2 Jan 2003 21:42:59 -0000
@@ -329,7 +329,9 @@
 				event = new MIBreakpointEvent(rr);
 			}
 			session.getMIInferior().setSuspended();
-		} else if ("watchpoint-trigger".equals(reason)) {
+		} else if ("watchpoint-trigger".equals(reason) ||
+		           "read-watchpoint-trigger".equals(reason) ||
+		           "access-watchpoint-trigger".equals(reason)) {
 			if (exec != null) {
 				event = new MIWatchpointTriggerEvent(exec);
 			} else if (rr != null) {
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.11
diff -u -r1.11 VariableManager.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java	5 Dec 2002 15:59:55 -0000	1.11
+++ src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java	2 Jan 2003 21:43:00 -0000
@@ -40,6 +40,7 @@
 		MIVar miVar;
 		String name;
 		StackFrame stackframe;
+		int stackdepth;
 		Variable variable;
 	}
 
@@ -49,6 +50,9 @@
 		oosList = new ArrayList();
 	}
 
+	/**
+	 * Return the element that have the uniq varName.
+	 */
 	Element getElement(String varName) {
 		Element[] elements = getElements();
 		for (int i = 0; i < elements.length; i++) {
@@ -59,12 +63,26 @@
 		return null;
 	}
 
+	/**
+	 * Return the Element with that stackframe, stack, that with this name.
+	 * null is return if the element is not in the cache.
+	 */
 	Element getElement(StackFrame stack, String name) {
 		Element[] elements = getElements();
 		for (int i = 0; i < elements.length; i++) {
 			if (elements[i].name.equals(name)) {
 				if (elements[i].stackframe.equals(stack)) {
-					return elements[i];
+					int depth = 0;
+					CThread thread = stack.getCThread();
+					if (thread != null) {
+						try {
+							depth = thread.getStackFrameCount();
+						} catch (CDIException e) {
+						}
+					}
+					if (elements[i].stackdepth == depth) {
+						return elements[i];
+					}
 				}
 			}
 		}
@@ -85,10 +103,19 @@
 		elementList.add(element);
 	}
 
+	/**
+	 * Returns all the elements that are in the cache.
+	 */
 	Element[] getElements() {
 		return (Element[]) elementList.toArray(new Element[0]);
 	}
 
+	/**
+	 * Update the elements in the cache, from the response of the "-var-update *"
+	 * mi/command.  Out-of-scope elements are removed etc ..
+	 * Expression are special they are not remove when out-of-scope is thrown.
+	 * For all remove element in the cache fires a destroy event.
+	 */
 	void update() throws CDIException {
 		MISession mi = getCSession().getMISession();
 		CommandFactory factory = mi.getCommandFactory();
@@ -121,6 +148,10 @@
 		}
 	}
 
+	/**
+	 * If element is not in the cache create a new element "-var-create"
+	 * for the stackframe(stack).
+	 */
 	Element createElement(StackFrame stack, String name) throws CDIException {
 		Element element = getElement(stack, name);
 		if (element == null) {
@@ -138,6 +169,10 @@
 				element.miVar = info.getMIVar();
 				element.name = name;
 				element.stackframe = stack;
+				CThread thread = stack.getCThread();
+				if (thread != null) {
+					element.stackdepth = thread.getStackFrameCount();
+				}
 			} catch (MIException e) {
 				throw new MI2CDIException(e);
 			}
@@ -145,6 +180,9 @@
 		return element;
 	}
 
+	/**
+	 * Remove element from the OutOfscope list(oos).
+	 */
 	Element removeOutOfScope(String varName) {
 		Element[] oos = (Element[])oosList.toArray(new Element[0]);
 		for (int i = 0; i < oos.length; i++) {
@@ -155,6 +193,9 @@
 		return null;
 	}
 
+	/**
+	 * Tell gdb to remove the underlying var-object also.
+	 */
 	void removeMIVar(MIVar miVar) throws CDIException {
 		MISession mi = getCSession().getMISession();
 		CommandFactory factory = mi.getCommandFactory();
@@ -167,6 +208,11 @@
 		}
 	}
 
+	/**
+	 * When element are remove from the cache, they are put on the OutOfScope list, oos,
+	 * because they are still needed for the destroy events.  The destroy event will
+	 * call removeOutOfScope.
+	 */
 	void removeElement(String varName) throws CDIException {
 		Element[] elements = getElements();
 		for (int i = 0; i < elements.length; i++) {
@@ -178,16 +224,25 @@
 		}
 	}
 
+	/**
+	 * Finds the variable Uniq name and call removeElement().
+	 */
 	void removeElement(MIVarChange changed) throws CDIException {
 		String varName = changed.getVarName();
 		removeElement(varName);
 	}
 
+	/**
+	 * Remove the Element.
+	 */
 	void removeElement(Variable variable) throws CDIException {
 		String varName = ((Variable)variable).getMIVar().getVarName();
 		removeElement(varName);
 	}
 
+	/**
+	 * Remove the elements.
+	 */
 	void removeElements(Variable[] variables) throws CDIException {
 		for (int i = 0; i < variables.length; i++) {
 			removeElement(variables[i]);
@@ -218,7 +273,6 @@
 		addElement(element);
 		return var;
 	}
-
 
 	ICDIArgument createArgument(StackFrame stack, String name) throws CDIException {
 		Element element = createElement(stack, name);
Index: src/org/eclipse/cdt/debug/mi/core/event/MIWatchpointTriggerEvent.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIWatchpointTriggerEvent.java,v
retrieving revision 1.3
diff -u -r1.3 MIWatchpointTriggerEvent.java
--- src/org/eclipse/cdt/debug/mi/core/event/MIWatchpointTriggerEvent.java	29 Nov 2002 18:53:38 -0000	1.3
+++ src/org/eclipse/cdt/debug/mi/core/event/MIWatchpointTriggerEvent.java	2 Jan 2003 21:43:00 -0000
@@ -80,7 +80,7 @@
 				String var = results[i].getVariable();
 				MIValue value = results[i].getMIValue();
 
-				if (var.equals("wpt")) {
+				if (var.equals("wpt") || var.equals("hw-awpt") || var.equals("hw-rwpt")) {
 					if (value instanceof MITuple) {
 						parseWPT((MITuple) value);
 					}
@@ -143,6 +143,8 @@
 				oldValue = str;
 			} else if (var.equals("new")) {
 				newValue = str;
+			} else if (var.equals("value")) {
+				oldValue = newValue = str;
 			}
 		}
 	}



Back to the top