Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] The core support of the prompting source locator

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.79
diff -u -r1.79 ChangeLog
--- ChangeLog 17 Dec 2002 19:47:32 -0000 1.79
+++ ChangeLog 17 Dec 2002 19:55:21 -0000
@@ -1,4 +1,13 @@
 2002-12-17 Mikhail Khodjaiants
+ The core support of the prompting source locator.
+ * ICSourceLocator.java
+ * CDebugTarget.java
+ * CDirectorySourceLocation.java
+ * CSourceLocator.java
+ * CSourceManager.java
+ * DisassemblyManager.java
+
+2002-12-17 Mikhail Khodjaiants
  The 'getLineNumber' method of CStackFrame should return the line number associated with the stack frame if the current source locator
  does not implement 'ICSourceLocator'.
  * CStackFrame.java
Index: src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java,v
retrieving revision 1.5
diff -u -r1.5 ICSourceLocator.java
--- src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java 2 Dec 2002 23:22:22 -0000 1.5
+++ src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java 17 Dec 2002 19:55:21 -0000
@@ -5,9 +5,9 @@
  */
 package org.eclipse.cdt.debug.core.sourcelookup;
 
-import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.model.IStackFrame;
 
 /**
  *
@@ -27,17 +27,8 @@
   * @return line number of instruction pointer in this stack frame,
   *      or -1 if line number information is unavailable
   */
- int getLineNumber( IStackFrameInfo frameInfo );
+ int getLineNumber( IStackFrame stackFrame );
 
- /**
-  * Returns a source element that corresponds to the given file name, or
-  * <code>null</code> if a source element could not be located.
-  *
-  * @param fileName the file name for which to locate source
-  * @return an object representing a source element.
-  */
-// Object getSourceElement( String fileName );

  /**
   * Returns the source locations of this locator.
   *
Index: src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java,v
retrieving revision 1.61
diff -u -r1.61 CDebugTarget.java
--- src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 10 Dec 2002 03:46:46 -0000 1.61
+++ src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 17 Dec 2002 19:55:22 -0000
@@ -68,14 +68,13 @@
 import org.eclipse.cdt.debug.internal.core.CMemoryManager;
 import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
 import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
-import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator;
 import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager;
 import org.eclipse.cdt.debug.internal.core.sourcelookup.DisassemblyManager;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarkerDelta;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
@@ -212,7 +211,12 @@
  private CMemoryManager fMemoryManager;
 
  /**
-  * A memory manager for this target.
+  * A disassembly manager for this target.
+  */
+ private DisassemblyManager fDisassemblyManager;
+
+ /**
+  * Whether the debugger process is default.
   */
  private boolean fIsDebuggerProcessDefault = false;
 
@@ -244,14 +248,11 @@
   setCDITarget( cdiTarget );
   setBreakpoints( new HashMap( 5 ) );
   setExecFile( file );
-  if ( getExecFile() != null )
-  {
-   getLaunch().setSourceLocator( createSourceLocator( getExecFile().getProject() ) );
-  }
   setConfiguration( cdiTarget.getSession().getConfiguration() );
   fSupportsTerminate = allowsTerminate & getConfiguration().supportsTerminate();
   fSupportsDisconnect = allowsDisconnect & getConfiguration().supportsDisconnect();
   setThreadList( new ArrayList( 5 ) );
+  setDisassemblyManager( new DisassemblyManager( this ) );
   initialize();
   DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this );
   DebugPlugin.getDefault().getExpressionManager().addExpressionListener( this );
@@ -827,9 +828,9 @@
    return this;
   if ( adapter.equals( ISourceMode.class ) )
   {
-   if ( getSourceLocator() instanceof ISourceMode )
+   if ( getSourceLocator() instanceof IAdaptable )
    {
-    return getSourceLocator();
+    return ((IAdaptable)getSourceLocator()).getAdapter( ISourceMode.class );
    }
   }
   if ( adapter.equals( ICMemoryManager.class ) )
@@ -840,6 +841,8 @@
    return this;
   if ( adapter.equals( IRunToLine.class ) )
    return this;
