mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
[299542] Source locators not honored when opening a file by double clicking a Binary child element
This commit is contained in:
parent
8b83105af2
commit
1d6fff500a
1 changed files with 32 additions and 15 deletions
|
@ -22,6 +22,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CCorePreferenceConstants;
|
||||
import org.eclipse.cdt.core.ISourceFinder;
|
||||
import org.eclipse.cdt.core.ISymbolReader;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
|
@ -308,29 +309,40 @@ public class Binary extends Openable implements IBinary {
|
|||
String[] sourceFiles = symbolreader.getSourceFiles();
|
||||
if (sourceFiles != null && sourceFiles.length > 0) {
|
||||
for (String filename : sourceFiles) {
|
||||
File file = new File(filename);
|
||||
try {
|
||||
if (file.exists()) {
|
||||
filename = file.getCanonicalPath();
|
||||
|
||||
// Find the file locally
|
||||
ISourceFinder srcFinder = (ISourceFinder) getAdapter(ISourceFinder.class);
|
||||
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
|
||||
String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), file.getName());
|
||||
if (id == null) {
|
||||
// Don't add files we can't get an ID for.
|
||||
continue;
|
||||
}
|
||||
|
||||
// See if this source file is already in the project.
|
||||
// We check this to determine if we should create a TranslationUnit or ExternalTranslationUnit
|
||||
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()) {
|
||||
wkspFile = element;
|
||||
break;
|
||||
for (IFile element : filesInWP) {
|
||||
if (element.isAccessible()) {
|
||||
wkspFile = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,12 +350,17 @@ public class Binary extends Openable implements IBinary {
|
|||
if (wkspFile != null)
|
||||
tu = new TranslationUnit(this, wkspFile, id);
|
||||
else {
|
||||
IPath path = Path.fromOSString(filename);
|
||||
if (path.toFile().exists()) {
|
||||
tu = new ExternalTranslationUnit(this, path, id);
|
||||
// If we have an absolute path (for the host file system), then use an IPath to create the
|
||||
// ExternalTranslationUnit, as that is the more accurate way to specify the file. If it's
|
||||
// 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 {
|
||||
// filename may be a UNIX path; don't convert to c:\ on Windows.
|
||||
tu = new ExternalTranslationUnit(this, URIUtil.toURI(filename), id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue