Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-debug-dev] Zylin Embedded CDT patches

What's the plan for further improvements to CDT GDB support?

The Wiki 4.0 plan did not contain any mention of GDB(where my primary
interest in CDT lies).

http://wiki.eclipse.org/index.php/CDT/planning/4.0


With CDT 3.1 out of the door, perhaps it is time to submit patches or
send a "ping" on those patches/improvements that have not been
incorporated yet?

Attached are the modifications I've made to CDT to a) fix problems
with breakpoints b) improve GDB console.  I'll be happy to work on
making these modifications more palatable if there CDT  is receptive
to GDB patches(receptive as in have resources to follow up on).


--
Øyvind Harboe
http://www.zylin.com
### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.debug.mi.core
Index: cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java,v
retrieving revision 1.39
diff -u -r1.39 BreakpointManager.java
--- cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java	23 Jun 2006 17:25:38 -0000	1.39
+++ cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java	29 Jun 2006 13:51:22 -0000
@@ -433,14 +433,7 @@
 					int line = allMIBreakpoints[i].getLine();
 					String addr = allMIBreakpoints[i].getAddress();
 
-					if (file != null && file.length() > 0 && line > 0) {
-						LineLocation location = createLineLocation (allMIBreakpoints[i].getFile(),
-								allMIBreakpoints[i].getLine());
-						// By default new breakpoint are LineBreakpoint
-						Breakpoint newBreakpoint = new LineBreakpoint(target, type, location, condition);
-						newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]});
-						bList.add(newBreakpoint);
-					} else if (function != null && function.length() > 0) {
+					if (function != null && function.length() > 0) {
 						FunctionLocation location = createFunctionLocation(file, function);
 						// By default new breakpoint are LineBreakpoint
 						Breakpoint newBreakpoint = new FunctionBreakpoint(target, type, location, condition);
@@ -453,6 +446,13 @@
 						Breakpoint newBreakpoint = new AddressBreakpoint(target, type, location, condition);
 						newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]});
 						bList.add(newBreakpoint);
+					} else if (file != null && file.length() > 0 && line > 0) {
+						LineLocation location = createLineLocation (allMIBreakpoints[i].getFile(),
+								allMIBreakpoints[i].getLine());
+						// By default new breakpoint are LineBreakpoint
+						Breakpoint newBreakpoint = new LineBreakpoint(target, type, location, condition);
+						newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]});
+						bList.add(newBreakpoint);
 					}
 				}
 				eventList.add(new MIBreakpointCreatedEvent(miSession, no)); 
@@ -936,9 +936,11 @@
 					if (colon != -1) {
 						line.append(function);
 					} else {
-						if (file != null && file.length() > 0) {
-							line.append(file).append(':');
-						}
+						// FIX!!! sometimes the file can be the name of the binary(foo.elf)
+						// in which this does not work.
+//						if (file != null && file.length() > 0) {
+//							line.append(file).append(':');
+//						}
 						// GDB does not seem to accept function arguments when
 						// we use file name:
 						// (gdb) break file.c:Test(int)
Index: mi/org/eclipse/cdt/debug/mi/core/output/MIConst.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIConst.java,v
retrieving revision 1.8
diff -u -r1.8 MIConst.java
--- mi/org/eclipse/cdt/debug/mi/core/output/MIConst.java	23 Jun 2006 17:52:01 -0000	1.8
+++ mi/org/eclipse/cdt/debug/mi/core/output/MIConst.java	29 Jun 2006 13:51:23 -0000
@@ -65,7 +65,7 @@
 			buffer.append('\\');
 		}
 
