Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Bug fix to suspend gdb inferior.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.123
diff -u -r1.123 ChangeLog
--- ChangeLog	23 Apr 2003 17:09:43 -0000	1.123
+++ ChangeLog	24 Apr 2003 15:17:22 -0000
@@ -1,3 +1,19 @@
+2003-04-24 Alain Magloire
+
+	* src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java (createMIInfoProgram):
+	New method.
+	* src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java:
+	New file, "info program".
+	* src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java:
+	New file, parsing of "info Program".
+	* src/org/eclipse/cdt/debug/mi/core/output/EventManager.java (processSuspend):
+	Call MIInferio.update();
+	* src/org/eclipse/cdt/debug/mi/core/MIInferior.java (update):
+	New method to retrieve the pid.
+	(interrupt): Try doing Spawner.raise(pid, INT) as a fallback.
+	* src/org/eclipse/cdt/debug/mi/core/cdi/Configuration.java (supportSuspend):
+	Bug fix.	
+
 2003-04-23 Alain Magloire
 
 	* src/org/eclipse/cdt/debug/mi/core/cdi/SignalManager.java (update):
Index: src/org/eclipse/cdt/debug/mi/core/MIInferior.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIInferior.java,v
retrieving revision 1.27
diff -u -r1.27 MIInferior.java
--- src/org/eclipse/cdt/debug/mi/core/MIInferior.java	22 Apr 2003 21:15:57 -0000	1.27
+++ src/org/eclipse/cdt/debug/mi/core/MIInferior.java	24 Apr 2003 15:17:22 -0000
@@ -14,8 +14,10 @@
 import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
 import org.eclipse.cdt.debug.mi.core.command.MIExecAbort;
 import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode;
+import org.eclipse.cdt.debug.mi.core.command.MIInfoProgram;
 import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent;
 import org.eclipse.cdt.debug.mi.core.output.MIGDBShowExitCodeInfo;
+import org.eclipse.cdt.debug.mi.core.output.MIInfoProgramInfo;
 import org.eclipse.cdt.utils.pty.PTY;
 import org.eclipse.cdt.utils.spawner.Spawner;
 
@@ -43,6 +45,9 @@
 	PipedOutputStream errPiped;
 	PTY pty;
 
+	int inferiorPid;
+
+
 	MIInferior(MISession mi, PTY p) {
 		session = mi;
 		pty = p;
@@ -182,7 +187,17 @@
 			// Allow (5 secs) for the interrupt to propagate.
 			for (int i = 0; isRunning() && i < 5; i++) {
 				try {
-					java.lang.Thread.sleep(2000);
+					java.lang.Thread.sleep(1000);
+				} catch (InterruptedException e) {
+				}
+			}
+			if (isRunning() && inferiorPid != 0) {
+				// lets try something else.
+				gdbSpawner.raise(inferiorPid, gdbSpawner.INT);
+			}
+			for (int i = 0; isRunning() && i < 5; i++) {
+				try {
+					java.lang.Thread.sleep(1000);
 				} catch (InterruptedException e) {
 				}
 			}
@@ -291,5 +306,20 @@
 
 	public PTY getPTY() {
 		return pty;
+	}
+
+	public void update() {
+		if (inferiorPid == 0) {
+			// Try to discover the pid
+			CommandFactory factory = session.getCommandFactory();
+			MIInfoProgram prog = factory.createMIInfoProgram();
+			try {
+				session.postCommand(prog);
+				MIInfoProgramInfo info = prog.getMIInfoProgramInfo();
+				inferiorPid = info.getPID();
+			} catch (MIException e) {
+				// no rethrown.
+			}
+		}
 	}
 }