+  if ( adapter.equals( DisassemblyManager.class ) )
+   return fDisassemblyManager;
   return super.getAdapter( adapter );
  }
  
@@ -1832,12 +1835,6 @@
   return getLaunch().getSourceLocator();
  }
  
- protected ISourceLocator createSourceLocator( IProject project )
- {
-  return new CSourceManager( ( getLaunch().getSourceLocator() != null ) ? getLaunch().getSourceLocator() : new CSourceLocator( project ),
-         new DisassemblyManager( this ) ) ;
- }

  protected void setSourceSearchPath()
  {
   ICDISourceManager mgr = getCDISession().getSourceManager();
@@ -2019,5 +2016,15 @@
         return path;
          }
       };
+ }

+ protected void setDisassemblyManager( DisassemblyManager dm )
+ {
+  fDisassemblyManager = dm;
+ }

+ protected DisassemblyManager getDisassemblyManager()
+ {
+  return fDisassemblyManager;
  }
 }
Index: src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java,v
retrieving revision 1.1
diff -u -r1.1 CDirectorySourceLocation.java
--- src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java 9 Oct 2002 17:56:16 -0000 1.1
+++ src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java 17 Dec 2002 19:55:21 -0000
@@ -26,11 +26,16 @@
 public class CDirectorySourceLocation implements ICSourceLocation
 {
  /**
-  * The directory associated with this source location
+  * The root directory of this source location
   */
  private IPath fDirectory;
 
  /**
+  * The associted path of this source location.
+  */
+ private IPath fAssociation = null;
+
+ /**
   * Constructor for CDirectorySourceLocation.
   */
  public CDirectorySourceLocation( IPath directory )
@@ -38,6 +43,15 @@
   setDirectory( directory );
  }
 
+ /**
+  * Constructor for CDirectorySourceLocation.
+  */
+ public CDirectorySourceLocation( IPath directory, IPath association )
+ {
+  setDirectory( directory );
+  setAssociation( association );
+ }
+
  /* (non-Javadoc)
   * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#findSourceElement(String)
   */
@@ -67,19 +81,17 @@
  }
 
  /**
-  * Sets the directory in which source elements will
-  * be searched for.
+  * Sets the directory in which source elements will be searched for.
   *
   * @param directory a directory
   */
- private void setDirectory( IPath directory )
+ protected void setDirectory( IPath directory )
  {
   fDirectory = directory;
  }
 
  /**
-  * Returns the directory associated with this source
-  * location.
+  * Returns the root directory of this source location.
   *
   * @return directory
   */
@@ -88,29 +100,45 @@
   return fDirectory;
  }
 
+ protected void setAssociation( IPath association )
+ {
+  fAssociation = association;
+ }
+
+ public IPath getAssociation()
+ {
+  return fAssociation;
+ }
+
  private Object findFileByAbsolutePath( String fileName )
  {
   IPath filePath = new Path( fileName );
-  String name = filePath.lastSegment();
-  filePath = filePath.removeLastSegments( 1 );
   IPath path = getDirectory();
-  if ( path.equals( filePath ) )
+  IPath association = getAssociation();
+  if ( path.isPrefixOf( filePath ) )
   {
-   path = path.append( name );
-
-   // Try for a file in another workspace project
-   IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
-   if ( f != null )
-   {
-    return f;
-   }
-
-   File file = path.toFile();
-   if ( file.exists() )
-   {
-    return createExternalFileStorage( path );
-   }
+   filePath = path.append( filePath.removeFirstSegments( path.segmentCount() ) );
+  }
+  else if ( association != null && association.isPrefixOf( filePath ) )
+  {
+   filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
+  }
+  else
+  {
+   return null;
+  }
+  // Try for a file in another workspace project
+  IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( filePath );
+  if ( f != null )
+  {
+   return f;
   }
+
+  File file = filePath.toFile();
+  if ( file.exists() )
+  {
+   return createExternalFileStorage( filePath );
+  }
   return null;
  }
 