-		return buffer.toString();
+		return buffer.toString().replaceAll("\\r\\n", "\n");
 	}
 
 	public String toString() {
Index: mi/org/eclipse/cdt/debug/mi/core/output/MIParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIParser.java,v
retrieving revision 1.9
diff -u -r1.9 MIParser.java
--- mi/org/eclipse/cdt/debug/mi/core/output/MIParser.java	23 Jun 2006 17:25:40 -0000	1.9
+++ mi/org/eclipse/cdt/debug/mi/core/output/MIParser.java	29 Jun 2006 13:51:23 -0000
@@ -131,7 +131,13 @@
 				if (token.charAt(0) == '^') {
 					token.deleteCharAt(0);
 					rr = processMIResultRecord(token, id);
-				} else if (startsWith(token, primaryPrompt)) {
+				} else if (!token.toString().startsWith(primaryPrompt)) {
+					/* we want to process the primary prompt as well to get it printed.. */
+	                MIOOBRecord band = processMIOOBRecord(token, id);
+                    if (band != null) {
+                        oobs.add(band);
+                    }
+                } else if (startsWith(token, primaryPrompt)) {
 					//break; // Do nothing.
 				} else {
 					MIOOBRecord band = processMIOOBRecord(token, id);
@@ -246,7 +252,7 @@
 		} else {
 			// Badly format MI line, just pass it to the user as target stream
 			MIStreamRecord stream = new MITargetStreamOutput();
-			stream.setCString(buffer.toString() + "\n"); //$NON-NLS-1$
+			stream.setCString(buffer.toString()); //$NON-NLS-1$
 			oob = stream;
 		}
 		return oob;
@@ -338,7 +344,7 @@
 				MIResult result = processMIResult(buffer);
 				if (result != null) {
 					resultList.add(result);
-				}
+		}
 			}
 			if (buffer.length() > 0 && buffer.charAt(0) == ',') {
 				buffer.deleteCharAt(0);
Index: mi/org/eclipse/cdt/debug/mi/core/RxThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/RxThread.java,v
retrieving revision 1.13
diff -u -r1.13 RxThread.java
--- mi/org/eclipse/cdt/debug/mi/core/RxThread.java	23 Jun 2006 17:25:44 -0000	1.13
+++ mi/org/eclipse/cdt/debug/mi/core/RxThread.java	29 Jun 2006 13:51:23 -0000
@@ -97,6 +97,19 @@
 
 				setPrompt(line);
 				processMIOutput(line + "\n"); //$NON-NLS-1$
+				if (inPrimaryPrompt()&&!session.isVerboseModeEnabled()) {
+					if (!session.silent())
+					{
+						OutputStream console = session.getConsolePipe();
+						if (console!=null)
+						{
+							console.write(line.getBytes());
+							console.flush();
+						}
+					}
+					session.processedPrompt();
+				}
+
 			}
 		} catch (IOException e) {
 			//e.printStackTrace();
@@ -173,8 +186,11 @@
 
 			MIResultRecord rr = response.getMIResultRecord();
 			if (rr != null) {
+				
 				int id = rr.getToken();
 				Command cmd = rxQueue.removeCommand(id);
+				
+			    session.retireCmd(cmd);
 
 				// Clear the accumulate oobList on each new Result Command
 				// response.
@@ -329,6 +345,24 @@
 			}
 		} else if (async instanceof MIStatusAsyncOutput) {
 			// Nothing done .. but what about +download??
+			// This is meant for the gdb console.
+			OutputStream log = session.getLogPipe();
+			if (log != null) {
+			    MIStatusAsyncOutput out = (MIStatusAsyncOutput) async;
+			    for (int i=0; i<out.getMIResults().length; i++) {
+					String str = out.getMIResults()[i].getVariable();
+					if (str != null) {
+						try {
+							log.write((str + "\n").getBytes());
+							log.flush();
+						} catch (IOException e) {
+						}
+					}
+			    }
+			}
+		    
+		    
+		    
 		} else if (async instanceof MINotifyAsyncOutput) {
 			// Nothing
 		}
@@ -336,6 +370,7 @@
 
 	void processMIOOBRecord(MIStreamRecord stream) {
 		if (stream instanceof MIConsoleStreamOutput) {
+			if (!session.silent()) {
 			OutputStream console = session.getConsolePipe();
 			if (console != null) {
 				MIConsoleStreamOutput out = (MIConsoleStreamOutput) stream;
@@ -349,11 +384,13 @@
 					} catch (IOException e) {
 					}
 				}
+				}
 			}
 			// Accumulate the Console Stream Output response for parsing.
 			// Some commands will put valuable info  in the Console Stream.
 			oobList.add(stream);
 		} else if (stream instanceof MITargetStreamOutput) {
+			if (true/*!session.silent()*/) {
 			OutputStream target = session.getMIInferior().getPipedOutputStream();
 			if (target != null) {
 				MITargetStreamOutput out = (MITargetStreamOutput) stream;
@@ -365,12 +402,29 @@
 					} catch (IOException e) {
 					}
 				}
+				} else {
+					/* dump to GDB console as a fallback... */
+					OutputStream console = session.getConsolePipe();
+					if (console != null) {
+						MITargetStreamOutput out = (MITargetStreamOutput) stream;
+						String str = out.getString();
+						// Process the console stream too.
+						if (str != null) {
+							try {
+								console.write(str.getBytes());
+								console.flush();
+							} catch (IOException e) {
+							}
+						}
+					}
+				}
 			}
 			// Accumulate the Target Stream Output response for parsing.
 			// Some commands, e.g. 'monitor' will put valuable info  in the Console Stream.
 			// This fixes bug 119370.
 			oobList.add(stream);
 		} else if (stream instanceof MILogStreamOutput) {
+			if (!session.silent()) {
 			// This is meant for the gdb console.
 			OutputStream log = session.getLogPipe();
 			if (log != null) {
@@ -383,11 +437,34 @@
 					} catch (IOException e) {
 					}
 				}
+				}
 			}
 			// Accumulate the Log Stream Output response for parsing.
 			// Some commands will put valuable info  in the Log Stream.
 			oobList.add(stream);
