Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Code to deal when gdb coredumps

 	There are some serious problems with gdb/mi, for example
 	the most recurrent one is when using -data-disassemble
 	in a threaded program, GNU/Linux uses a thread manager,
 	when trying to access the stackframe, gdb usually coredumps
 	with an assert, it goes something like this:
 -data-disassemble -f manager.c -l 136 -n 100 0
 &"Cannot access memory at address 0x4002d794\n"
 ^error,msg="Cannot access memory at address 0x4002d794"
 (gdb) 
 -data-disassemble -s 0x4002d900 -e 0x4002d964 0
 &"Cannot access memory at address 0x4002d900\n"
 ^error,msg="Cannot access memory at address 0x4002d900"
 (gdb) 
 -thread-select 2
 &"ui-out.c:133: gdb-internal-error: push_level: Assertion `uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS' failed.\n"
 
 	The RxThread will spawn a thread to terminate the session
 	and clear the receiving queue.
 
 

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.6
diff -u -r1.6 ChangeLog
--- ChangeLog	13 Oct 2002 01:59:14 -0000	1.6
+++ ChangeLog	13 Oct 2002 02:25:49 -0000
@@ -1,5 +1,47 @@
 2002-10-12 Alain Magloire
 
+	There are some serious problems with gdb/mi, for example
+	the most recurrent one is when using -data-disassemble
+	in a threaded program, GNU/Linux uses a thread manager
+	when trying to access the stackframe, gdb usually coredumps
+	with an assert, it goes something like this:
+	54 0-data-disassemble -f manager.c -l 136 -n 100 0
+
+&"Cannot access memory at address 0x4002d794\n"
+^error,msg="Cannot access memory at address 0x4002d794"
+(gdb) 
+-data-disassemble -s 0x4002d900 -e 0x4002d964 0
+&"Cannot access memory at address 0x4002d900\n"
+^error,msg="Cannot access memory at address 0x4002d900"
+(gdb) 
+-thread-select 2
+&"ui-out.c:133: gdb-internal-error: push_level: Assertion `uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS' failed.\n"
+
+	The RxThread will spawn a thread to terminate the session
+	and clear the receiving queue.
+
+
+	* RxThread.java (run): When the thread is being cancel() or
+	running out of run(), clear the receiving queue(rxQueue) and
+	notify any commands waiting.
+
+	* TxTread.java (run): Before putting the command in the
+	receiving queue(rxQueue) check to see if the thread is
+	still running.
+	When the thread is being cancel() or running out of run(),
+	clear the transmition queue(txQueue) an notify any commands
+	waiting.
+
+	* Queue.java (clearItems): New method that clear the items
+	on the queue and returning them.
+
+	* CommandQueue.java (clearCommands): New method calls super.clearItems()
+	whith the appropriate castings.
+
+	* cdi/CThread.java (setCurrentStackFrame): Check for null.
+
+2002-10-12 Alain Magloire
+
 	The memory block is implemented with
 	-data-read-memory (MIDataReadMemory)
 	Since the ICDIMemoryBlock only have
@@ -60,4 +102,4 @@
 
 2002-10-10 Alain Magloire
 
-	* SourceManager.java:  Implement getInstructions().
\ No newline at end of file
+	* SourceManager.java:  Implement getInstructions().
Index: src/org/eclipse/cdt/debug/mi/core/CommandQueue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CommandQueue.java,v
retrieving revision 1.2
diff -u -r1.2 CommandQueue.java
--- src/org/eclipse/cdt/debug/mi/core/CommandQueue.java	9 Oct 2002 14:08:42 -0000	1.2
+++ src/org/eclipse/cdt/debug/mi/core/CommandQueue.java	13 Oct 2002 02:25:52 -0000
@@ -9,7 +9,7 @@
 /**
  * Simple thread-safe Queue implemetation.
  */