Index: src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java,v
retrieving revision 1.4
diff -u -r1.4 CSourceLocator.java
--- src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java 10 Dec 2002 18:25:07 -0000 1.4
+++ src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java 17 Dec 2002 19:55:22 -0000
@@ -15,10 +15,9 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.IPersistableSourceLocator;
 import org.eclipse.debug.core.model.IStackFrame;
 
 /**
@@ -27,7 +26,7 @@
  *
  * @since Aug 19, 2002
  */
-public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator
+public class CSourceLocator implements ICSourceLocator
 {
  /**
   * The array of source locations associated with this locator.
@@ -73,9 +72,10 @@
  /* (non-Javadoc)
   * @see org.eclipse.cdt.debug.core.ICSourceLocator#getLineNumber(IStackFrameInfo)
   */
- public int getLineNumber( IStackFrameInfo frameInfo )
+ public int getLineNumber( IStackFrame frame )
  {
-  return ( frameInfo != null ) ? frameInfo.getFrameLineNumber() : 0;
+  IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
+  return ( info != null ) ? info.getFrameLineNumber() : 0;
  }
 
  protected Object getInput( IStackFrameInfo info )
@@ -86,27 +86,23 @@
    String fileName = info.getFile();
    if ( fileName != null && fileName.length() > 0 )
    {
-    ICSourceLocation[] locations = getSourceLocations();
-    for ( int i = 0; i < locations.length; ++i )
+    result = findFileByAbsolutePath( fileName );
+    if ( result == null )
     {
-     try
+     ICSourceLocation[] locations = getSourceLocations();
+     for ( int i = 0; i < locations.length; ++i )
      {
-      result = locations[i].findSourceElement( fileName );
+      try
+      {
+       result = locations[i].findSourceElement( fileName );
+      }
+      catch( CoreException e )
+      {
+       // do nothing
+      }
+      if ( result != null )
+       break;
      }
-     catch( CoreException e )
-     {
-      // do nothing
-     }
-     if ( result != null )
-      break;
-    }
-   }
-   if ( result == null )
-   {
-    Path path = new Path( fileName );
-    if ( path.isAbsolute() && path.toFile().exists() )
-    {
-     return new FileStorage( path );
     }
    }
   }  
@@ -191,26 +187,20 @@
   }
   return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
  }
-
- /**
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
-  */
- public String getMemento() throws CoreException

+ private Object findFileByAbsolutePath( String fileName )
  {
+  Path path = new Path( fileName );
+  if ( path.isAbsolute() && path.toFile().exists() )
+  {
+   // Try for a file in another workspace project
+   IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
+   if ( f != null )
+   {
+    return f;
+   }
+   return new FileStorage( path );
+  }
   return null;
- }
-
- /**
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
-  */
- public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
- {
- }
-
- /**
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
-  */
- public void initializeFromMemento( String memento ) throws CoreException
- {
  }
 }
Index: src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java,v
retrieving revision 1.5
diff -u -r1.5 CSourceManager.java
--- src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java 2 Dec 2002 23:22:22 -0000 1.5
+++ src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java 17 Dec 2002 19:55:22 -0000
@@ -6,6 +6,9 @@
 
 package org.eclipse.cdt.debug.internal.core.sourcelookup;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+
 import org.eclipse.cdt.debug.core.CDebugCorePlugin;
 import org.eclipse.cdt.debug.core.ICDebugConstants;
 import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
@@ -14,6 +17,7 @@
 import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.model.ISourceLocator;
 import org.eclipse.debug.core.model.IStackFrame;
 