-		}
+		} else 
+		{
+			try
+			{
+				MIStreamRecord out = (MIStreamRecord) stream;
+				/* unknown type, just dump output to console */
+				if (!session.silent()) {
+					OutputStream console = session.getConsolePipe();
+					if (console != null) {
+						String str = out.getString();
+						if (str != null) {
+							try {
+								console.write(str.getBytes());
+								console.flush();
+							} catch (IOException e) {
+							}
+						}
+					}
+				}
+			} catch (RuntimeException e)
+			{
+			}
+		} 
 	}
 
 	/**
Index: mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java,v
retrieving revision 1.9
diff -u -r1.9 SessionProcess.java
--- mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java	23 Jun 2006 17:52:03 -0000	1.9
+++ mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java	29 Jun 2006 13:51:23 -0000
@@ -92,11 +92,13 @@
 						cmd = new RawCommand(str);
 					} else if (session.useExecConsole() && str.length() > 0 
 							&& !CLIProcessor.isSteppingOperation(str)) {
+					    // FIX!!! Does not work on my GDB for "load"
 						CommandFactory factory = session.getCommandFactory();
 						cmd = factory.createMIInterpreterExecConsole(str);
 					} else {
 						cmd = new CLICommand(str);
 					}
+					cmd.setSilent(false);
 					try {
 						// Do not wait around for the answer.
 						session.postCommand(cmd, -1);
Index: mi/org/eclipse/cdt/debug/mi/core/MISession.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java,v
retrieving revision 1.17
diff -u -r1.17 MISession.java
--- mi/org/eclipse/cdt/debug/mi/core/MISession.java	23 Jun 2006 17:25:44 -0000	1.17
+++ mi/org/eclipse/cdt/debug/mi/core/MISession.java	29 Jun 2006 13:51:23 -0000
@@ -837,4 +837,47 @@
 	public boolean isVerboseModeEnabled() {
 		return verboseMode;
 	}
+
+
+	private Command inflightCmd;
+	private boolean showOutput=true; // show first command
+	/**
+	 * Set this cmd as in flight
+	 * 
+	 * @param console
+	 */
+	public void inflightConsoleCmd(Command cmd) {
+		inflightCmd=cmd;
+		showOutput=showOutput||!cmd.isSilent();
+	}
+
+	/**
+	 * @param cmd
+	 */
+	public void retireCmd(Command cmd) {
+	    if (inflightCmd!=null&&cmd!=null) {
+	        if (cmd.getToken()==inflightCmd.getToken()) {	            
+	            inflightCmd=null;
+	        } else {
+	            int x=0;
+	        }
+	    }
+	}
+
+	/**
+	 * Are we in silent mode?
+	 * 
+	 * @return
+	 */
+	public boolean silent() {
+		return !showOutput&&!isVerboseModeEnabled();
+	}
+
+	public void processedPrompt()
+	{
+		showOutput=false;
+	}
+	
+
+	
 }
Index: mi/org/eclipse/cdt/debug/mi/core/TxThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/TxThread.java,v
retrieving revision 1.7
diff -u -r1.7 TxThread.java
--- mi/org/eclipse/cdt/debug/mi/core/TxThread.java	23 Jun 2006 17:52:03 -0000	1.7
+++ mi/org/eclipse/cdt/debug/mi/core/TxThread.java	29 Jun 2006 13:51:23 -0000
@@ -71,6 +71,7 @@
 						} else if (cmd instanceof MIInterpreterExecConsole) {
 							cli.processStateChanges((MIInterpreterExecConsole)cmd);
 						}