-public class CommandQueue extends Queue{
+public class CommandQueue extends Queue {
 
 
 	public CommandQueue() {
@@ -40,6 +40,13 @@
 	public void addCommand(Command cmd) {
 		//print("in addCommand() - entering");
 		addItem(cmd);
+	}
+
+	public Command[] clearCommands() {
+		Object[] objs = clearItems();
+		Command[] cmds = new Command[objs.length];
+		System.arraycopy(objs, 0, cmds, 0, objs.length);
+		return cmds;
 	}
 
 	private static void print(String msg) {
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.21
diff -u -r1.21 MIInferior.java
--- src/org/eclipse/cdt/debug/mi/core/MIInferior.java	9 Oct 2002 14:08:42 -0000	1.21
+++ src/org/eclipse/cdt/debug/mi/core/MIInferior.java	13 Oct 2002 02:25:52 -0000
@@ -70,6 +70,7 @@
 				public void flush() throws IOException {
 					CLICommand cmd = new CLICommand(buf.toString()) {
 						public void setToken(int token) {
+							token = token;
 							// override to do nothing;
 						}
 					};
Index: src/org/eclipse/cdt/debug/mi/core/Queue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/Queue.java,v
retrieving revision 1.4
diff -u -r1.4 Queue.java
--- src/org/eclipse/cdt/debug/mi/core/Queue.java	15 Aug 2002 05:58:08 -0000	1.4
+++ src/org/eclipse/cdt/debug/mi/core/Queue.java	13 Oct 2002 02:25:52 -0000
@@ -35,6 +35,7 @@
 			return item;
 		}
 	}
+
 	public void addItem(Object item) {
 		//print("in addItem() - entering");
 		synchronized (list) {
@@ -49,6 +50,15 @@
 			//print("in addItem() - just notified");
 		}
 		//print("in addItem() - leaving");
+	}
+
+	public Object[] clearItems() {
+		Object[] array;
+		synchronized (list) {
+			array = list.toArray();
+			list.clear();
+		}
+		return array;
 	}
 
 	private static void print(String msg) {
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.31
diff -u -r1.31 RxThread.java
--- src/org/eclipse/cdt/debug/mi/core/RxThread.java	10 Oct 2002 22:06:08 -0000	1.31
+++ src/org/eclipse/cdt/debug/mi/core/RxThread.java	13 Oct 2002 02:25:50 -0000
@@ -91,6 +91,16 @@
 			clean.setDaemon(true);
 			clean.start();
 		}
+		// Clear the queue and notify any command waiting, we are going down.
+		CommandQueue rxQueue = session.getRxQueue();
+		if (rxQueue != null) {
+			Command[] cmds = rxQueue.clearCommands();
+			for (int i = 0; i < cmds.length; i++) {
+				synchronized (cmds[i]) {
+					cmds[i].notifyAll();
+				}
+			}
+		}
 	}
 
 	/**
Index: src/org/eclipse/cdt/debug/mi/core/TxThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/TxThread.java,v
retrieving revision 1.12
diff -u -r1.12 TxThread.java
--- src/org/eclipse/cdt/debug/mi/core/TxThread.java	7 Sep 2002 14:49:09 -0000	1.12
+++ src/org/eclipse/cdt/debug/mi/core/TxThread.java	13 Oct 2002 02:25:51 -0000
@@ -46,7 +46,8 @@
 					// Move to the RxQueue only if we have
 					// a valid token, this is to permit input(HACK!)
 					// or commands that do not want to wait for responses.
-					if (cmd.getToken() > 0) {
+					Thread rx = session.getRxThread();
+					if (cmd.getToken() > 0 && rx != null && rx.isAlive()) {
 						CommandQueue rxQueue = session.getRxQueue();
 						rxQueue.addCommand(cmd);
 					} else {
@@ -66,5 +67,16 @@
 		} catch (IOException e) {
 			//e.printStackTrace();
 		}
+
+		// Clear the queue and notify any command waiting, we are going down.
+                CommandQueue txQueue = session.getTxQueue();
+                if (txQueue != null) {
+                        Command[] cmds = txQueue.clearCommands();
+                        for (int i = 0; i < cmds.length; i++) {
+                                synchronized (cmds[i]) {
+                                        cmds[i].notifyAll();
+                                }
+                        }
+                }
 	}
 }
Index: src/org/eclipse/cdt/debug/mi/core/cdi/CThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CThread.java,v
retrieving revision 1.16
diff -u -r1.16 CThread.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/CThread.java	10 Oct 2002 22:04:59 -0000	1.16
+++ src/org/eclipse/cdt/debug/mi/core/cdi/CThread.java	13 Oct 2002 02:25:53 -0000
@@ -102,7 +102,7 @@
 		
 		// Check to see if we are already at this level
 		StackFrame current = getCurrentStackFrame();
-		if (current.getLevel() == frameNum) {
+		if (current != null && current.getLevel() == frameNum) {
 			// noop
 			return;
 		}



Back to the top