1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 22:35:43 +02:00

[299542] Source locators not honored when opening a file by double clicking a Binary child element

This commit is contained in:
John Cortell 2010-01-13 19:17:32 +00:00
parent 8b83105af2
commit 1d6fff500a

View file

@ -22,6 +22,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.ISourceFinder;
import org.eclipse.cdt.core.ISymbolReader; import org.eclipse.cdt.core.ISymbolReader;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
@ -308,29 +309,40 @@ public class Binary extends Openable implements IBinary {
String[] sourceFiles = symbolreader.getSourceFiles(); String[] sourceFiles = symbolreader.getSourceFiles();
if (sourceFiles != null && sourceFiles.length > 0) { if (sourceFiles != null && sourceFiles.length > 0) {
for (String filename : sourceFiles) { for (String filename : sourceFiles) {
File file = new File(filename);
try { // Find the file locally
if (file.exists()) { ISourceFinder srcFinder = (ISourceFinder) getAdapter(ISourceFinder.class);
filename = file.getCanonicalPath(); if (srcFinder != null) {
String localPath = srcFinder.toLocalPath(filename);
if (localPath != null) {
filename = localPath;
} }
} catch (IOException e) { // Do nothing.
} }
// Be careful how you use this File object. If filename is a relative path, the resulting File
// object will apply the relative path to the working directory, which is not what we want.
// Stay away from methods that return or use the absolute path of the object. Note that
// File.isAbsolute() returns false when the object was constructed with a relative path.
File file = new File(filename);
// Create a translation unit for this file and add it as a child of the binary // Create a translation unit for this file and add it as a child of the binary
String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), file.getName()); String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), file.getName());
if (id == null) { if (id == null) {
// Don't add files we can't get an ID for. // Don't add files we can't get an ID for.
continue; continue;
} }
// See if this source file is already in the project. // See if this source file is already in the project.
// We check this to determine if we should create a TranslationUnit or ExternalTranslationUnit // We check this to determine if we should create a TranslationUnit or ExternalTranslationUnit
IFile wkspFile = null; IFile wkspFile = null;
IFile[] filesInWP = ResourceLookup.findFilesForLocation(new Path(filename)); if (file.isAbsolute()) {
IFile[] filesInWP = ResourceLookup.findFilesForLocation(new Path(filename));
for (IFile element : filesInWP) {
if (element.isAccessible()) { for (IFile element : filesInWP) {
wkspFile = element; if (element.isAccessible()) {
break; wkspFile = element;
break;
}
} }
} }
@ -338,12 +350,17 @@ public class Binary extends Openable implements IBinary {
if (wkspFile != null) if (wkspFile != null)
tu = new TranslationUnit(this, wkspFile, id); tu = new TranslationUnit(this, wkspFile, id);
else { else {
IPath path = Path.fromOSString(filename); // If we have an absolute path (for the host file system), then use an IPath to create the
if (path.toFile().exists()) { // ExternalTranslationUnit, as that is the more accurate way to specify the file. If it's
tu = new ExternalTranslationUnit(this, path, id); // not, then use the path specification we got from the debug information. We want to
// avoid, e.g., converting a UNIX path to a Windows one when debugging a UNIX-built binary
// on Windows. The opportunity to remap source paths was taken above, when we called
// ISourceFinder. If a mapping didn't occur, we want to preserve whatever the debug
// information told us. See bugzilla 297781
if (file.isAbsolute()) {
tu = new ExternalTranslationUnit(this, Path.fromOSString(filename), id);
} }
else { else {
// filename may be a UNIX path; don't convert to c:\ on Windows.
tu = new ExternalTranslationUnit(this, URIUtil.toURI(filename), id); tu = new ExternalTranslationUnit(this, URIUtil.toURI(filename), id);
} }
} }