Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Another try at Cygwin GDB - mi.core

Title: Another try at Cygwin GDB - mi.core

I have made another attempt at supporting Cygwin GDB without messing with native GDB.  This patch (and the following one for mi.ui) creates a new debugger for Cygwin GDB.  It subclasses the GDBDebugger but sets a flag in MISession to not that this is Cygwin.  The Source Manager checks the flag and converts the path if necessary.  Please review.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.38
diff -u -r1.38 ChangeLog
--- ChangeLog   25 Nov 2002 17:08:07 -0000      1.38
+++ ChangeLog   26 Nov 2002 16:33:45 -0000
@@ -1,3 +1,14 @@
+2002-11-26 Doug Schaefer
+
+       * src/.../mi/core/MISession.java:
+       Added flag to mark when the session is for the Cygwin version of gdb
+       * src/.../mi/core/CygwinGDBDebugger:
+       New.  The debugger for Cygwin GDB subclasses GDB Debugger and sets above flag
+       * src/.../mi/core/cdi/SourceManager.java (addSourcePaths):
+       Checks cygwin flag and converts the paths if true.
+       * plugin.xml:
+       Added the new debugger.
+
 2002-11-25 Alain Magloire
 
        * src/.../mi/core/cdi/Watchpoint.java:
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/plugin.xml,v
retrieving revision 1.12
diff -u -r1.12 plugin.xml
--- plugin.xml  13 Nov 2002 14:00:45 -0000      1.12
+++ plugin.xml  26 Nov 2002 16:33:45 -0000
@@ -22,12 +22,20 @@
    <extension
          point="org.eclipse.cdt.debug.core.CDebugger">
       <debugger
+            platform="native"
             name="%GDBDebugger.name"
             modes="run,core,attach"
+            cpu="native"
             class="org.eclipse.cdt.debug.mi.core.GDBDebugger"
-            id="org.eclipse.cdt.debug.mi.core.CDebugger"
-               cpu="native"
-               platform="native">
+            id="org.eclipse.cdt.debug.mi.core.CDebugger">
+      </debugger>
+      <debugger
+            platform="win32"
+            name="Cygwin GDB Debugger"
+            modes="run,core,attach"
+            cpu="native"
+            class="org.eclipse.cdt.debug.mi.core.CygwinGDBDebugger"
+            id="org.eclipse.cdt.debug.mi.core.CygwinCDebugger">
       </debugger>
    </extension>
 
Index: src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
diff -N src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java    26 Nov 2002 16:33:45 -0000
@@ -0,0 +1,40 @@
+/*
+ * (c) Copyright Rational Software Corporation. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.debug.mi.core;
+
+import org.eclipse.cdt.debug.core.cdi.CDIException;
+import org.eclipse.cdt.debug.core.cdi.ICDISession;
+import org.eclipse.cdt.debug.mi.core.cdi.CSession;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+/**
+ * @author Doug Schaefer
+ *
+ * Turns on behavior specific to cygwin.  Specifically, this handles
+ * conversion of DOS paths to Cygwin-style paths in the SourceManager.
+ */
+public class CygwinGDBDebugger extends GDBDebugger {
+
+       public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException
+       {
+               CSession session = (CSession)super.createLaunchSession(config, exe);
+               session.getMISession().setIsCygwin(true);
+               return session;
+       }
+      
+       public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException {
+               CSession session = (CSession)super.createAttachSession(config, exe, pid);
+               session.getMISession().setIsCygwin(true);
+               return session;
+       }
+      
+       public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException {

+               CSession session = (CSession)super.createCoreSession(config, exe, corefile);
+               session.getMISession().setIsCygwin(true);
+               return session;
+       }
+}
Index: src/org/eclipse/cdt/debug/mi/core/MISession.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java,v
retrieving revision 1.40
diff -u -r1.40 MISession.java
--- src/org/eclipse/cdt/debug/mi/core/MISession.java    1 Nov 2002 16:44:34 -0000       1.40
+++ src/org/eclipse/cdt/debug/mi/core/MISession.java    26 Nov 2002 16:33:45 -0000
@@ -53,6 +53,9 @@
 
        // hold the type of the session(post-mortem, attach etc ..)
        int sessionType;
+      
+       // flag to invoke cygwin specific behavior
+       boolean isCygwin = false;
 
        Process sessionProcess;
        Process gdbProcess;
@@ -502,4 +505,11 @@
                }
        }
 
+       public boolean getIsCygwin() {
+               return isCygwin;
+       }
+      
+       public void setIsCygwin(boolean c) {
+               isCygwin = c;
+       }
 }
Index: src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java,v
retrieving revision 1.16
diff -u -r1.16 SourceManager.java
--- src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java    20 Oct 2002 23:28:38 -0000      1.16
+++ src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java    26 Nov 2002 16:33:45 -0000
@@ -38,6 +38,25 @@
         */
        public void addSourcePaths(String[] dirs) throws CDIException {
                MISession mi = getCSession().getMISession();
+              
+               // If we are running cygwin, convert the paths
+               if (mi.getIsCygwin())
+               {
+                       String[] newdirs = new String[dirs.length];
+
+                       // For cygwin, need to convert the slashes to the other way and convert the drive letter
+                       for (int i = 0; i < dirs.length; i++) {
+                               String path = dirs[i].replace('\\', '/');
+
+                               if (path.charAt(1) == ':')
+                                       path = "/cygdrive/" + path.charAt(0) + path.substring(2);
+
+                               newdirs[i] = path;
+                       }
+                      
+                       dirs = newdirs;
+               }
+
                CommandFactory factory = mi.getCommandFactory();
                MIEnvironmentDirectory dir = factory.createMIEnvironmentDirectory(dirs);
                try {

Doug Schaefer
Senior Staff Software Engineer
Rational - the software development company
Ottawa (Kanata), Ontario, Canada


Back to the top