diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryContainerAdapter.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryContainerAdapter.java new file mode 100644 index 00000000000..d9ef3b255d1 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryContainerAdapter.java @@ -0,0 +1,265 @@ +package org.eclipse.cdt.internal.core.model.parser; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.util.ArrayList; + +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.internal.core.model.Container; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; + +/** + */ +public class BinaryContainerAdapter extends Container implements IFolder { + + IBinaryArchive archive; + long timestamp; + ArrayList children; + ArrayList phantomResources; + + public BinaryContainerAdapter (IBinaryArchive ar) { + archive = ar; + phantomResources = new ArrayList(0); + children = new ArrayList(5); + } + + /** + * @see org.eclipse.core.resources.IResource#refreshLocal(int, IProgressMonitor) + */ + public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException { + IFile file = archive.getFile(); + if (file != null) { + file.refreshLocal(depth, monitor); + } + } + + /** + * @see org.eclipse.core.resources.IResource#getFullPath() + */ + public IPath getFullPath() { + IFile file = archive.getFile(); + if (file != null) { + return file.getFullPath(); + } + return new Path(""); + } + + /** + * @see org.eclipse.core.resources.IResource#getParent() + */ + public IContainer getParent() { + IFile file = archive.getFile(); + if (file != null) { + return file.getParent(); + } + return null; + } + + /** + * @see org.eclipse.core.resources.IResource#getType() + */ + public int getType() { + return IResource.FOLDER; + } + + /** + * @see org.eclipse.core.resources.IResource#getModificationStamp() + */ + public long getModificationStamp() { + IFile file = archive.getFile(); + if (file != null) { + return file.getModificationStamp(); + } + return 0; + } + + /** + * @see org.eclipse.core.resources.IFolder#delete(boolean, boolean, IProgressMonitor) + */ + public void delete(boolean force, boolean keepHistory, + IProgressMonitor monitor) throws CoreException { + delete((keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IResource#delete(int, IProgressMonitor) + */ + public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException { + IFile file = archive.getFile(); + if (file != null) { + file.delete(updateFlags, monitor); + } + } + + /** + * @see org.eclipse.core.resources.IResource#touch(IProgressMonitor) + */ + public void touch(IProgressMonitor monitor) throws CoreException { + IFile file = archive.getFile(); + if (file != null) { + file.touch(monitor); + } + } + + /** + * @see org.eclipse.core.resources.IFolder#create(boolean, boolean, IProgressMonitor) + */ + public void create(boolean force, boolean local, IProgressMonitor monitor) + throws CoreException { + create((force ? FORCE : IResource.NONE), local, monitor); + } + + /** + * @see org.eclipse.core.resources.IFolder#create(int, boolean, IProgressMonitor) + */ + public void create(int updateFlags, boolean local, + IProgressMonitor monitor) throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IFolder#getFile(String) + */ + public IFile getFile(IPath path) { + IFile f = (IFile)findMember(path); + if (f == null) { + // Pass it to parent to create a fake/phantom if the object + // is not in the archive. + f = getParent().getFile(path); + // Add it to the list of phantoms + if (! phantomResources.contains(f)) { + phantomResources.add(f); + phantomResources.trimToSize(); + } + } + return f; + } + + /** + * @see org.eclipse.core.resources.IFolder#move(IPath, boolean, boolean, IProgressMonitor) + */ + public void move(IPath destination, boolean force, boolean keepHistory, + IProgressMonitor monitor) throws CoreException { + move(destination, (keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IContainer#exists(IPath) + */ + public boolean exists(IPath path) { + // Check if it is the archive. + if (getFullPath().equals(path)) { + IFile file = archive.getFile(); + if (file != null) { + return file.exists(); + } + return false; + } + return findMember(path) != null; + } + + /** + * @see org.eclipse.core.resources.IContainer#getFolder(IPath) + */ + public IFolder getFolder(IPath path) { + // Only Files in the archive pass this to the parent + // to create a phatom resource + IFolder f = getParent().getFolder(path); + if (!phantomResources.contains(f)) { + phantomResources.add(f); + phantomResources.trimToSize(); + } + return f; + } + + /** + * @see org.eclipse.core.resources.IContainer#members(int) + */ + public IResource[] members(int memberFlags) throws CoreException { + final boolean includePhantoms = (memberFlags & IContainer.INCLUDE_PHANTOMS) != 0; + final boolean includeTeamPrivateMember = + (memberFlags & IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS) != 0; + + ArrayList aList = new ArrayList(); + + if (hasChanged()) { + children.clear(); + IBinaryObject[] objects = archive.getObjects(); + for (int i = 0; i < objects.length; i++) { + children.add(new BinaryFileAdapter(this, objects[i])); + } + } + + for (int i = 0; i < children.size(); i++) { + IResource child = (IResource)children.get(i); + if (includeTeamPrivateMember && child.isTeamPrivateMember() || !child.isTeamPrivateMember()) { + aList.add(child); + } + } + + if (includePhantoms) { + aList.addAll(phantomResources); + } + return (IResource[])aList.toArray(new IResource[0]); + } + + /** + * @see org.eclipse.core.resources.IContainer#findDeletedMembersWithHistory(int, IProgressMonitor) + */ + public IFile[] findDeletedMembersWithHistory(int depth, IProgressMonitor monitor) + throws CoreException { + return new IFile[0]; + } + + /** + * @see org.eclipse.core.resources.IResource#getPersistentProperty(QualifiedName) + */ + public String getPersistentProperty(QualifiedName key) throws CoreException { + IFile file = archive.getFile(); + if (file != null) { + return file.getPersistentProperty(key); + } + return null; + } + + /** + * @see org.eclipse.core.resources.IResource#setPersistentProperty(QualifiedName, String) + */ + public void setPersistentProperty(QualifiedName key, String value) throws CoreException { + IFile file = archive.getFile(); + if (file != null) { + file.setPersistentProperty(key, value); + } + } + + /** + * @see org.eclipse.core.resources.IResource#exists() + */ + public boolean exists() { + IFile file = archive.getFile(); + if (file != null) { + return file.exists(); + } + return false; + } + + boolean hasChanged() { + boolean changed; + long modif = getModificationStamp(); + changed = modif != timestamp; + timestamp = modif; + return changed; + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryFileAdapter.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryFileAdapter.java new file mode 100644 index 00000000000..4ce133a767a --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/BinaryFileAdapter.java @@ -0,0 +1,231 @@ +package org.eclipse.cdt.internal.core.model.parser; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.io.InputStream; + +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.internal.core.model.Resource; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFileState; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; + +/** + */ +public class BinaryFileAdapter extends Resource implements IFile { + + IBinaryObject object; + IContainer parent; + + public BinaryFileAdapter(IContainer p, IBinaryObject o) { + object = o; + parent = p; + } + + /** + * @see org.eclipse.core.resources.IFile#appendContents(InputStream, boolean, boolean, IProgressMonitor) + */ + public void appendContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException { + appendContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IFile#appendContents(InputStream, int, IProgressMonitor) + */ + public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) + throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IFile#create(InputStream, boolean, IProgressMonitor) + */ + public void create(InputStream source, boolean force, + IProgressMonitor monitor) throws CoreException { + create(source, (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IFile#create(InputStream, int, IProgressMonitor) + */ + public void create(InputStream source, int updateFlags, + IProgressMonitor monitor) throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IStorage#getContents() + */ + public InputStream getContents() throws CoreException { + return getContents(false); + } + + /** + * @see org.eclipse.core.resources.IFile#getContents(boolean) + */ + public InputStream getContents(boolean force) throws CoreException { + return object.getContents(); + } + + /** + * @see org.eclipse.core.resources.IFile#getEncoding() + */ + public int getEncoding() throws CoreException { + return ENCODING_UNKNOWN; + } + + /** + * @see org.eclipse.core.resources.IFile#getHistory(IProgressMonitor) + */ + public IFileState[] getHistory(IProgressMonitor monitor) + throws CoreException { + return new IFileState[0]; + } + + /** + * @see org.eclipse.core.resources.IFile#move(IPath, boolean, boolean, IProgressMonitor) + */ + public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) + throws CoreException { + move(destination, (keepHistory ? KEEP_HISTORY : IResource.NONE) + | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IFile#setContents(InputStream, boolean, boolean, IProgressMonitor) + */ + public void setContents(InputStream source, boolean force, boolean keepHistory, + IProgressMonitor monitor) throws CoreException { + setContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) + | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IFile#setContents(IFileState, boolean, boolean, IProgressMonitor) + */ + public void setContents(IFileState source, boolean force, boolean keepHistory, + IProgressMonitor monitor) throws CoreException { + setContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) + | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IFile#setContents(InputStream, int, IProgressMonitor) + */ + public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) + throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IFile#setContents(IFileState, int, IProgressMonitor) + */ + public void setContents(IFileState source, int updateFlags, IProgressMonitor monitor) + throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IFile#delete(boolean, boolean, IProgressMonitor) + */ + public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) + throws CoreException { + delete((keepHistory ? KEEP_HISTORY : IResource.NONE) + | (force ? FORCE : IResource.NONE), monitor); + } + + /** + * @see org.eclipse.core.resources.IResource#delete(int, IProgressMonitor) + */ + public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException { + // FIXME: Not implemented. + } + + /** + * @see org.eclipse.core.resources.IResource#getFullPath() + */ + public IPath getFullPath() { + IFile file = object.getFile(); + if (file != null) { + return file.getFullPath().append(object.getName()); + } + return new Path(object.getName()); + } + + /** + * @see org.eclipse.core.resources.IResource#getModificationStamp() + */ + public long getModificationStamp() { + IFile file = object.getFile(); + if (file != null) { + return file.getModificationStamp(); + } + return 0; + } + + /** + * @see org.eclipse.core.resources.IResource#getParent() + */ + public IContainer getParent() { + return parent; + } + + /** + * @see org.eclipse.core.resources.IResource#getType() + */ + public int getType() { + return IResource.FILE; + } + + /** + * @see org.eclipse.core.resources.IResource#refreshLocal(int, IProgressMonitor) + */ + public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException { + IFile file = object.getFile(); + if (file != null) { + file.refreshLocal(depth, monitor); + } + } + + /** + * @see org.eclipse.core.resources.IResource#touch(IProgressMonitor) + */ + public void touch(IProgressMonitor monitor) throws CoreException { + IFile file = object.getFile(); + if (file != null) { + file.touch(monitor); + } + } + + /** + * @see org.eclipse.core.resources.IResource#getPersistentProperty(QualifiedName) + */ + public String getPersistentProperty(QualifiedName key) + throws CoreException { + return null; + } + + /** + * @see org.eclipse.core.resources.IResource#setPersistentProperty(QualifiedName, String) + */ + public void setPersistentProperty(QualifiedName key, String value) + throws CoreException { + } + + /** + * @see org.eclipse.core.resources.IResource#exists() + */ + public boolean exists() { + return parent.exists(new Path(getName())); + } + +} 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 new file mode 100644 index 00000000000..928148cd237 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java @@ -0,0 +1,94 @@ +package org.eclipse.cdt.internal.core.model.parser; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; + +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.utils.elf.AR; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.PlatformObject; + +/** + */ +public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive { + + IFile file; + ArrayList children; + long timestamp; + + public ElfBinaryArchive(IFile f) { + file = f; + children = new ArrayList(5); + } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#getObjects() + */ + public IBinaryObject[] getObjects() { + if (hasChanged()) { + children.clear(); + IPath location = file.getLocation(); + if (location != null) { + AR ar = null; + try { + ar = new AR(location.toOSString()); + AR.ARHeader[] headers = ar.getHeaders(); + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new ElfBinaryFile(file, 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 IFile getFile() { + return file; + } + + /** + * @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 file.getContents(); + } catch (CoreException e) { + } + return new ByteArrayInputStream(new byte[0]); + } + + boolean hasChanged() { + long modif = file.getModificationStamp(); + boolean changed = modif != timestamp; + timestamp = modif; + return changed; + } +} 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 new file mode 100644 index 00000000000..115e8e65d4f --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java @@ -0,0 +1,414 @@ +package org.eclipse.cdt.internal.core.model.parser; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; + +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared; +import org.eclipse.cdt.core.model.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.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.PlatformObject; + +/** + */ +public class ElfBinaryFile extends PlatformObject implements IBinaryFile, + IBinaryObject, IBinaryExecutable, IBinaryShared { + + IFile file; + String objectName; + long timestamp; + String soname; + String[] needed; + Sizes sizes; + Attribute attribute; + ArrayList symbols; + + public class ElfSymbol implements ISymbol { + + String filename; + int lineno; + String name; + int type; + + public ElfSymbol (Elf.Symbol symbol, int t) throws IOException { + filename = symbol.getFilename(); + name = symbol.toString(); + lineno = symbol.getFuncLineNumber(); + type = t; + } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getFilename() + */ + public String getFilename() { + return filename; + } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getLineNumber() + */ + public int getLineNumber() { + return lineno; + } + + /** + * @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; + } + + } + + public ElfBinaryFile(IFile f) throws IOException { + this(f, null, null); + } + + public ElfBinaryFile(IFile f, String n) throws IOException { + this(f, n, null); + } + + public ElfBinaryFile(IFile f, String n, Elf elf) throws IOException { + file = f; + objectName = n; + if (elf != null) { + loadAttributes(new ElfHelper(elf)); + } else { + loadAttributes(); + } + } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() + */ + public IFile getFile() { + return file; + } + + /** + * @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; + } + } + 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 (file != null && objectName != null) { + IPath location = file.getLocation(); + if (location != null) { + AR ar = null; + try { + ar = new AR(file.getLocation().toOSString()); + AR.ARHeader[] headers = ar.getHeaders(); + for (int i = 0; i < headers.length; i++) { + if (objectName.equals(headers[i].getObjectName())) { + stream = new ByteArrayInputStream(headers[i].getObjectData()); + break; + } + } + } catch (IOException e) { + } + if (ar != null) { + ar.dispose(); + } + } + } else if (file != null && file.exists()) { + try { + stream = file.getContents(); + } catch (CoreException e) { + } + } + if (stream == null) { + stream = new ByteArrayInputStream(new byte[0]); + } + return stream; + } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() + */ + public String getName() { + return objectName; + } + + 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 = file.getModificationStamp(); + boolean changed = modification != timestamp; + timestamp = modification; + return changed; + } + + protected ElfHelper getElfHelper() throws IOException { + // Archive ? + if (file != null && file.exists() && objectName != null) { + ElfHelper helper = null; + AR ar = null; + try { + ar = new AR(file.getLocation().toOSString()); + AR.ARHeader[] headers = ar.getHeaders(); + for (int i = 0; i < headers.length; i++) { + if (objectName.equals(headers[i].getObjectName())) { + helper = new ElfHelper(headers[i].getElf()); + break; + } + } + } finally { + if (ar != null) { + ar.dispose(); + } + } + return helper; + } else if (file != null && file.exists()) { + IPath path = file.getLocation(); + if (path == null) { + path = new Path(""); + } + return new ElfHelper(path.toOSString()); + } + throw new IOException("No file assiocated with Binary"); + } + + protected void loadInformation() throws IOException { + loadAttributes(); + if (symbols != null) { + symbols.clear(); + loadSymbols(); + symbols.trimToSize(); + } + } + + protected void loadAttributes() throws IOException { + ElfHelper helper = getElfHelper(); + loadAttributes(helper); + helper.dispose(); + } + + protected 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(); + } + + protected void loadSymbols() throws IOException { + ElfHelper helper = getElfHelper(); + loadSymbols(helper); + helper.dispose(); + } + + protected 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(); + } + + protected void addSymbols(Elf.Symbol[] array, int type) { + for (int i = 0; i < array.length; i++) { + try { + ISymbol sym = new ElfSymbol(array[i], type); + symbols.add(sym); + } catch (IOException e) { + } + } + } + +} 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 new file mode 100644 index 00000000000..5e94e7e5275 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfParser.java @@ -0,0 +1,35 @@ +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.model.IBinaryParser; +import org.eclipse.cdt.utils.elf.AR; +import org.eclipse.cdt.utils.elf.Elf; +import org.eclipse.core.resources.IFile; + +/** + */ +public class ElfParser implements IBinaryParser { + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath) + */ + public IBinaryFile getBinary(IFile file) throws IOException { + try { + Elf e = new Elf(file.getLocation().toOSString()); + e.dispose(); + return new ElfBinaryFile(file); + } catch (IOException e) { + } + // Is it an Archive. + AR ar = new AR(file.getLocation().toOSString()); + ar.dispose(); + return new ElfBinaryArchive(file); + } + +}