From afa454ec63fcc11232e3ff1880dd17d41cb28939 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Mon, 18 May 2009 18:45:37 +0000 Subject: [PATCH] Bug 253170, ELF and GNU ELF parsers incorrectly parse GNUARM executables. --- .../cdt/utils/debug/dwarf/DwarfReader.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java index f6cf6be47fb..97f51a5923a 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java @@ -157,6 +157,11 @@ public class DwarfReader extends Dwarf implements ISymbolReader { if (str.length() == 0) break; dirList.add(str); + // If the directory is relative, append it to the CU dir + IPath dir = new Path(str); + if(!dir.isAbsolute()) + dir = new Path(cuCompDir).append(str); + dirList.add(dir.toString()); } // Read file names @@ -369,7 +374,10 @@ public class DwarfReader extends Dwarf implements ISymbolReader { // Combine dir & name if needed. if (!pa.isAbsolute() && dir.length() > 0) pa = dirPa.append(pa); - + + // Fix cygwin style paths + pa = new Path(fixUpPath(pa.toString())); + // For win32 only. // On Windows, there are cases where the source file itself has the full path // except the drive letter. @@ -394,6 +402,42 @@ public class DwarfReader extends Dwarf implements ISymbolReader { m_fileCollection.add(fullName); } + + private String fixUpPath(String path) { + // some compilers generate extra back slashes + path = path.replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$//$NON-NLS-2$ + + // translate any cygwin drive paths, e.g. //G/System/main.cpp or /cygdrive/c/system/main.c + if (path.startsWith("/cygdrive/") && ('/' == path.charAt(11))) { //$NON-NLS-1$ + char driveLetter = path.charAt(10); + driveLetter = (Character.isLowerCase(driveLetter)) ? Character.toUpperCase(driveLetter) + : driveLetter; + + StringBuffer buf = new StringBuffer(path); + buf.delete(0, 11); + buf.insert(0, driveLetter); + buf.insert(1, ':'); + + path = buf.toString(); + } + + // translate any cygwin drive paths, e.g. //G/System/main.cpp or /cygdrive/c/system/main.c + if (path.startsWith("//") && ('/' == path.charAt(3))) { //$NON-NLS-1$ + char driveLetter = path.charAt(2); + driveLetter = (Character.isLowerCase(driveLetter)) ? Character.toUpperCase(driveLetter) + : driveLetter; + + StringBuffer buf = new StringBuffer(path); + buf.delete(0, 3); + buf.insert(0, driveLetter); + buf.insert(1, ':'); + + path = buf.toString(); + } + + return path; + } + /** * Read a null-ended string from the given "data" stream. * data : IN, byte buffer