Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Proposed CDT 1.2 patches 1/3

CDT 1-2 patch: 1/3

1. If the stack-info-depth command on one of the threads returns an error,
   CDT does not display the stack trace for that thread.  This behavior is
   different from command line gdb, where gdb displays all the frames that it
   can, and then prints an error message.

   The proposed patch is to retry the stack-info-depth command- which
   generally succeeds because gdb patches the offending stack frame- and then
   display the results.

Ashish.

#!/bin/bash
--- ./precious/old/Thread.java	2003-10-22 19:40:41.000000000 -0400
+++ ./precious/new/Thread.java	2003-10-22 19:40:41.000000000 -0400
@@ -1,4 +1,4 @@
-/*
+ /*
  * (c) Copyright QNX Software Systems Ltd. 2002.
  * All Rights Reserved.
  *
@@ -12,6 +12,7 @@
 import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
 import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
 import org.eclipse.cdt.debug.mi.core.MIException;
+import org.eclipse.cdt.debug.mi.core.MIPlugin;
 import org.eclipse.cdt.debug.mi.core.MISession;
 import org.eclipse.cdt.debug.mi.core.cdi.MI2CDIException;
 import org.eclipse.cdt.debug.mi.core.cdi.RegisterManager;
@@ -28,7 +29,7 @@

 /**
  */
-public class Thread extends CObject implements ICDIThread {
+public class  Thread extends CObject implements ICDIThread {

 	static ICDIStackFrame[] noStack = new ICDIStackFrame[0];
 	int id;
@@ -111,6 +112,7 @@
 	 * @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames()
 	 */
 	public int getStackFrameCount() throws CDIException {
+		
 		if (stackdepth == 0) {
 			Session session = (Session)(getTarget().getSession());
 			Target currentTarget = (Target)session.getCurrentTarget();
@@ -127,8 +129,32 @@
 				}
 				stackdepth = info.getDepth();
 			} catch (MIException e) {
+				try {
+					//First exception, retry. gdb patches up the corrupt frame
+					//so retry should give us a frame count that is safe.
+					MIPlugin.getDefault().debugLog(e.toString());
+					MISession mi = session.getMISession();
+					CommandFactory factory = mi.getCommandFactory();
+					MIStackInfoDepth depth = factory.createMIStackInfoDepth();
+					mi.postCommand(depth);
+					MIStackInfoDepthInfo info = depth.getMIStackInfoDepthInfo();
+					if (info == null) {
+						throw new CDIException("No answer");
+					}
+					stackdepth = info.getDepth();
+ // Set frame count to one less frame than the count that would cause an exception + // REVISIT: if we don't keep changing the thread back to the currentThread in the + // finally clause below, decrementing the frame count would not be necessary here.
+					if (stackdepth > 0)
+						stackdepth--;
+				} catch (MIException e1) {
+					// Second  exception, now throw it.
+					e1.printStackTrace();
+				
+				
 				throw new MI2CDIException(e);
 				//System.out.println(e);
+				}
 			} finally {
 				currentTarget.setCurrentThread(currentThread, false);
 			}



Back to the top