Bug 284435 - Executables view opens a workspace file as an ExternalTranslationUnit
Summary: Executables view opens a workspace file as an ExternalTranslationUnit
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug (show other bugs)
Version: 6.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: cdt-debug-inbox@eclipse.org CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-23 11:03 EDT by Philippe Coucaud CLA
Modified: 2020-09-04 15:17 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Coucaud CLA 2009-07-23 11:03:26 EDT
Build ID:  I20090611-1540 + CDT 6.0.0

I have an ISymbolReader which returns paths which are relative to the underlying executable. The code in Executable.getSourceFiles() does support this pattern:

[...]
 // Also check for relative path names and attempt to
 // resolve
 // them relative to the executable.

 boolean fileExists = false;
 try {
   File file = new File(filename);
   fileExists = file.exists();
   if (fileExists) {
     filename = file.getCanonicalPath();
   } else if (filename.startsWith(".")) { //$NON-NLS-1$
     file = new File(executablePath.removeLastSegments(1).toOSString(), filename);
     filename = file.getCanonicalPath();
   }
 } catch (IOException e) { // Do nothing.
 }
[...]

So with an executable having the absolute path /a/b/c/d.exe and a path ../foo.c, 'filename' will be properly resolved to '/a/b/c/foo.c'. Then the code tries to determine which kind of translation unit has to be created for this file:

[...]
  IFile wkspFile = null;
  IFile sourceFile = getProject().getFile(filename);
  IPath sourcePath = new Path(filename);
  if (fileExists) {
    // See if this source file is already in the project.
    // We check this to determine if we should create a
    // TranslationUnit or ExternalTranslationUnit
    if (sourceFile.exists())
      wkspFile = sourceFile;
    else {
     IFile[] filesInWP = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(sourcePath);
     for (int j = 0; j < filesInWP.length; j++) {
       if (filesInWP[j].isAccessible()) {
         wkspFile = filesInWP[j];
         break;
       }
     }
   }
  }
[...]

However 'fileExists' was only set to 'true' if the path was absolute in the first place and isn't updated when 'filename' is recomputed based on the location of the executable. 'wkspFile' is not updated and remains 'null'.

[...]
  if (wkspFile != null)
    tu = new TranslationUnit(cproject, wkspFile, id);
  else
    tu = new ExternalTranslationUnit(cproject, URIUtil.toURI(sourcePath), id);
[...]

Then an external translation unit gets created for a file that is in the workspace (meaning that a different C editor will get created when opening the same C file from outside the Executables view).

If I manually force 'fileExists' to 'true' in the debugger 'wkspFile' is properly computed and a proper translation unit gets created.