From d06d62c1c20f90862cd3cc8f095c34c0485f6365 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Sun, 19 Oct 2003 01:13:53 +0000 Subject: [PATCH] The real implementation of the parser been move to utils/org/eclipse/cdt/utils/coff/parser and utils/org/eclipse/cdt/utils/elf/parser --- .../core/model/parser/ElfBinaryArchive.java | 105 ------ .../core/model/parser/ElfBinaryFile.java | 346 ------------------ .../internal/core/model/parser/ElfParser.java | 51 +-- .../core/model/parser/PEBinaryArchive.java | 109 ------ .../core/model/parser/PEBinaryFile.java | 304 --------------- .../internal/core/model/parser/PEParser.java | 39 +- .../internal/core/model/parser/Symbol.java | 62 ---- 7 files changed, 17 insertions(+), 999 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryArchive.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryFile.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java deleted file mode 100644 index bb3514be1d0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.eclipse.cdt.internal.core.model.parser; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.utils.elf.AR; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; - -/** - */ -public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive { - - IPath path; - ArrayList children; - long timestamp; - - public ElfBinaryArchive(IPath p) throws IOException { - path = p; - new AR(path.toOSString()).dispose(); // check file type - children = new ArrayList(5); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#getObjects() - */ - public IBinaryObject[] getObjects() { - if (hasChanged()) { - children.clear(); - if (path != null) { - AR ar = null; - try { - ar = new AR(path.toOSString()); - AR.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ElfBinaryFile(path, headers[i]); - children.add(bin); - } - } catch (IOException e) { - //e.printStackTrace(); - } - if (ar != null) { - ar.dispose(); - } - } - children.trimToSize(); - } - return (IBinaryObject[])children.toArray(new IBinaryObject[0]); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() - */ - public IPath getPath() { - return path; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.ARCHIVE; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - try { - return new FileInputStream(path.toFile()); - } catch (IOException e) { - } - return new ByteArrayInputStream(new byte[0]); - } - - boolean hasChanged() { - long modif = path.toFile().lastModified(); - boolean changed = modif != timestamp; - timestamp = modif; - return changed; - } - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[]) - */ - public void add(IBinaryObject[] objs) throws IOException { - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#delete(IBinaryObject[]) - */ - public void delete(IBinaryObject[] objs) throws IOException { - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java deleted file mode 100644 index 7a8480d4320..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java +++ /dev/null @@ -1,346 +0,0 @@ -package org.eclipse.cdt.internal.core.model.parser; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.utils.elf.AR; -import org.eclipse.cdt.utils.elf.Elf; -import org.eclipse.cdt.utils.elf.ElfHelper; -import org.eclipse.cdt.utils.elf.Elf.Attribute; -import org.eclipse.cdt.utils.elf.ElfHelper.Sizes; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; - -/** - */ -public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinaryObject, IBinaryExecutable, IBinaryShared { - IPath path; - AR.ARHeader header; - long timestamp; - String soname; - String[] needed; - Sizes sizes; - Attribute attribute; - ArrayList symbols; - - public ElfBinaryFile(IPath p) throws IOException { - this(p, null); - } - - public ElfBinaryFile(IPath p, AR.ARHeader h) throws IOException { - header = h; - path = p; - loadInformation(); - hasChanged(); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() - */ - public IPath getPath() { - return path; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS() - */ - public long getBSS() { - Sizes sz = getSizes(); - if (sz != null) { - return sizes.bss; - } - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getCPU() - */ - public String getCPU() { - Attribute attr = getAttribute(); - if (attr != null) { - return attribute.getCPU(); - } - return ""; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getData() - */ - public long getData() { - Sizes sz = getSizes(); - if (sz != null) { - return sizes.data; - } - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getText() - */ - public long getText() { - Sizes sz = getSizes(); - if (sz != null) { - return sizes.text; - } - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName() - */ - public String getSoName() { - if (hasChanged()) { - try { - loadInformation(); - } catch (IOException e) { - } - } - if (soname != null) { - return soname; - } - return ""; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#hasDebug() - */ - public boolean hasDebug() { - Attribute attr = getAttribute(); - if (attr != null) { - return attribute.hasDebug(); - } - return false; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#isLittleEndian() - */ - public boolean isLittleEndian() { - Attribute attr = getAttribute(); - if (attr != null) { - return attribute.isLittleEndian(); - } - return false; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs() - */ - public String[] getNeededSharedLibs() { - if (hasChanged()) { - try { - loadInformation(); - } catch (IOException e) { - } - } - if (needed != null) { - return needed; - } - return new String[0]; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - int type = 0; - Attribute attr = getAttribute(); - if (attr != null) { - switch (attribute.getType()) { - case Attribute.ELF_TYPE_EXE : - type = IBinaryFile.EXECUTABLE; - break; - - case Attribute.ELF_TYPE_SHLIB : - type = IBinaryFile.SHARED; - break; - - case Attribute.ELF_TYPE_OBJ : - type = IBinaryFile.OBJECT; - break; - - case Attribute.ELF_TYPE_CORE : - type = IBinaryFile.CORE; - break; - } - } - return type; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols() - */ - public ISymbol[] getSymbols() { - if (hasChanged() || symbols == null) { - if (symbols == null) { - symbols = new ArrayList(5); - } - try { - loadInformation(); - } catch (IOException e) { - } - } - return (ISymbol[]) symbols.toArray(new ISymbol[0]); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - // Archive ? - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } else if (path != null) { - try { - stream = new FileInputStream(path.toFile()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = new ByteArrayInputStream(new byte[0]); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - if (path != null) { - return path.lastSegment().toString(); - } - return ""; - } - - public String toString() { - return getName(); - } - - protected Attribute getAttribute() { - if (hasChanged()) { - try { - loadInformation(); - } catch (IOException e) { - } - } - return attribute; - } - - protected Sizes getSizes() { - if (hasChanged()) { - try { - loadInformation(); - } catch (IOException e) { - } - } - return sizes; - } - - boolean hasChanged() { - long modification = path.toFile().lastModified(); - boolean changed = modification != timestamp; - timestamp = modification; - return changed; - } - - protected ElfHelper getElfHelper() throws IOException { - // Archive ? - if (header != null) { - return new ElfHelper(header.getElf()); - } else if (path != null) { - return new ElfHelper(path.toOSString()); - } - throw new IOException("No file assiocated with Binary"); - } - - protected void loadInformation() throws IOException { - ElfHelper helper = null; - try { - helper = getElfHelper(); - loadInformation(helper); - } finally { - if (helper != null) { - helper.dispose(); - } - } - } - - private void loadInformation(ElfHelper helper) throws IOException { - loadAttributes(helper); - if (symbols != null) { - symbols.clear(); - loadSymbols(helper); - symbols.trimToSize(); - } - } - - private void loadAttributes(ElfHelper helper) throws IOException { - Elf.Dynamic[] sharedlibs = helper.getNeeded(); - needed = new String[sharedlibs.length]; - for (int i = 0; i < sharedlibs.length; i++) { - needed[i] = sharedlibs[i].toString(); - } - sizes = helper.getSizes(); - soname = helper.getSoname(); - attribute = helper.getElf().getAttributes(); - } - - private void loadSymbols(ElfHelper helper) throws IOException { - Elf.Dynamic[] sharedlibs = helper.getNeeded(); - needed = new String[sharedlibs.length]; - for (int i = 0; i < sharedlibs.length; i++) { - needed[i] = sharedlibs[i].toString(); - } - sizes = helper.getSizes(); - soname = helper.getSoname(); - attribute = helper.getElf().getAttributes(); - - addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION); - addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION); - addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE); - addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE); - symbols.trimToSize(); - } - - private void addSymbols(Elf.Symbol[] array, int type) { - for (int i = 0; i < array.length; i++) { - Symbol sym = new Symbol(); - sym.type = type; - sym.name = array[i].toString(); - sym.addr = array[i].st_value; - try { - // This can fail if we use addr2line - // but we can safely ignore the error. - if (header == null) { - sym.filename = array[i].getFilename(); - sym.startLine = array[i].getFuncLineNumber(); - sym.endLine = sym.startLine; - } - } catch (IOException e) { - //e.printStackTrace(); - } - symbols.add(sym); - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfParser.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfParser.java index ffad041aaff..883102ff323 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfParser.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfParser.java @@ -1,42 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002,2003 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ + package org.eclipse.cdt.internal.core.model.parser; -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; - -import org.eclipse.cdt.core.AbstractCExtension; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - /** + * Implementation moved to org.eclipse.cdt.utils.elf.parser.ElfParser + * But this class is still provided for backward compatibility. */ -public class ElfParser extends AbstractCExtension implements IBinaryParser { - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath) - */ - public IBinaryFile getBinary(IPath path) throws IOException { - if (path == null ) { - path = new Path(""); - } - IBinaryFile bFile; - try { - bFile = new ElfBinaryFile(path); - } catch (IOException e) { - bFile = new ElfBinaryArchive(path); - } - return bFile; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser#getFormat() - */ - public String getFormat() { - return "ELF"; - } - +public class ElfParser extends org.eclipse.cdt.utils.elf.parser.ElfParser { } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryArchive.java deleted file mode 100644 index d18f0fd8cd5..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryArchive.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.eclipse.cdt.internal.core.model.parser; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.utils.coff.PEArchive; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; - -/** - */ -public class PEBinaryArchive extends PlatformObject implements IBinaryArchive { - - IPath path; - ArrayList children; - long timestamp; - - public PEBinaryArchive(IPath p) { - path = p; - children = new ArrayList(5); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#getObjects() - */ - public IBinaryObject[] getObjects() { - if (hasChanged()) { - children.clear(); - if (path != null) { - PEArchive ar = null; - try { - ar = new PEArchive(path.toOSString()); - PEArchive.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new PEBinaryFile(path, headers[i].getObjectName()); - children.add(bin); - } - } catch (IOException e) { - //e.printStackTrace(); - } - if (ar != null) { - ar.dispose(); - } - } - children.trimToSize(); - } - return (IBinaryObject[])children.toArray(new IBinaryObject[0]); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() - */ - public IPath getPath() { - return path; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.ARCHIVE; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - try { - return new FileInputStream(path.toFile()); - } catch (IOException e) { - } - return new ByteArrayInputStream(new byte[0]); - } - - boolean hasChanged() { - File file = path.toFile(); - if (file != null && file.exists()) { - long modification = file.lastModified(); - boolean changed = modification != timestamp; - timestamp = modification; - return changed; - } - return false; - } - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[]) - */ - public void add(IBinaryObject[] objs) throws IOException { - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#delete(IBinaryObject[]) - */ - public void delete(IBinaryObject[] objs) throws IOException { - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryFile.java deleted file mode 100644 index 616e289eab0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEBinaryFile.java +++ /dev/null @@ -1,304 +0,0 @@ -package org.eclipse.cdt.internal.core.model.parser; -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.utils.coff.Coff; -import org.eclipse.cdt.utils.coff.PE; -import org.eclipse.cdt.utils.coff.PEArchive; -import org.eclipse.cdt.utils.coff.PE.Attribute; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; - -/** - */ -public class PEBinaryFile extends PlatformObject implements IBinaryFile, - IBinaryObject, IBinaryExecutable, IBinaryShared { - - IPath path; - long timestamp; - PE.Attribute attribute; - String objectName; - ArrayList symbols; - - public PEBinaryFile(IPath p) throws IOException { - this(p, null); - } - - public PEBinaryFile(IPath p, String o) throws IOException { - path = p; - objectName = o; - loadInformation(); - hasChanged(); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && objectName != null) { - PEArchive ar = null; - try { - ar = new PEArchive(path.toOSString()); - PEArchive.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - PEArchive.ARHeader hdr = headers[i]; - if (objectName.equals(hdr.getObjectName())) { - stream = new ByteArrayInputStream(hdr.getObjectData()); - break; - } - } - } catch (IOException e) { - } finally { - if (ar != null) { - ar.dispose(); - } - } - } else if (path != null) { - try { - stream = new FileInputStream (path.toFile()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = new ByteArrayInputStream(new byte[0]); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() - */ - public IPath getPath() { - return path; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - int type = 0; - Attribute attr = getAttribute(); - if (attr != null) { - switch (attribute.getType()) { - case Attribute.PE_TYPE_EXE: - type = IBinaryFile.EXECUTABLE; - break; - - case Attribute.PE_TYPE_SHLIB: - type = IBinaryFile.SHARED; - break; - - case Attribute.PE_TYPE_OBJ: - type = IBinaryFile.OBJECT; - break; - - case Attribute.PE_TYPE_CORE: - type = IBinaryFile.CORE; - break; - } - } - return type; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS() - */ - public long getBSS() { - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getCPU() - */ - public String getCPU() { - Attribute attr = getAttribute(); - if (attr != null) { - return attribute.getCPU(); - } - return ""; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getData() - */ - public long getData() { - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (objectName != null) { - return objectName; - } else if (path != null) { - return path.lastSegment().toString(); - } - return ""; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols() - */ - public ISymbol[] getSymbols() { - if (hasChanged() || symbols == null) { - if (symbols == null) { - symbols = new ArrayList(5); - } - try { - loadInformation(); - } catch (IOException e) { - } - } - return (ISymbol[])symbols.toArray(new ISymbol[0]); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getText() - */ - public long getText() { - return 0; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#hasDebug() - */ - public boolean hasDebug() { - Attribute attr = getAttribute(); - if (attr != null) { - return attr.hasDebug(); - } - return false; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#isLittleEndian() - */ - public boolean isLittleEndian() { - Attribute attr = getAttribute(); - if (attr != null) { - return attr.isLittleEndian(); - } - return false; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs() - */ - public String[] getNeededSharedLibs() { - return new String[0]; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName() - */ - public String getSoName() { - return ""; - } - - protected PE getPE() throws IOException { - if (path != null && objectName != null) { - PE pe = null; - PEArchive ar = null; - try { - ar = new PEArchive(path.toOSString()); - PEArchive.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - PEArchive.ARHeader hdr = headers[i]; - if (objectName.equals(hdr.getObjectName())) { - pe = hdr.getPE(); - break; - } - } - } finally { - if (ar != null) { - ar.dispose(); - } - } - if (pe != null) { - return pe; - } - } else if (path != null) { - return new PE(path.toOSString()); - } - throw new IOException("No file assiocated with Binary"); - } - - protected PE.Attribute getAttribute() { - if (hasChanged()) { - try { - loadInformation(); - } catch (IOException e) { - } - } - return attribute; - } - - protected void loadInformation() throws IOException { - PE pe = getPE(); - loadInformation(pe); - pe.dispose(); - } - - private void loadInformation(PE pe) throws IOException { - loadAttribute(pe); - if (symbols != null) { - symbols.clear(); - loadSymbols(pe); - symbols.trimToSize(); - } - } - - private void loadAttribute(PE pe) throws IOException { - attribute = pe.getAttribute(); - } - - private void loadSymbols(PE pe) throws IOException { - Coff.Symbol[] peSyms = pe.getSymbols(); - byte[] table = pe.getStringTable(); - for (int i = 0; i < peSyms.length; i++) { - if (peSyms[i].isFunction() || peSyms[i].isPointer() ||peSyms[i].isArray()) { - String name = peSyms[i].getName(table); - if (name == null || name.trim().length() == 0 || - !Character.isJavaIdentifierStart(name.charAt(0))) { - continue; - } - Symbol sym = new Symbol(); - sym.filename = null; - sym.name = name; - sym.addr = peSyms[i].n_value; - sym.startLine = 0; - sym.endLine = 0; - sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE; - symbols.add(sym); - } - } - } - - boolean hasChanged() { - File file = path.toFile(); - if (file != null && file.exists()) { - long modification = file.lastModified(); - boolean changed = modification != timestamp; - timestamp = modification; - return changed; - } - return false; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEParser.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEParser.java index b3ef05d34e4..0b092507350 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEParser.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/PEParser.java @@ -5,43 +5,10 @@ package org.eclipse.cdt.internal.core.model.parser; * All Rights Reserved. */ -import java.io.IOException; - -import org.eclipse.cdt.core.AbstractCExtension; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.utils.coff.PE; -import org.eclipse.cdt.utils.coff.PEArchive; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; /** + * Implementation moved to org.eclipse.cdt.utils.coff.parser.PEParser + * But this class is still provided for backward compatibility. */ -public class PEParser extends AbstractCExtension implements IBinaryParser { - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IFile) - */ - public IBinaryFile getBinary(IPath path) throws IOException { - if (path == null) { - path = new Path(""); - } - try { - PE pe = new PE(path.toOSString()); - pe.dispose(); - return new PEBinaryFile(path); - } catch (IOException e) { - } - // Is it an Archive. - PEArchive ar = new PEArchive(path.toOSString()); - ar.dispose(); - return new PEBinaryArchive(path); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser#getFormat() - */ - public String getFormat() { - return "PE"; - } - +public class PEParser extends org.eclipse.cdt.utils.coff.parser.PEParser { } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java deleted file mode 100644 index acfb334c68d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.eclipse.cdt.internal.core.model.parser; - -import org.eclipse.cdt.core.IBinaryParser.ISymbol; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -public class Symbol implements ISymbol { - - public String filename; - public int startLine; - public int endLine; - public long addr; - public String name; - public int type; - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getFilename() - */ - public String getFilename() { - return filename; - } - - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getName() - */ - public String getName() { - return name; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getType() - */ - public int getType() { - return type; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getAdress() - */ - public long getAddress() { - return addr; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getEndLine() - */ - public int getEndLine() { - return endLine; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getStartLine() - */ - public int getStartLine() { - return startLine; - } - -}