Index: src/org/eclipse/cdt/debug/mi/core/cdi/Configuration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Configuration.java,v
retrieving revision 1.9
diff -u -r1.9 Configuration.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/Configuration.java	23 Jan 2003 20:00:36 -0000	1.9
+++ src/org/eclipse/cdt/debug/mi/core/cdi/Configuration.java	24 Apr 2003 15:17:22 -0000
@@ -122,23 +122,25 @@
 		}
 		Process gdb = miSession.getGDBProcess();
 		if (gdb instanceof Spawner) {
-			// If we attached sending a control-c, seems to work.
+			// If we attached sending a control-c,
+			// seems to alays work.
 			if (fAttached) {
 				return true;
 			}
 
 			// If we have a pty, sending a control-c will work
 			// except for solaris.
-			MIInferior inferior = miSession.getMIInferior();
-			if (inferior.getPTY() != null) {
-				// FIXME: bug in Solaris gdb when using -tty, sending a control-c
-				// does not work.
-				if (os.equals("SunOS")) {
+			if (os.equals("SunOS")) {
+				MIInferior inferior = miSession.getMIInferior();
+				if (inferior.getPTY() != null) {
+					// FIXME: bug in Solaris gdb when using -tty, sending a control-c
+					// does not work.
 					return false;
 				} else {
 					return true;
 				}
 			}
+			return true;
 		}
 		return false;
 	}
Index: src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java,v
retrieving revision 1.38
diff -u -r1.38 EventManager.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java	12 Feb 2003 05:26:03 -0000	1.38
+++ src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java	24 Apr 2003 15:17:22 -0000
@@ -24,6 +24,7 @@
 import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
 import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener;
 import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
+import org.eclipse.cdt.debug.mi.core.MISession;
 import org.eclipse.cdt.debug.mi.core.cdi.event.ChangedEvent;
 import org.eclipse.cdt.debug.mi.core.cdi.event.CreatedEvent;
 import org.eclipse.cdt.debug.mi.core.cdi.event.DestroyedEvent;
@@ -281,6 +282,9 @@
 			if (srcMgr.isAutoUpdate()) {
 				srcMgr.update();
 			}
+			// give a chance also to the underlying inferior.
+			MISession mi = session.getMISession();
+			mi.getMIInferior().update();
 		} catch (CDIException e) {
 			//System.out.println(e);
 		}
Index: src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java,v
retrieving revision 1.23
diff -u -r1.23 CommandFactory.java
--- src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java	4 Feb 2003 19:14:17 -0000	1.23
+++ src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java	24 Apr 2003 15:17:23 -0000
@@ -293,6 +293,10 @@
 		return new MIPType(name);
 	}
 
+	public MIInfoProgram createMIInfoProgram() {
+		return new MIInfoProgram();
+	}
+
 	public MIVarCreate createMIVarCreate(String expression) {
 		return new MIVarCreate(expression);
 	}
Index: src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java
diff -N src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java	24 Apr 2003 15:17:23 -0000
@@ -0,0 +1,40 @@
+/*
+ *(c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ * 
+ */
+
+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.MIInfoProgramInfo;
+import org.eclipse.cdt.debug.mi.core.output.MIOutput;
+
+/**
+ * 
+ *    info threads
+ *
+ */
+public class MIInfoProgram extends CLICommand 
+{
+	public MIInfoProgram() {
+		super("info program");
+	}
+
+	public MIInfoProgramInfo getMIInfoProgramInfo() throws MIException {
+		return (MIInfoProgramInfo)getMIInfo();
+	}
+
+	public MIInfo getMIInfo() throws MIException {
+		MIInfo info = null;
+		MIOutput out = getMIOutput();
+		if (out != null) {
+			info = new MIInfoProgramInfo(out);
+			if (info.isError()) {
+				throw new MIException(info.getErrorMsg());
+			}
+		}
+		return info;
+	}
+}
Index: src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java
diff -N src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java	24 Apr 2003 15:17:23 -0000
@@ -0,0 +1,70 @@
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.debug.mi.core.output;
+
+import java.util.StringTokenizer;
+
+
+/**
+ * GDB/MI info program parsing.
+(gdb) 
+info program
+&"info program\n"
+~"\tUsing the running image of child process 21301.\n"
+~"Program stopped at 0x804853f.\n"
+~"It stopped at breakpoint 1.\n"
+~"Type \"info stack\" or \"info registers\" for more information.\n"
+^done
+(gdb) 
+
+ */
+public class MIInfoProgramInfo extends MIInfo {
+
+	int pid;
+
+	public MIInfoProgramInfo(MIOutput out) {
+		super(out);
+		parse();
+	}
+
+	public int getPID() {
+		return pid;
+	}
+
+	void parse() {
+		if (isDone()) {
+			MIOutput out = getMIOutput();
+			MIOOBRecord[] oobs = out.getMIOOBRecords();
+			for (int i = 0; i < oobs.length; i++) {
+				if (oobs[i] instanceof MIConsoleStreamOutput) {
+					MIStreamRecord cons = (MIStreamRecord) oobs[i];
+					String str = cons.getString();
+					// We are interested in the signal info
+					parseLine(str);
+				}
+			}
+		}
+	}
+
+	void parseLine(String str) {
+		if (str != null && str.length() > 0) {
+			str = str.replace('.', ' ');
+			str = str.trim();
+			if (str.startsWith("Using")) {
+				StringTokenizer st = new StringTokenizer(str);
+				while (st.hasMoreTokens()) {
+					String s = st.nextToken();
+					if (Character.isDigit(s.charAt(0))) {
+						try {
+							pid = Integer.decode(s).intValue();
+							break;
+						} catch (NumberFormatException e) {
+						}
+					}
+				}
+			}
+		}
+	}
+}



Back to the top