Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Allow a subclass of GDBLaunchDelegate to create its own Launch object without duplicating the initialization sequence.

Hi,

Sorry, forgot to attach the patch in the earlier mail.

Thanks
Abeer Bagul
Tensilica India.

On Thu, Feb 10, 2011 at 4:55 PM, Abeer Bagul <abeer4eclipse@xxxxxxxxx> wrote:
Hi,

In our DSF launch, I create a subclass of GDBLaunch using the method GdbLaunchDelegate.getLaunch(). Currently this method does the following steps:
1) Create an object of GDBLaunch
2) Initialize the above obj
3) Create the sourceLocator
3.1) Initialize the sourceLocator from the memento

The method getSourceLocator() is also private, so a subclass of GDBLaunchDelegate, which only wants to substitute the GDBLaunch object and the sourcelocator object, while keeping the superclass initialization sequence as it is, has to currently copy both the methods getLaunch() and getSourceLocator() to the subclass. If there is any minor bugfix to theĀ  initialization sequence in these methods in the superclass, the vendor specific subclass will miss out on these bug fixes.

Can we modify the GDBLaunchDelegate as follows:
1) Make getSourceLocator() protected instead of private
2) Create the GDBLaunch object in a separate protected method createLaunch() which is called from getLaunch() in place of the constructor call.
3) Create the sourceLocator object in a separate protected method createSourceLocator which is called from getSourceLocator in place of the constructor call.

Have attached a patch to GDBLaunchDelegate to demonstrate the changes.

Thanks
Abeer Bagul.
Tensilica India.

### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.dsf.gdb
Index: src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java,v
retrieving revision 1.20
diff -u -r1.20 GdbLaunchDelegate.java
--- src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java	27 Sep 2010 15:10:04 -0000	1.20
+++ src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java	10 Feb 2011 11:09:34 -0000
@@ -45,6 +45,7 @@
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2;
  
 /**
  * The shared launch configuration delegate for the DSF/GDB debugger.
@@ -279,14 +280,18 @@
 		fIsNonStopSession = LaunchUtils.getIsNonStopMode(configuration);
 		fIsPostMortemTracingSession = LaunchUtils.getIsPostMortemTracing(configuration);
 
-        GdbLaunch launch = new GdbLaunch(configuration, mode, null);
+        GdbLaunch launch = createLaunch(configuration, mode); // new GdbLaunch(configuration, mode, null);
         launch.initialize();
         launch.setSourceLocator(getSourceLocator(configuration, launch.getSession()));
         return launch;
     }
+    
+    protected GdbLaunch createLaunch(ILaunchConfiguration configuration, String mode) {
+    	return new GdbLaunch(configuration, mode, null);
+    }
 
-    private ISourceLocator getSourceLocator(ILaunchConfiguration configuration, DsfSession session) throws CoreException {
-        DsfSourceLookupDirector locator = new DsfSourceLookupDirector(session);
+    protected ISourceLocator getSourceLocator(ILaunchConfiguration configuration, DsfSession session) throws CoreException {
+        IPersistableSourceLocator2 locator = createSourceLocator(configuration, session); // new DsfSourceLookupDirector(session);
         String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null);
         if (memento == null) {
             locator.initializeDefaults(configuration);
@@ -295,6 +300,10 @@
         }
         return locator;
     }
+    
+    protected IPersistableSourceLocator2 createSourceLocator(ILaunchConfiguration configuration, DsfSession session) {
+    	return new DsfSourceLookupDirector(session);
+    }
 	
 	/**
 	 * Returns true if the specified version of GDB supports

Back to the top