Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Framework for sharedlib deferred breakpoint

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.161
diff -u -r1.161 ChangeLog
--- ChangeLog	13 Aug 2003 21:16:17 -0000	1.161
+++ ChangeLog	19 Aug 2003 01:50:56 -0000
@@ -1,3 +1,21 @@
+2003-08-18 Alain Magloire
+
+	From the manual:
+	By default GDB will automatically keep track of objects as they are
+	loaded and unloaded by the dynamic linker.  By using the command `set
+	stop-on-solib-events 1' you can arrange for GDB to stop the inferior
+	when shared library events occur, thus allowing you to set breakpoints
+	in shared libraries which are explicitly loaded by the inferior.
+
+	* src/org/eclipse/cdt/debug/mi/core/event/MISharedLibEvent.java:
+	New file, StoppedEvent du to shared lib events.
+	* src/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java:
+	Catch MISharedLibEvent.
+	* src/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryevent.java:
+	New file implements ICDISharedLibaryEvent.
+	* src/org/eclipse/cdt/debug/mi/core/RxThread.java:
+	Hack to catch suspend/stop on shared library.
+
 2003-08-11 Mikhail Khodjaiants
 	* src/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java:
 	* src/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java:
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.44
diff -u -r1.44 RxThread.java
--- src/org/eclipse/cdt/debug/mi/core/RxThread.java	3 Feb 2003 21:29:30 -0000	1.44
+++ src/org/eclipse/cdt/debug/mi/core/RxThread.java	19 Aug 2003 01:50:56 -0000
@@ -26,6 +26,7 @@
 import org.eclipse.cdt.debug.mi.core.event.MIInferiorSignalExitEvent;
 import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
 import org.eclipse.cdt.debug.mi.core.event.MIRunningEvent;
+import org.eclipse.cdt.debug.mi.core.event.MISharedLibEvent;
 import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
 import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
 import org.eclipse.cdt.debug.mi.core.event.MIStoppedEvent;
@@ -64,9 +65,8 @@
 	 * Get the response, parse the output, dispatch for OOB
 	 * search for the corresponding token in rxQueue for the ResultRecord.
 	 */
-	public void run () {
-		BufferedReader reader =
-			new BufferedReader(new InputStreamReader(session.getChannelInputStream()));
+	public void run() {
+		BufferedReader reader = new BufferedReader(new InputStreamReader(session.getChannelInputStream()));
 		try {
 			String line;
 			while ((line = reader.readLine()) != null) {
@@ -84,8 +84,8 @@
 		if (session.getChannelInputStream() != null) {
 			Runnable cleanup = new Runnable() {
 				public void run() {
-					// Change the state of the inferior.
-					session.getMIInferior().setTerminated();
+						// Change the state of the inferior.
+	session.getMIInferior().setTerminated();
 					session.terminate();
 				}
 			};
@@ -125,10 +125,9 @@
 
 				// Clear the accumulate oobList on each new Result Command
 				// response.
-				MIOOBRecord [] oobRecords =
-					(MIOOBRecord[])oobList.toArray(new MIOOBRecord[0]); 
+				MIOOBRecord[] oobRecords = (MIOOBRecord[]) oobList.toArray(new MIOOBRecord[0]);
 				oobList.clear();
-				
+
 				// Check if the state changed.
 				String state = rr.getResultClass();
 				if ("running".equals(state)) {
@@ -174,7 +173,7 @@
 						cmd.setMIOutput(response);
 						cmd.notifyAll();
 					}
-				} 
+				}
 				// Some result record contains informaton specific to oob.
 				// This will happen when CLI-Command is use, for example
 				// doing "run" will block and return a breakpointhit
@@ -189,7 +188,7 @@
 				}
 			}
 
-			MIEvent[] events = (MIEvent[])list.toArray(new MIEvent[list.size()]);
+			MIEvent[] events = (MIEvent[]) list.toArray(new MIEvent[list.size()]);
 			session.fireEvents(events);
 		} // if response != null
 	}
@@ -199,15 +198,15 @@
 	 */
 	void processMIOOBRecord(MIOOBRecord oob, List list) {
 		if (oob instanceof MIAsyncRecord) {
-			processMIOOBRecord((MIAsyncRecord)oob, list);
+			processMIOOBRecord((MIAsyncRecord) oob, list);
 		} else if (oob instanceof MIStreamRecord) {
-			processMIOOBRecord((MIStreamRecord)oob);
+			processMIOOBRecord((MIStreamRecord) oob);
 		}
 	}
 
 	void processMIOOBRecord(MIAsyncRecord async, List list) {
 		if (async instanceof MIExecAsyncOutput) {
-			MIExecAsyncOutput exec = (MIExecAsyncOutput)async;
+			MIExecAsyncOutput exec = (MIExecAsyncOutput) async;
 			// Change of state.
 			String state = exec.getAsyncClass();
 			if ("stopped".equals(state)) {
@@ -218,7 +217,7 @@
 					MIValue val = results[i].getMIValue();
 					if (var.equals("reason")) {
 						if (val instanceof MIConst) {
-							String reason =((MIConst)val).getString();
+							String reason = ((MIConst) val).getString();
 							e = createEvent(reason, exec);
 							if (e != null) {
 								list.add(e);
@@ -226,7 +225,24 @@
 						}
 					}
 				}
-			
+
+				// GDB does not have reason when stopping on shared, hopefully
+				// this will be fix in newer version meanwhile, we will use a hack
+				// to cope.  On most platform we can detect by looking at the
+				// console stream for phrase:
+				// 	~"Stopped due to shared library event\n"
+				//
+				// Althought it is a _real_ bad idea to do this, we do not have
+				// any other alternatives.
+				String[] logs = getStreamRecords();
+				for (int i = 0; i < logs.length; i++) {
+					if (logs[i].equalsIgnoreCase("Stopped due to shared library event")) {
+						session.getMIInferior().setSuspended();
+						e = new MISharedLibEvent(exec);
+						list.add(e);
+					}
+				}
+
 				// We were stopped for some unknown reason, for example
 				// GDB for temporary breakpoints will not send the
 				// "reason" ??? still fire a stopped event.
@@ -247,7 +263,7 @@
 		if (stream instanceof MIConsoleStreamOutput) {
 			OutputStream console = session.getConsolePipe();
 			if (console != null) {
-				MIConsoleStreamOutput out = (MIConsoleStreamOutput)stream;
+				MIConsoleStreamOutput out = (MIConsoleStreamOutput) stream;
 				String str = out.getString();
 				if (str != null) {
 					try {
@@ -263,7 +279,7 @@
 		} else if (stream instanceof MITargetStreamOutput) {
 			OutputStream target = session.getMIInferior().getPipedOutputStream();
 			if (target != null) {
-				MITargetStreamOutput out = (MITargetStreamOutput)stream;
+				MITargetStreamOutput out = (MITargetStreamOutput) stream;
 				String str = out.getString();
 				if (str != null) {
 					try {
@@ -277,7 +293,7 @@
 			// This is meant for the gdb console.
 			OutputStream log = session.getLogPipe();
 			if (log != null) {
-				MILogStreamOutput out = (MILogStreamOutput)stream;
+				MILogStreamOutput out = (MILogStreamOutput) stream;
 				String str = out.getString();
 				if (str != null) {
 					try {
@@ -297,13 +313,13 @@
 	 * Dispatch a thread to deal with the listeners.
 	 */
 	void processMIOOBRecord(MIResultRecord rr, List list) {
-		MIResult[] results =  rr.getMIResults();
+		MIResult[] results = rr.getMIResults();
 		for (int i = 0; i < results.length; i++) {
 			String var = results[i].getVariable();
 			if (var.equals("reason")) {
 				MIValue value = results[i].getMIValue();
 				if (value instanceof MIConst) {
-					String reason = ((MIConst)value).getString();
+					String reason = ((MIConst) value).getString();
 					MIEvent event = createEvent(reason, rr);
 					if (event != null) {
 						list.add(event);
@@ -330,9 +346,10 @@
 				event = new MIBreakpointHitEvent(rr);
 			}
 			session.getMIInferior().setSuspended();
-		} else if ("watchpoint-trigger".equals(reason) ||
-		           "read-watchpoint-trigger".equals(reason) ||
-		           "access-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) {
@@ -374,8 +391,7 @@
 				event = new MIFunctionFinishedEvent(rr);
 			}
 			session.getMIInferior().setSuspended();
-		} else if ("exited-normally".equals(reason) ||
-			"exited".equals(reason)) {
+		} else if ("exited-normally".equals(reason) || "exited".equals(reason)) {
 			if (exec != null) {
 				event = new MIInferiorExitEvent(exec);
 			} else if (rr != null) {
@@ -391,6 +407,20 @@
 			session.getMIInferior().setTerminated();
 		}
 		return event;
+	}
+
+	String[] getStreamRecords() {
+		List streamRecords = new ArrayList();
+		MIOOBRecord[] oobRecords = (MIOOBRecord[]) oobList.toArray(new MIOOBRecord[0]);
+		for (int i = 0; i < oobRecords.length; i++) {
+			if (oobRecords[i] instanceof MIStreamRecord) {
+				String s = ((MIStreamRecord) oobRecords[i]).getString().trim();
+				if (s != null && s.length() > 0) {
+					streamRecords.add(s);
+				}
+			}
+		}
+		return (String[]) streamRecords.toArray(new String[0]);
 	}
 
 }
Index: src/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryEvent.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryEvent.java
diff -N src/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryEvent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryEvent.java	19 Aug 2003 01:50:56 -0000
@@ -0,0 +1,17 @@
+/*
+ * 
+ */
+package org.eclipse.cdt.debug.mi.core.cdi;
+
+import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryEvent;
+
+/**
+ *
+ */
+public class SharedLibraryEvent extends SessionObject implements ICDISharedLibraryEvent {
+	
+	public SharedLibraryEvent(Session session) {
+		super(session);
+	}
+
+}
Index: src/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java,v
retrieving revision 1.3
diff -u -r1.3 SuspendedEvent.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java	27 Jan 2003 03:09:20 -0000	1.3
+++ src/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java	19 Aug 2003 01:50:56 -0000
@@ -13,6 +13,7 @@
 import org.eclipse.cdt.debug.mi.core.cdi.EndSteppingRange;
 import org.eclipse.cdt.debug.mi.core.cdi.ErrorInfo;
 import org.eclipse.cdt.debug.mi.core.cdi.Session;
+import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryEvent;
 import org.eclipse.cdt.debug.mi.core.cdi.SignalReceived;
 import org.eclipse.cdt.debug.mi.core.cdi.WatchpointScope;
 import org.eclipse.cdt.debug.mi.core.cdi.WatchpointTrigger;
@@ -21,6 +22,7 @@
 import org.eclipse.cdt.debug.mi.core.event.MIEvent;
 import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent;
 import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
+import org.eclipse.cdt.debug.mi.core.event.MISharedLibEvent;
 import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
 import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
 import org.eclipse.cdt.debug.mi.core.event.MIWatchpointScopeEvent;
@@ -56,6 +58,8 @@
 			return new EndSteppingRange(session);
 		} else if (event instanceof MIErrorEvent) {
 			return new ErrorInfo(session, (MIErrorEvent)event);
+		} else if (event instanceof MISharedLibEvent) {
+			return new SharedLibraryEvent(session);
 		}
 		return session;
 	}
Index: src/org/eclipse/cdt/debug/mi/core/event/MISharedLibEvent.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/event/MISharedLibEvent.java
diff -N src/org/eclipse/cdt/debug/mi/core/event/MISharedLibEvent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/event/MISharedLibEvent.java	19 Aug 2003 01:50:56 -0000
@@ -0,0 +1,28 @@
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ *
+ */
+package org.eclipse.cdt.debug.mi.core.event;
+
+import org.eclipse.cdt.debug.mi.core.output.MIExecAsyncOutput;
+import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
+
+
+
+/**
+ *
+ */
+public class MISharedLibEvent extends MIStoppedEvent {
+
+	public MISharedLibEvent(MIExecAsyncOutput async) {
+		super(async);
+		parse();
+	}
+ 
+	public MISharedLibEvent(MIResultRecord record) {
+		super(record);
+		parse();
+	}
+
+}



Back to the top