+						session.inflightConsoleCmd(cmd);
 
 						// shove in the pipe
 						if (out != null) {
Index: mi/org/eclipse/cdt/debug/mi/core/command/Command.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/Command.java,v
retrieving revision 1.5
diff -u -r1.5 Command.java
--- mi/org/eclipse/cdt/debug/mi/core/command/Command.java	23 Jun 2006 17:25:39 -0000	1.5
+++ mi/org/eclipse/cdt/debug/mi/core/command/Command.java	29 Jun 2006 13:51:23 -0000
@@ -112,4 +112,21 @@
 	public void setQuiet( boolean quiet ) {
 		this.quiet = quiet;
 	}
+
+	private boolean silent = true;
+
+	/**
+	 * @return Returns the silent.
+	 */
+	public boolean isSilent() {
+		return silent;
+	}
+
+	/**
+	 * @param silent The silent to set.
+	 */
+	public void setSilent(boolean silent) {
+		this.silent = silent;
+	}
+
 }
#P org.eclipse.cdt.debug.core
Index: src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-releng/all/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java,v
retrieving revision 1.59
diff -u -r1.59 CBreakpointManager.java
--- src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java	23 Jun 2006 17:26:25 -0000	1.59
+++ src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java	29 Jun 2006 13:51:25 -0000
@@ -671,7 +671,12 @@
 		try {
 			ICDILocator location = cdiBreakpoint.getLocator();
 			String file = location.getFile();
-			if ( !isEmpty( file ) ) {
+			if ( !isEmpty( location.getFunction() ) ) {
+				breakpoint = createFunctionBreakpoint( cdiBreakpoint );
+			}
+			else if ( !location.getAddress().equals( BigInteger.ZERO ) ) {
+				breakpoint = createAddressBreakpoint( cdiBreakpoint );
+			} else if ( !isEmpty( file ) ) {
 				Object sourceElement = getSourceElement( file );
 				String sourceHandle = file;
 				IResource resource = getProject();
@@ -682,7 +687,7 @@
 				else if ( sourceElement instanceof IStorage ) {
 					sourceHandle = ((IStorage)sourceElement).getFullPath().toOSString();
 					resource = ResourcesPlugin.getWorkspace().getRoot();
-				}
+				} 
 				breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint );
 //				else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) {
 //					breakpoint = createFunctionBreakpoint( cdiBreakpoint );
@@ -691,12 +696,6 @@
 //					breakpoint = createAddressBreakpoint( cdiBreakpoint );
 //				}
 			}
-			else if ( !isEmpty( location.getFunction() ) ) {
-				breakpoint = createFunctionBreakpoint( cdiBreakpoint );
-			}
-			else if ( !location.getAddress().equals( BigInteger.ZERO ) ) {
-				breakpoint = createAddressBreakpoint( cdiBreakpoint );
-			}
 		}
 		catch( CDIException e ) {
 		}
@@ -870,24 +869,28 @@
 		ICBreakpoint[] breakpoints = register( bps );
 		setBreakpointsOnTarget0( breakpoints );
 	}
-
+	
 	private boolean isTargetBreakpoint( ICBreakpoint breakpoint ) {
 		IResource resource = breakpoint.getMarker().getResource();
 		if ( breakpoint instanceof ICAddressBreakpoint )
 			return supportsAddressBreakpoint( (ICAddressBreakpoint)breakpoint );
 		if ( breakpoint instanceof ICLineBreakpoint ) {
-			try {
-				String handle = breakpoint.getSourceHandle();
-				ISourceLocator sl = getSourceLocator();
-				if ( sl instanceof ICSourceLocator )
-					return ( ((ICSourceLocator)sl).findSourceElement( handle ) != null );
-				else if ( sl instanceof CSourceLookupDirector ) {
-					return ( ((CSourceLookupDirector)sl).contains( breakpoint ) );
-				}
-			}
-			catch( CoreException e ) {
-				return false;
-			}
+			/* if this isn't a valid line breakpoint, then GDB will produce an
+			 * error message, which is sufficient handling of the problem.
+			 */
+			return true;
+//			try {
+//				String handle = breakpoint.getSourceHandle();
+//				ISourceLocator sl = getSourceLocator();
+//				if ( sl instanceof ICSourceLocator )
+//					return ( ((ICSourceLocator)sl).findSourceElement( handle ) != null );
+//				else if (checkCSourceLookupDirector(sl)) {
+//					return ( ((CSourceLookupDirector)sl).contains( breakpoint ) );
+//				}
+//			}
+//			catch( CoreException e ) {
+//				return false;
+//			}
 		}
 		else {
 			IProject project = resource.getProject();

Back to the top