@@ -24,53 +28,44 @@
  */
 public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
 {
- private ISourceLocator fSourceLocator;
- private DisassemblyManager fDisassemblyManager;
+ private ISourceLocator fSourceLocator = null;
  private int fMode = ISourceMode.MODE_SOURCE;
  private int fRealMode = fMode;
+ private ILaunch fLaunch = null;
  
  /**
   * Constructor for CSourceManager.
   */
- public CSourceManager( ISourceLocator sourceLocator, DisassemblyManager disassemblyManager )
+ public CSourceManager( ISourceLocator sourceLocator )
  {
   setSourceLocator( sourceLocator );
-  setDisassemblyManager( disassemblyManager );
  }
 
  /* (non-Javadoc)
   * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getLineNumber(IStackFrameInfo)
   */
- public int getLineNumber( IStackFrameInfo frameInfo )
+ public int getLineNumber( IStackFrame frame )
  {
   if ( getRealMode() == ISourceMode.MODE_SOURCE )
   {
    if ( getCSourceLocator() != null )
    {
-    return getCSourceLocator().getLineNumber( frameInfo );
+    return getCSourceLocator().getLineNumber( frame );
    }
-   if ( frameInfo != null )
+   IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
+   if ( info != null )
    {
-    return frameInfo.getFrameLineNumber();
+    return info.getFrameLineNumber();
    }
   }
-  if ( getRealMode() == ISourceMode.MODE_DISASSEMBLY && getDisassemblyManager() != null )
+  if ( getRealMode() == ISourceMode.MODE_DISASSEMBLY && getDisassemblyManager( frame ) != null )
   {
-   return getDisassemblyManager().getLineNumber( frameInfo );
+   return getDisassemblyManager( frame ).getLineNumber( frame );
   }
   return 0;
  }
 
  /* (non-Javadoc)
-  * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getSourceElement(String)
-  */
-/*
- public Object getSourceElement( String fileName )
- {
-  return ( getCSourceLocator() != null ) ? getCSourceLocator().getSourceElement( fileName ) : null;
- }
-*/
- /* (non-Javadoc)
   * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getSourceLocations()
   */
  public ICSourceLocation[] getSourceLocations()
@@ -146,10 +141,10 @@
   }
   if ( result == null &&
     ( autoDisassembly || getMode() == ISourceMode.MODE_DISASSEMBLY ) &&
-    getDisassemblyManager() != null )
+    getDisassemblyManager( stackFrame ) != null )
   {
    setRealMode( ISourceMode.MODE_DISASSEMBLY );
-   result = getDisassemblyManager().getSourceElement( stackFrame );
+   result = getDisassemblyManager( stackFrame ).getSourceElement( stackFrame );
   }
   else
   {
@@ -167,7 +162,11 @@
  
  protected ISourceLocator getSourceLocator()
  {
-  return fSourceLocator;
+  if ( fSourceLocator != null )
+   return fSourceLocator;
+  else if ( fLaunch != null )
+   return fLaunch.getSourceLocator();
+  return null;
  }
 
  protected void setSourceLocator( ISourceLocator sl )
@@ -175,13 +174,20 @@
   fSourceLocator = sl;
  }
  
- protected void setDisassemblyManager( DisassemblyManager dm )
+ protected DisassemblyManager getDisassemblyManager( IStackFrame stackFrame )
  {
-  fDisassemblyManager = dm;
+  if ( stackFrame != null )
+  {
+   return (DisassemblyManager)stackFrame.getDebugTarget().getAdapter( DisassemblyManager.class );
+  }
+  return null;
  }
-
- protected DisassemblyManager getDisassemblyManager()

+ public void addSourceLocation( ICSourceLocation location )
  {
-  return fDisassemblyManager;
+  ICSourceLocation[] locations = getSourceLocations();
+  ArrayList list = new ArrayList( Arrays.asList( locations ) );
+  list.add( location );
+  setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) );
  }
 }
Index: src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java,v
retrieving revision 1.6
diff -u -r1.6 DisassemblyManager.java
--- src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java 2 Dec 2002 23:22:22 -0000 1.6
+++ src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java 17 Dec 2002 19:55:21 -0000
@@ -39,12 +39,16 @@
   setDebugTarget( target );
  }
 
- public int getLineNumber( IStackFrameInfo frameInfo )
+ public int getLineNumber( IStackFrame frame )
  {
-  DisassemblyStorage storage = getSourceElement( frameInfo );
-  if ( storage != null )
+  IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
+  if ( info != null )
   {
-   return storage.getLineNumber( frameInfo.getAddress() );
+   DisassemblyStorage storage = getSourceElement( info );
+   if ( storage != null )
+   {
+    return storage.getLineNumber( info.getAddress() );
+   }
   }
   return 0;
  }

Back to the top