1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 20:05:35 +02:00

Bug 341168 - EDC Dwarf Reader shouldn't do source mapping

This commit is contained in:
John Cortell 2011-04-14 20:41:44 +00:00
parent 9782f044c7
commit 4e7d74a6be
3 changed files with 84 additions and 20 deletions

View file

@ -23,6 +23,7 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
public class Util { public class Util {
@ -290,6 +291,43 @@ public class Util {
} }
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, msg, t); return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, msg, t);
} }
/**
* Determines if [filename] is an absolute path specification on the host OS. For example, "c:\some\file"
* will return true on Windows, but false on UNIX. Conversely, "/some/file" will return false on Windows,
* true on Linux. "somefile.txt", "some/file", "./some/file", and "../some/file" will all return false on
* all hosts.
*
* <p>
* UNC paths ("\\some\dir") are recognized as native on Windows.
*
* @param filename
* a file specification. Slashes do not need to be in native format or consistent, except for a
* UNC path, where both prefix slashes must be either forward or backwards.
*/
public static boolean isNativeAbsolutePath(String filename) {
if (Platform.getOS().equals(Platform.OS_WIN32)) {
if (filename.length() > 2) {
// "c:\some\dir"
if (filename.charAt(1) == ':') {
return filename.length() > 3 && isSlash(filename.charAt(2));
}
else {
return filename.startsWith("\\\\") || // UNC //$NON-NLS-1$
filename.startsWith("//"); // UNC converted to forward slashes //$NON-NLS-1$
}
}
return false;
}
else {
// So much simpler on Linux/UNIX (and MacOS now?)
return filename.length() > 1 && isSlash(filename.charAt(0));
}
}
private static boolean isSlash(Character c) {
return c == '\\' || c == '/';
}
} }

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.debug.internal.core.Trace; import org.eclipse.cdt.debug.internal.core.Trace;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit; import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
@ -214,23 +215,29 @@ public class Executable extends PlatformObject {
// case than the actual file system path. Even if the file // case than the actual file system path. Even if the file
// system is not case sensitive this will confuse the Path // system is not case sensitive this will confuse the Path
// class. So make sure the path is canonical, otherwise // class. So make sure the path is canonical, otherwise
// breakpoints won't be resolved, etc.. Also check for relative // breakpoints won't be resolved, etc. Make sure to do this only
// path names and attempt to resolve them relative to the // for files that are specified as an absolute path at this
// executable. // point. Paths that are not absolute can't be trusted to
// java.io.File to canonicalize since that class will
// arbitrarily give the specification a local context, and we
// don't want that. A source file that continues to be
// non-absolute after having been run through source lookups
// (done in remapSourceFile() above) is effectively ambiguous
// and we should leave it that way. Users will need to configure
// a source lookup to give the file a local context if in fact
// the file is available on his machine.
boolean fileExists = false; boolean fileExists = false;
boolean isNativeAbsPath = Util.isNativeAbsolutePath(filename);
if (isNativeAbsPath) {
try { try {
File file = new File(filename); File file = new File(filename);
fileExists = file.exists(); fileExists = file.exists();
if (fileExists) { if (fileExists) {
filename = file.getCanonicalPath(); 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. } catch (IOException e) { // Do nothing.
} }
}
IFile wkspFile = null; IFile wkspFile = null;
IFile sourceFile = getProject().getFile(filename); IFile sourceFile = getProject().getFile(filename);
@ -266,7 +273,7 @@ public class Executable extends PlatformObject {
// Be careful not to convert a unix path like // Be careful not to convert a unix path like
// "/src/home" to "c:\source\home" on Windows. See // "/src/home" to "c:\source\home" on Windows. See
// bugzilla 297781 // bugzilla 297781
URI uri = (sourcePath.toFile().exists()) ? URIUtil.toURI(sourcePath) : URIUtil.toURI(filename, true); URI uri = (isNativeAbsPath && sourcePath.toFile().exists()) ? URIUtil.toURI(sourcePath) : URIUtil.toURI(filename, true);
tu = new ExternalTranslationUnit(cproject, uri, id); tu = new ExternalTranslationUnit(cproject, uri, id);
} }

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.debug.core.executables.ExecutablesManager;
import org.eclipse.cdt.debug.core.executables.IExecutablesChangeListener; import org.eclipse.cdt.debug.core.executables.IExecutablesChangeListener;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput; import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants; import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.util.LRUCache; import org.eclipse.cdt.internal.core.util.LRUCache;
import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -254,13 +255,31 @@ public class SourceFilesViewer extends BaseViewer {
info.location = tu.getLocation(); info.location = tu.getLocation();
if (info.location != null) { if (info.location != null) {
// A source file with a non-absolute path has no local context;
// its location is ambiguous. Converting the IPath to a
// java.io.File would be wrong since that class makes arbitrary
// assumptions about where the file should be locally. See
// similar comment in Executable.getSourceFiles()
if (Util.isNativeAbsolutePath(info.location.toOSString()) ) {
File file = info.location.toFile(); File file = info.location.toFile();
info.exists = file.exists(); info.exists = file.exists();
if (info.exists) {
info.fileLength = file.length(); info.fileLength = file.length();
info.lastModified = file.lastModified(); info.lastModified = file.lastModified();
}
else {
info.fileLength = 0;
info.lastModified = 0;
}
}
else {
info.exists = false;
info.fileLength = 0;
info.lastModified = 0;
}
info.originalLocation = new Path(executable.getOriginalLocation(tu)); info.originalLocation = new Path(executable.getOriginalLocation(tu));
info.originalExists = info.originalLocation.toFile().exists(); info.originalExists = Util.isNativeAbsolutePath(info.originalLocation.toOSString()) && info.originalLocation.toFile().exists();
} else { } else {
info.exists = false; info.exists = false;
info.fileLength = 0; info.fileLength = 0;