From 24cdf54262129f2995e009c581400dc2bfa4d337 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 21 Sep 2004 18:40:44 +0000 Subject: [PATCH] major binary parser cleanup see change log --- core/org.eclipse.cdt.core/ChangeLog | 10 + .../utils/org/eclipse/cdt/utils/AR.java | 329 ++++++ .../org/eclipse/cdt/utils/BinaryFile.java | 30 +- .../cdt/utils/BinaryObjectAdapter.java | 9 +- .../cdt/utils/DefaultCygwinToolFactory.java | 54 + .../cdt/utils/DefaultGnuToolFactory.java | 119 ++ .../utils/{elf => }/ERandomAccessFile.java | 4 +- .../eclipse/cdt/utils/IGnuToolFactory.java | 6 +- .../org/eclipse/cdt/utils/coff/PEArchive.java | 1 + .../cdt/utils/coff/parser/ARMember.java | 86 -- .../coff/parser/CygwinPEBinaryArchive.java | 42 + .../coff/parser/CygwinPEBinaryExecutable.java | 28 + .../coff/parser/CygwinPEBinaryObject.java | 148 ++- .../coff/parser/CygwinPEBinaryShared.java | 28 + .../cdt/utils/coff/parser/CygwinPEParser.java | 186 +-- ...inaryArchive.java => PEBinaryArchive.java} | 35 +- .../utils/coff/parser/PEBinaryExecutable.java | 28 + .../cdt/utils/coff/parser/PEBinaryObject.java | 40 +- .../cdt/utils/coff/parser/PEBinaryShared.java | 28 + .../cdt/utils/coff/parser/PEParser.java | 42 +- .../utils/org/eclipse/cdt/utils/elf/AR.java | 2 + .../utils/org/eclipse/cdt/utils/elf/Elf.java | 1003 ++++++++--------- .../org/eclipse/cdt/utils/elf/ElfHelper.java | 69 +- .../cdt/utils/elf/parser/ARMember.java | 78 -- ...naryArchive.java => ElfBinaryArchive.java} | 24 +- .../utils/elf/parser/ElfBinaryExecutable.java | 23 + .../cdt/utils/elf/parser/ElfBinaryObject.java | 54 +- .../cdt/utils/elf/parser/ElfBinaryShared.java | 25 + .../cdt/utils/elf/parser/ElfParser.java | 33 +- .../utils/elf/parser/GNUElfBinaryArchive.java | 42 + .../elf/parser/GNUElfBinaryExecutable.java | 24 + .../utils/elf/parser/GNUElfBinaryObject.java | 119 +- .../utils/elf/parser/GNUElfBinaryShared.java | 27 + .../cdt/utils/elf/parser/GNUElfParser.java | 150 +-- .../cdt/utils/elf/parser/GNUSymbol.java | 5 +- .../utils/org/eclipse/cdt/utils/macho/AR.java | 8 +- .../eclipse/cdt/utils/macho/MachOHelper.java | 22 +- .../cdt/utils/macho/parser/ARMember.java | 80 -- ...ryArchive.java => MachOBinaryArchive.java} | 30 +- .../macho/parser/MachOBinaryExecutable.java | 28 + .../utils/macho/parser/MachOBinaryObject.java | 47 +- .../utils/macho/parser/MachOBinaryShared.java | 28 + .../cdt/utils/macho/parser/MachOParser.java | 31 +- .../utils/org/eclipse/cdt/utils/som/AR.java | 6 +- .../utils/org/eclipse/cdt/utils/som/SOM.java | 4 +- .../cdt/utils/som/parser/ARMember.java | 107 -- ...naryArchive.java => SOMBinaryArchive.java} | 15 +- .../utils/som/parser/SOMBinaryExecutable.java | 27 + .../cdt/utils/som/parser/SOMBinaryObject.java | 111 +- .../cdt/utils/som/parser/SOMBinaryShared.java | 27 + .../cdt/utils/som/parser/SOMParser.java | 149 +-- .../cdt/utils/som/parser/SomSymbol.java | 2 - .../utils/org/eclipse/cdt/utils/xcoff/AR.java | 25 +- .../org/eclipse/cdt/utils/xcoff/XCoff32.java | 2 +- .../cdt/utils/xcoff/parser/ARMember.java | 107 -- .../cdt/utils/xcoff/parser/XCOFF32Parser.java | 192 +--- ...ryArchive.java => XCOFFBinaryArchive.java} | 14 +- .../xcoff/parser/XCOFFBinaryExecutable.java | 27 + .../utils/xcoff/parser/XCOFFBinaryObject.java | 95 +- .../utils/xcoff/parser/XCOFFBinaryShared.java | 28 + .../cdt/utils/xcoff/parser/XCoffSymbol.java | 2 - 61 files changed, 2204 insertions(+), 1941 deletions(-) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultCygwinToolFactory.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultGnuToolFactory.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/{elf => }/ERandomAccessFile.java (97%) delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryArchive.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryShared.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/{BinaryArchive.java => PEBinaryArchive.java} (61%) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryShared.java delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/{BinaryArchive.java => ElfBinaryArchive.java} (72%) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryShared.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryArchive.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryShared.java delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/ARMember.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/{BinaryArchive.java => MachOBinaryArchive.java} (69%) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryShared.java delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/ARMember.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/{BinaryArchive.java => SOMBinaryArchive.java} (81%) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryShared.java delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/ARMember.java rename core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/{BinaryArchive.java => XCOFFBinaryArchive.java} (81%) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryExecutable.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryShared.java diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index c1267133c20..a60abfda180 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,13 @@ +2004-09-21 David Inglis + + Lots of changes to the binary parsers + - major clean up + - remove lots of duplication + - reuse of AR class + - common GnuToolsFactory + - fixed IBinaryExecutable/IBinaryShared implementors + - improved symbol loading preformance for gnu type parsers. + 2004-09-15 Alain Magloire Jumbo patch from Artyom Kuanbekov diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java new file mode 100644 index 00000000000..0b366f79e35 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java @@ -0,0 +1,329 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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.utils; + + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Vector; + +import org.eclipse.cdt.core.CCorePlugin; + +/** + * The AR class is used for parsing standard ELF archive (ar) files. + * + * Each object within the archive is represented by an ARHeader class. Each of + * of these objects can then be turned into an Elf object for performing Elf + * class operations. + * @see ARHeader + */ +public class AR { + + protected String filename; + protected ERandomAccessFile efile; + protected long strtbl_pos = -1; + private ARHeader[] headers; + + public void dispose() { + try { + if (efile != null) { + efile.close(); + efile = null; + } + } catch (IOException e) { + } + } + + protected void finalize() throws Throwable { + try { + dispose(); + } finally { + super.finalize(); + } + } + + /** + * The ARHeader class is used to store the per-object file + * archive headers. It can also create an Elf object for inspecting + * the object file data. + */ + public class ARHeader { + + private String object_name; + private String modification_time; + private String uid; + private String gid; + private String mode; + private long size; + private long obj_offset; + + /** + * Remove the padding from the archive header strings. + */ + private String removeBlanks(String str) { + while (str.charAt(str.length() - 1) == ' ') + str = str.substring(0, str.length() - 1); + return str; + } + + /** + * Look up the name stored in the archive's string table based + * on the offset given. + * + * Maintains efile file location. + * + * @param offset + * Offset into the string table for first character of the name. + * @throws IOException + * offset not in string table bounds. + */ + private String nameFromStringTable(long offset) throws IOException { + StringBuffer name = new StringBuffer(0); + long pos = efile.getFilePointer(); + + try { + if (strtbl_pos != -1) { + byte temp; + efile.seek(strtbl_pos + offset); + while ((temp = efile.readByte()) != '\n') + name.append((char) temp); + } + } finally { + efile.seek(pos); + } + + return name.toString(); + } + + /** + * Creates a new archive header object. + * + * Assumes that efile is already at the correct location in the file. + * + * @throws IOException + * There was an error processing the header data from the file. + */ + ARHeader() throws IOException { + byte[] object_name = new byte[16]; + byte[] modification_time = new byte[12]; + byte[] uid = new byte[6]; + byte[] gid = new byte[6]; + byte[] mode = new byte[8]; + byte[] size = new byte[10]; + byte[] trailer = new byte[2]; + + // + // Read in the archive header data. Fixed sizes. + // + efile.read(object_name); + efile.read(modification_time); + efile.read(uid); + efile.read(gid); + efile.read(mode); + efile.read(size); + efile.read(trailer); + + // + // Save this location so we can create the Elf object later. + // + obj_offset = efile.getFilePointer(); + + // + // Convert the raw bytes into strings and numbers. + // + this.object_name = removeBlanks(new String(object_name)); + this.modification_time = new String(modification_time); + this.uid = new String(uid); + this.gid = new String(gid); + this.mode = new String(mode); + this.size = Long.parseLong(removeBlanks(new String(size))); + + // + // If the name is of the format "/", get name from the + // string table. + // + if (strtbl_pos != -1 && this.object_name.length() > 1 && this.object_name.charAt(0) == '/') { + try { + long offset = Long.parseLong(this.object_name.substring(1)); + this.object_name = nameFromStringTable(offset); + } catch (java.lang.Exception e) { + } + } + + // + // Strip the trailing / from the object name. + // + int len = this.object_name.length(); + if (len > 2 && this.object_name.charAt(len - 1) == '/') { + this.object_name = this.object_name.substring(0, len - 1); + } + } + + /** Get the name of the object file */ + public String getObjectName() { + return object_name; + } + + /** Get the size of the object file . */ + public long getSize() { + return size; + } + + public String getArchiveName() { + return filename; + } + + public long getObjectDataOffset() { + return obj_offset; + } + + public byte[] getObjectData() throws IOException { + byte[] temp = new byte[(int) size]; + if (efile != null) { + efile.seek(obj_offset); + efile.read(temp); + } else { + efile = new ERandomAccessFile(filename, "r"); //$NON-NLS-1$ + efile.seek(obj_offset); + efile.read(temp); + efile.close(); + efile = null; + } + return temp; + } + } + + public static boolean isARHeader(byte[] ident) { + if (ident.length < 7 + || ident[0] != '!' + || ident[1] != '<' + || ident[2] != 'a' + || ident[3] != 'r' + || ident[4] != 'c' + || ident[5] != 'h' + || ident[6] != '>') + return false; + return true; + } + + /** + * Creates a new AR object from the contents of + * the given file. + * + * @param filename The file to process. + * @throws IOException The file is not a valid archive. + */ + public AR(String filename) throws IOException { + this.filename = filename; + efile = new ERandomAccessFile(filename, "r"); //$NON-NLS-1$ + String hdr = efile.readLine(); + if (hdr == null || hdr.compareTo("!") != 0) { //$NON-NLS-1$ + efile.close(); + throw new IOException(CCorePlugin.getResourceString("Util.exception.invalidArchive")); //$NON-NLS-1$ + } + } + + /** Load the headers from the file (if required). */ + private void loadHeaders() throws IOException { + if (headers != null) + return; + + Vector v = new Vector(); + try { + // + // Check for EOF condition + // + while (efile.getFilePointer() < efile.length()) { + ARHeader header = new ARHeader(); + String name = header.getObjectName(); + + long pos = efile.getFilePointer(); + + // + // If the name starts with a / it is specical. + // + if (name.charAt(0) != '/') + v.add(header); + + // + // If the name is "//" then this is the string table section. + // + if (name.compareTo("//") == 0) //$NON-NLS-1$ + strtbl_pos = pos; + + // + // Compute the location of the next header in the archive. + // + pos += header.getSize(); + if ((pos % 2) != 0) + pos++; + + efile.seek(pos); + } + } catch (IOException e) { + } + headers = (ARHeader[]) v.toArray(new ARHeader[0]); + } + + /** + * Get an array of all the object file headers for this archive. + * + * @throws IOException + * Unable to process the archive file. + * @return An array of headers, one for each object within the archive. + * @see ARHeader + */ + public ARHeader[] getHeaders() throws IOException { + loadHeaders(); + return headers; + } + + private boolean stringInStrings(String str, String[] set) { + for (int i = 0; i < set.length; i++) + if (str.compareTo(set[i]) == 0) + return true; + return false; + } + + public String[] extractFiles(String outdir, String[] names) throws IOException { + Vector names_used = new Vector(); + String object_name; + int count; + + loadHeaders(); + + count = 0; + for (int i = 0; i < headers.length; i++) { + object_name = headers[i].getObjectName(); + if (names != null && !stringInStrings(object_name, names)) + continue; + + object_name = "" + count + "_" + object_name; //$NON-NLS-1$ //$NON-NLS-2$ + count++; + + byte[] data = headers[i].getObjectData(); + File output = new File(outdir, object_name); + names_used.add(object_name); + + RandomAccessFile rfile = new RandomAccessFile(output, "rw"); //$NON-NLS-1$ + rfile.write(data); + rfile.close(); + } + + return (String[]) names_used.toArray(new String[0]); + } + + public String[] extractFiles(String outdir) throws IOException { + return extractFiles(outdir, null); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryFile.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryFile.java index 2dfd718b3b1..e18ae80f16d 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryFile.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryFile.java @@ -25,41 +25,43 @@ import org.eclipse.core.runtime.PlatformObject; */ public abstract class BinaryFile extends PlatformObject implements IBinaryFile { - protected IPath path; - protected long timestamp; - protected IBinaryParser parser; + private final IPath path; + private final IBinaryParser parser; + private final int type; + private long timestamp; - public BinaryFile(IBinaryParser parser, IPath path) { + public BinaryFile(IBinaryParser parser, IPath path, int type) { this.path = path; this.parser = parser; + this.type = type; } - public IBinaryParser getBinaryParser() { + public final IBinaryParser getBinaryParser() { return parser; } /** * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() */ - public IPath getPath() { + public final IPath getPath() { return path; } /** * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() */ - public abstract int getType(); + public final int getType() { + return type; + } /** + * @throws IOException * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() */ - public InputStream getContents() { + public InputStream getContents() throws IOException { InputStream stream = null; if (path != null) { - try { - stream = new FileInputStream(path.toFile()); - } catch (IOException e) { - } + stream = new FileInputStream(path.toFile()); } if (stream == null) { stream = new ByteArrayInputStream(new byte[0]); @@ -70,7 +72,9 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile { protected boolean hasChanged() { long modification = getPath().toFile().lastModified(); boolean changed = modification != timestamp; - timestamp = modification; + if (changed) { + timestamp = modification; + } return changed; } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryObjectAdapter.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryObjectAdapter.java index 119f105b025..431eaf686c2 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryObjectAdapter.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/BinaryObjectAdapter.java @@ -16,16 +16,13 @@ import java.util.Arrays; import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.core.IAddressFactory; import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; import org.eclipse.cdt.core.IBinaryParser.ISymbol; import org.eclipse.core.runtime.IPath; /** */ -public abstract class BinaryObjectAdapter extends BinaryFile implements IBinaryObject, - IBinaryExecutable, IBinaryShared { +public abstract class BinaryObjectAdapter extends BinaryFile implements IBinaryObject { protected ISymbol[] NO_SYMBOLS = new ISymbol[0]; @@ -46,8 +43,8 @@ public abstract class BinaryObjectAdapter extends BinaryFile implements IBinaryO } } - public BinaryObjectAdapter(IBinaryParser parser, IPath path) { - super(parser, path); + public BinaryObjectAdapter(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultCygwinToolFactory.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultCygwinToolFactory.java new file mode 100644 index 00000000000..9bc3a0bbc0b --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultCygwinToolFactory.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils; + +import java.io.IOException; + +import org.eclipse.cdt.core.ICExtension; +import org.eclipse.cdt.core.ICExtensionReference; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + + +public class DefaultCygwinToolFactory extends DefaultGnuToolFactory implements ICygwinToolsFactroy { + + + /** + * + */ + public DefaultCygwinToolFactory(ICExtension ext) { + super(ext); + } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.utils.CygwinToolsProvider#getCygPath() + */ + public CygPath getCygPath() { + IPath cygPathPath = getCygPathPath(); + CygPath cygpath = null; + if (cygPathPath != null && !cygPathPath.isEmpty()) { + try { + cygpath = new CygPath(cygPathPath.toOSString()); + } catch (IOException e1) { + } + } + return cygpath; + } + + protected IPath getCygPathPath() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("cygpath"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = "cygpath"; //$NON-NLS-1$ + } + return new Path(value); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultGnuToolFactory.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultGnuToolFactory.java new file mode 100644 index 00000000000..a0b532b4844 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/DefaultGnuToolFactory.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils; + +import java.io.IOException; + +import org.eclipse.cdt.core.ICExtension; +import org.eclipse.cdt.core.ICExtensionReference; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + + +public class DefaultGnuToolFactory implements IGnuToolFactory { + protected ICExtension fExtension; + + /** + * + */ + public DefaultGnuToolFactory(ICExtension ext) { + fExtension = ext; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.IGnuToolProvider#getAddr2line(org.eclipse.core.runtime.IPath) + */ + public Addr2line getAddr2line(IPath path) { + IPath addr2LinePath = getAddr2linePath(); + Addr2line addr2line = null; + if (addr2LinePath != null && !addr2LinePath.isEmpty()) { + try { + addr2line = new Addr2line(addr2LinePath.toOSString(), path.toOSString()); + } catch (IOException e1) { + } + } + return addr2line; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.IGnuToolProvider#getCPPFilt() + */ + public CPPFilt getCPPFilt() { + IPath cppFiltPath = getCPPFiltPath(); + CPPFilt cppfilt = null; + if (cppFiltPath != null && ! cppFiltPath.isEmpty()) { + try { + cppfilt = new CPPFilt(cppFiltPath.toOSString()); + } catch (IOException e2) { + } + } + return cppfilt; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.IGnuToolProvider#getObjdump(org.eclipse.core.runtime.IPath) + */ + public Objdump getObjdump(IPath path) { + IPath objdumpPath = getObjdumpPath(); + String objdumpArgs = getObjdumpArgs(); + Objdump objdump = null; + if (objdumpPath != null && !objdumpPath.isEmpty()) { + try { + objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString()); + } catch (IOException e1) { + } + } + return objdump; + } + + protected IPath getAddr2linePath() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = "addr2line"; //$NON-NLS-1$ + } + return new Path(value); + } + + protected IPath getObjdumpPath() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("objdump"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = "objdump"; //$NON-NLS-1$ + } + return new Path(value); + } + + protected String getObjdumpArgs() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = ""; //$NON-NLS-1$ + } + return value; + } + + protected IPath getCPPFiltPath() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = "c++filt"; //$NON-NLS-1$ + } + return new Path(value); + } + + protected IPath getStripPath() { + ICExtensionReference ref = fExtension.getExtensionReference(); + String value = ref.getExtensionData("strip"); //$NON-NLS-1$ + if (value == null || value.length() == 0) { + value = "strip"; //$NON-NLS-1$ + } + return new Path(value); + } +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ERandomAccessFile.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/ERandomAccessFile.java similarity index 97% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ERandomAccessFile.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/ERandomAccessFile.java index 41b6efdc20a..813804bfa11 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ERandomAccessFile.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/ERandomAccessFile.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.utils.elf; +package org.eclipse.cdt.utils; import java.io.EOFException; @@ -85,7 +85,7 @@ public class ERandomAccessFile extends RandomAccessFile { super.readFully(bytes); byte tmp = 0; if( isle ) - for(int i=0; i <= bytes.length / 2; i++) + for(int i=0; i < (bytes.length / 2); i++) { tmp = bytes[i]; bytes[i] = bytes[bytes.length - i -1]; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/IGnuToolFactory.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/IGnuToolFactory.java index 3d44cededed..f2b2f467251 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/IGnuToolFactory.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/IGnuToolFactory.java @@ -16,9 +16,9 @@ import org.eclipse.core.runtime.IPath; */ public interface IGnuToolFactory { - public abstract Addr2line getAddr2line(IPath path); + Addr2line getAddr2line(IPath path); - public abstract CPPFilt getCPPFilt(); + CPPFilt getCPPFilt(); - public abstract Objdump getObjdump(IPath path); + Objdump getObjdump(IPath path); } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PEArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PEArchive.java index 4d850956bf2..7ad44c2e443 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PEArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PEArchive.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.CCorePlugin; * Each object within the archive is represented by an ARHeader class. Each of * of these objects can then be turned into an PE object for performing PE * class operations. + * @deprecated - use org.eclipse.cdt.ui.utils.AR * @see ARHeader */ public class PEArchive { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java deleted file mode 100644 index 7a90ca61927..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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.utils.coff.parser; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.Symbol; -import org.eclipse.cdt.utils.coff.Coff; -import org.eclipse.cdt.utils.coff.PE; -import org.eclipse.cdt.utils.coff.PEArchive; -import org.eclipse.core.runtime.IPath; - -/** - */ -public class ARMember extends PEBinaryObject { - PEArchive.ARHeader header; - - public ARMember(IBinaryParser parser, IPath path, PEArchive.ARHeader h) throws IOException { - super(parser, path); - header = h; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = super.getContents(); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - return ""; //$NON-NLS-1$ - } - - protected PE getPE() throws IOException { - if (header != null) { - return header.getPE(); - } - throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$ - } - - protected void addSymbols(Coff.Symbol[] peSyms, byte[] table, List list) { - 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; - } - int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE; - list.add(new Symbol(this, name, type, new Addr32(peSyms[i].n_value), 1)); - } - } - } - -} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryArchive.java new file mode 100644 index 00000000000..9fd84aecb03 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryArchive.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.coff.parser; + +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.utils.AR.ARHeader; +import org.eclipse.core.runtime.IPath; + +public class CygwinPEBinaryArchive extends PEBinaryArchive { + + /** + * @param parser + * @param path + * @throws IOException + */ + public CygwinPEBinaryArchive(PEParser parser, IPath path) throws IOException { + super(parser, path); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.utils.coff.parser.PEBinaryArchive#addArchiveMembers(org.eclipse.cdt.utils.AR.ARHeader[], + * java.util.ArrayList) + */ + protected void addArchiveMembers(ARHeader[] headers, ArrayList children2) { + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new CygwinPEBinaryObject(getBinaryParser(), getPath(), headers[i]); + children.add(bin); + } + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryExecutable.java new file mode 100644 index 00000000000..1bc6f16482b --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryExecutable.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class CygwinPEBinaryExecutable extends CygwinPEBinaryObject implements IBinaryExecutable { + + /** + * @param parser + * @param path + * @param executable + */ + public CygwinPEBinaryExecutable(IBinaryParser parser, IPath path, int executable) { + super(parser, path, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java index beb010fe81d..6330d678a11 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java @@ -15,13 +15,17 @@ import java.math.BigInteger; import java.util.List; import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.ISymbol; import org.eclipse.cdt.utils.Addr2line; import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.CPPFilt; import org.eclipse.cdt.utils.CygPath; +import org.eclipse.cdt.utils.ICygwinToolsFactroy; import org.eclipse.cdt.utils.Objdump; +import org.eclipse.cdt.utils.AR.ARHeader; import org.eclipse.cdt.utils.coff.Coff; +import org.eclipse.cdt.utils.coff.PE; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -30,42 +34,50 @@ import org.eclipse.core.runtime.Path; */ public class CygwinPEBinaryObject extends PEBinaryObject { - private Addr2line addr2line; + private Addr2line autoDisposeAddr2line; + private Addr2line symbolLoadingAddr2line; + private CygPath symbolLoadingCygPath; + private CPPFilt symbolLoadingCPPFilt; + long starttime; /** * @param parser * @param path + * @param header */ - public CygwinPEBinaryObject(CygwinPEParser parser, IPath path) { - super(parser, path); + public CygwinPEBinaryObject(IBinaryParser parser, IPath path, ARHeader header) { + super(parser, path, header); + } + + /** + * @param parser + * @param path + * @param executable + */ + public CygwinPEBinaryObject(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line() - */ - protected Addr2line getAddr2line(boolean autodisposing) { + public Addr2line getAddr2line(boolean autodisposing) { if (!autodisposing) { - CygwinPEParser parser = (CygwinPEParser) getBinaryParser(); - return parser.getAddr2line(getPath()); + return getAddr2line(); } - if (addr2line == null) { - CygwinPEParser parser = (CygwinPEParser) getBinaryParser(); - addr2line = parser.getAddr2line(getPath()); - if (addr2line != null) { - timestamp = System.currentTimeMillis(); + if (autoDisposeAddr2line == null) { + autoDisposeAddr2line = getAddr2line(); + if (autoDisposeAddr2line != null) { + starttime = System.currentTimeMillis(); Runnable worker = new Runnable() { public void run() { - long diff = System.currentTimeMillis() - timestamp; + + long diff = System.currentTimeMillis() - starttime; while (diff < 10000) { try { Thread.sleep(10000); } catch (InterruptedException e) { break; } - diff = System.currentTimeMillis() - timestamp; + diff = System.currentTimeMillis() - starttime; } stopAddr2Line(); } @@ -73,16 +85,24 @@ public class CygwinPEBinaryObject extends PEBinaryObject { new Thread(worker, "Addr2line Reaper").start(); //$NON-NLS-1$ } } else { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); // reset autodispose timeout } - return addr2line; + return autoDisposeAddr2line; } synchronized void stopAddr2Line() { - if (addr2line != null) { - addr2line.dispose(); + if (autoDisposeAddr2line != null) { + autoDisposeAddr2line.dispose(); } - addr2line = null; + autoDisposeAddr2line = null; + } + + private Addr2line getAddr2line() { + ICygwinToolsFactroy factory = (ICygwinToolsFactroy)getAdapter(ICygwinToolsFactroy.class); + if (factory != null) { + return factory.getAddr2line(getPath()); + } + return null; } /* @@ -91,8 +111,11 @@ public class CygwinPEBinaryObject extends PEBinaryObject { * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt() */ protected CPPFilt getCPPFilt() { - CygwinPEParser parser = (CygwinPEParser) getBinaryParser(); - return parser.getCPPFilt(); + ICygwinToolsFactroy factory = (ICygwinToolsFactroy)getAdapter(ICygwinToolsFactroy.class); + if (factory != null) { + return factory.getCPPFilt(); + } + return null; } /* @@ -101,22 +124,29 @@ public class CygwinPEBinaryObject extends PEBinaryObject { * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump() */ protected Objdump getObjdump() { - CygwinPEParser parser = (CygwinPEParser) getBinaryParser(); - return parser.getObjdump(getPath()); + ICygwinToolsFactroy factory = (ICygwinToolsFactroy)getAdapter(ICygwinToolsFactroy.class); + if (factory != null) { + return factory.getObjdump(getPath()); + } + return null; } /** * @return */ protected CygPath getCygPath() { - CygwinPEParser parser = (CygwinPEParser) getBinaryParser(); - return parser.getCygPath(); + ICygwinToolsFactroy factory = (ICygwinToolsFactroy)getAdapter(ICygwinToolsFactroy.class); + if (factory != null) { + return factory.getCygPath(); + } + return null; } /** + * @throws IOException * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() */ - public InputStream getContents() { + public InputStream getContents() throws IOException { InputStream stream = null; Objdump objdump = getObjdump(); if (objdump != null) { @@ -133,6 +163,25 @@ public class CygwinPEBinaryObject extends PEBinaryObject { return stream; } + protected void loadSymbols(PE pe) throws IOException { + symbolLoadingAddr2line = getAddr2line(false); + symbolLoadingCPPFilt = getCPPFilt(); + symbolLoadingCygPath = getCygPath(); + super.loadSymbols(pe); + if (symbolLoadingAddr2line != null) { + symbolLoadingAddr2line.dispose(); + symbolLoadingAddr2line = null; + } + if (symbolLoadingCPPFilt != null) { + symbolLoadingCPPFilt.dispose(); + symbolLoadingCPPFilt = null; + } + if (symbolLoadingCygPath != null) { + symbolLoadingCygPath.dispose(); + symbolLoadingCygPath = null; + } + } + /* * (non-Javadoc) * @@ -140,9 +189,6 @@ public class CygwinPEBinaryObject extends PEBinaryObject { * byte[], java.util.List) */ protected void addSymbols(Coff.Symbol[] peSyms, byte[] table, List list) { - CPPFilt cppfilt = getCPPFilt(); - Addr2line addr2line = getAddr2line(false); - CygPath cygpath = getCygPath(); for (int i = 0; i < peSyms.length; i++) { if (peSyms[i].isFunction() || peSyms[i].isPointer() || peSyms[i].isArray()) { String name = peSyms[i].getName(table); @@ -152,16 +198,17 @@ public class CygwinPEBinaryObject extends PEBinaryObject { int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE; IAddress addr = new Addr32(peSyms[i].n_value); int size = 4; - if (cppfilt != null) { + if (symbolLoadingCPPFilt != null) { try { - name = cppfilt.getFunction(name); + name = symbolLoadingCPPFilt.getFunction(name); } catch (IOException e1) { - cppfilt = null; + symbolLoadingCPPFilt.dispose(); + symbolLoadingCPPFilt = null; } } - if (addr2line != null) { + if (symbolLoadingAddr2line != null) { try { - String filename = addr2line.getFileName(addr); + String filename = symbolLoadingAddr2line.getFileName(addr); // Addr2line returns the funny "??" when it can not find // the file. if (filename != null && filename.equals("??")) { //$NON-NLS-1$ @@ -169,16 +216,22 @@ public class CygwinPEBinaryObject extends PEBinaryObject { } if (filename != null) { - if (cygpath != null) { - filename = cygpath.getFileName(filename); + try { + if (symbolLoadingCygPath != null) { + filename = symbolLoadingCygPath.getFileName(filename); + } + } catch (IOException e) { + symbolLoadingCygPath.dispose(); + symbolLoadingCygPath = null; } } IPath file = filename != null ? new Path(filename) : Path.EMPTY; - int startLine = addr2line.getLineNumber(addr); - int endLine = addr2line.getLineNumber(addr.add(BigInteger.valueOf(size - 1))); + int startLine = symbolLoadingAddr2line.getLineNumber(addr); + int endLine = symbolLoadingAddr2line.getLineNumber(addr.add(BigInteger.valueOf(size - 1))); list.add(new CygwinSymbol(this, name, type, addr, size, file, startLine, endLine)); } catch (IOException e) { - addr2line = null; + symbolLoadingAddr2line.dispose(); + symbolLoadingAddr2line = null; // the symbol still needs to be added list.add(new CygwinSymbol(this, name, type, addr, size)); } @@ -188,15 +241,6 @@ public class CygwinPEBinaryObject extends PEBinaryObject { } } - if (cppfilt != null) { - cppfilt.dispose(); - } - if (cygpath != null) { - cygpath.dispose(); - } - if (addr2line != null) { - addr2line.dispose(); - } } /* diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryShared.java new file mode 100644 index 00000000000..07dd64ef6ee --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryShared.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class CygwinPEBinaryShared extends CygwinPEBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param path + * @param type + */ + protected CygwinPEBinaryShared(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.SHARED); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEParser.java index 8f73afe5114..f6bfcd53feb 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/CygwinPEParser.java @@ -12,19 +12,16 @@ package org.eclipse.cdt.utils.coff.parser; import java.io.IOException; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.utils.Addr2line; -import org.eclipse.cdt.utils.CPPFilt; -import org.eclipse.cdt.utils.CygPath; +import org.eclipse.cdt.utils.DefaultCygwinToolFactory; import org.eclipse.cdt.utils.ICygwinToolsFactroy; -import org.eclipse.cdt.utils.Objdump; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - /** */ -public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy { +public class CygwinPEParser extends PEParser { + + + private DefaultCygwinToolFactory toolFactory; /** * @see org.eclipse.cdt.core.model.IBinaryParser#getFormat() @@ -33,19 +30,20 @@ public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy { return "Cygwin PE"; //$NON-NLS-1$ } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.utils.coff.parser.PEParser#createBinaryArchive(org.eclipse.core.runtime.IPath) + */ + protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { + return new CygwinPEBinaryArchive(this, path); + } /** * @param path * @return */ protected IBinaryExecutable createBinaryExecutable(IPath path) { - return new CygwinPEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new CygwinPEBinaryExecutable(this, path, IBinaryFile.EXECUTABLE); } /** @@ -53,14 +51,7 @@ public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy { * @return */ protected IBinaryObject createBinaryCore(IPath path) { - return new CygwinPEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + return new CygwinPEBinaryObject(this, path, IBinaryFile.CORE); } /** @@ -68,14 +59,7 @@ public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy { * @return */ protected IBinaryObject createBinaryObject(IPath path) { - return new CygwinPEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.OBJECT; - } - }; + return new CygwinPEBinaryObject(this, path, IBinaryFile.OBJECT); } /** @@ -83,129 +67,27 @@ public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy { * @return */ protected IBinaryShared createBinaryShared(IPath path) { - return new CygwinPEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.CygwinToolsProvider#getCygPath() - */ - public CygPath getCygPath() { - IPath cygPathPath = getCygPathPath(); - CygPath cygpath = null; - if (cygPathPath != null && !cygPathPath.isEmpty()) { - try { - cygpath = new CygPath(cygPathPath.toOSString()); - } catch (IOException e1) { - } - } - return cygpath; - } - - protected IPath getCygPathPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("cygpath"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "cygpath"; //$NON-NLS-1$ - } - return new Path(value); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getAddr2line(org.eclipse.core.runtime.IPath) - */ - public Addr2line getAddr2line(IPath path) { - IPath addr2LinePath = getAddr2linePath(); - Addr2line addr2line = null; - if (addr2LinePath != null && !addr2LinePath.isEmpty()) { - try { - addr2line = new Addr2line(addr2LinePath.toOSString(), path.toOSString()); - } catch (IOException e1) { - } - } - return addr2line; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getCPPFilt() - */ - public CPPFilt getCPPFilt() { - IPath cppFiltPath = getCPPFiltPath(); - CPPFilt cppfilt = null; - if (cppFiltPath != null && ! cppFiltPath.isEmpty()) { - try { - cppfilt = new CPPFilt(cppFiltPath.toOSString()); - } catch (IOException e2) { - } - } - return cppfilt; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getObjdump(org.eclipse.core.runtime.IPath) - */ - public Objdump getObjdump(IPath path) { - IPath objdumpPath = getObjdumpPath(); - String objdumpArgs = getObjdumpArgs(); - Objdump objdump = null; - if (objdumpPath != null && !objdumpPath.isEmpty()) { - try { - objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString()); - } catch (IOException e1) { - } - } - return objdump; + return new CygwinPEBinaryShared(this, path); } - protected IPath getAddr2linePath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "addr2line"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getObjdumpPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdump"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "objdump"; //$NON-NLS-1$ - } - return new Path(value); + /** + * @return + */ + protected DefaultCygwinToolFactory createToolFactory() { + return new DefaultCygwinToolFactory(this); } - protected String getObjdumpArgs() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = ""; //$NON-NLS-1$ + /* (non-Javadoc) + * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.equals(ICygwinToolsFactroy.class)) { + if (toolFactory == null) { + toolFactory = createToolFactory(); + } + return toolFactory; } - return value; + // TODO Auto-generated method stub + return super.getAdapter(adapter); } - - protected IPath getCPPFiltPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "c++filt"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getStripPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("strip"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "strip"; //$NON-NLS-1$ - } - return new Path(value); - } - -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryArchive.java similarity index 61% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryArchive.java index 7a1f10cdc33..58f017e26f7 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryArchive.java @@ -14,23 +14,23 @@ package org.eclipse.cdt.utils.coff.parser; import java.io.IOException; import java.util.ArrayList; -import org.eclipse.cdt.core.IBinaryParser; 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.AR; import org.eclipse.cdt.utils.BinaryFile; -import org.eclipse.cdt.utils.coff.PEArchive; +import org.eclipse.cdt.utils.AR.ARHeader; import org.eclipse.core.runtime.IPath; /** */ -public class BinaryArchive extends BinaryFile implements IBinaryArchive { +public class PEBinaryArchive extends BinaryFile implements IBinaryArchive { ArrayList children; - public BinaryArchive(IBinaryParser parser, IPath path) throws IOException { - super(parser, path); - new PEArchive(path.toOSString()).dispose(); // check file type + public PEBinaryArchive(PEParser parser, IPath path) throws IOException { + super(parser, path, IBinaryFile.ARCHIVE); + new AR(path.toOSString()).dispose(); // check file type children = new ArrayList(5); } @@ -40,14 +40,11 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { public IBinaryObject[] getObjects() { if (hasChanged()) { children.clear(); - PEArchive ar = null; + AR ar = null; try { - ar = new PEArchive(getPath().toOSString()); - PEArchive.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ARMember(getBinaryParser(), path, headers[i]); - children.add(bin); - } + ar = new AR(getPath().toOSString()); + AR.ARHeader[] headers = ar.getHeaders(); + addArchiveMembers(headers, children); } catch (IOException e) { //e.printStackTrace(); } @@ -56,13 +53,17 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { } children.trimToSize(); } - return (IBinaryObject[])children.toArray(new IBinaryObject[0]); + return (IBinaryObject[]) children.toArray(new IBinaryObject[0]); } /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() + * @param headers + * @param children2 */ - public int getType() { - return IBinaryFile.ARCHIVE; + protected void addArchiveMembers(ARHeader[] headers, ArrayList children2) { + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new PEBinaryObject(getBinaryParser(), getPath(), headers[i]); + children.add(bin); + } } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryExecutable.java new file mode 100644 index 00000000000..7f5f6320343 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryExecutable.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class PEBinaryExecutable extends PEBinaryObject implements IBinaryExecutable { + + /** + * @param parser + * @param path + * @param isCorefile + */ + public PEBinaryExecutable(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java index 09686dc9815..e32b9f92af6 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.utils.coff.parser; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,6 +20,7 @@ import java.util.List; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.ISymbol; +import org.eclipse.cdt.utils.AR; import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.Symbol; @@ -31,18 +34,36 @@ public class PEBinaryObject extends BinaryObjectAdapter { BinaryObjectInfo info; ISymbol[] symbols; + AR.ARHeader header; - public PEBinaryObject(IBinaryParser parser, IPath path) { - super(parser, path); + public PEBinaryObject(IBinaryParser parser, IPath path, AR.ARHeader header) { + super(parser, path, IBinaryFile.OBJECT); } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() + + public PEBinaryObject(IBinaryParser parser, IPath p, int type) { + super(parser, p, type); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName() */ - public int getType() { - return IBinaryFile.OBJECT; - } + public String getName() { + if (header != null) { + return header.getObjectName(); + } + return super.getName(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getContents() + */ + public InputStream getContents() throws IOException { + if (getPath() != null && header != null) { + return new ByteArrayInputStream(header.getObjectData()); + } + return super.getContents(); + } + /** * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols() */ @@ -74,6 +95,9 @@ public class PEBinaryObject extends BinaryObjectAdapter { } protected PE getPE() throws IOException { + if (header != null) { + return new PE(getPath().toOSString(), header.getObjectDataOffset()); + } return new PE(getPath().toOSString()); } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryShared.java new file mode 100644 index 00000000000..e5478d30d52 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEBinaryShared.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class PEBinaryShared extends PEBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param p + * @param type + */ + public PEBinaryShared(IBinaryParser parser, IPath p) { + super(parser, p, IBinaryFile.SHARED); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java index ae33fc785cd..50f63c09d84 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java @@ -17,8 +17,8 @@ import java.io.IOException; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.utils.AR; import org.eclipse.cdt.utils.coff.PE; -import org.eclipse.cdt.utils.coff.PEArchive; import org.eclipse.cdt.utils.coff.PEConstants; import org.eclipse.cdt.utils.coff.PE.Attribute; import org.eclipse.core.resources.IFile; @@ -96,7 +96,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], org.eclipse.core.runtime.IPath) */ public boolean isBinary(byte[] array, IPath path) { - boolean isBin = PE.isExeHeader(array) || PEArchive.isARHeader(array); + boolean isBin = PE.isExeHeader(array) || AR.isARHeader(array); // It maybe an object file try the known machine types. if (!isBin && array.length > 1) { int f_magic = (((array[1] & 0xff) << 8) | (array[0] & 0xff)); @@ -137,14 +137,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryExecutable createBinaryExecutable(IPath path) { - return new PEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new PEBinaryExecutable(this, path); } /** @@ -152,14 +145,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryObject createBinaryCore(IPath path) { - return new PEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + return new PEBinaryObject(this, path, IBinaryFile.CORE); } /** @@ -167,14 +153,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryObject createBinaryObject(IPath path) { - return new PEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.OBJECT; - } - }; + return new PEBinaryObject(this, path, IBinaryFile.OBJECT); } /** @@ -182,14 +161,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryShared createBinaryShared(IPath path) { - return new PEBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + return new PEBinaryShared(this, path); } /** @@ -197,7 +169,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { - return new BinaryArchive(this, path); + return new PEBinaryArchive(this, path); } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java index c25fe3d9690..fbaf34e4c89 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java @@ -17,6 +17,7 @@ import java.io.RandomAccessFile; import java.util.Vector; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.utils.ERandomAccessFile; /** * The AR class is used for parsing standard ELF archive (ar) files. @@ -24,6 +25,7 @@ import org.eclipse.cdt.core.CCorePlugin; * Each object within the archive is represented by an ARHeader class. Each of * of these objects can then be turned into an Elf object for performing Elf * class operations. + * @deprecated use org.eclipse.cdt.utils.AR * @see ARHeader */ public class AR { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index 6fd3d7a1e83..4b79fe277c5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -1,16 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 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 + * Copyright (c) 2000, 2004 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 - *******************************************************************************/ + * Contributors: QNX Software Systems - Initial API and implementation + ******************************************************************************/ package org.eclipse.cdt.utils.elf; - import java.io.EOFException; import java.io.IOException; import java.util.ArrayList; @@ -24,40 +21,42 @@ import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.Addr32Factory; import org.eclipse.cdt.utils.Addr64; import org.eclipse.cdt.utils.Addr64Factory; +import org.eclipse.cdt.utils.ERandomAccessFile; // test checkin public class Elf { + public final static int ELF32_ADDR_SIZE = 4; public final static int ELF32_OFF_SIZE = 4; public final static int ELF64_ADDR_SIZE = 8; public final static int ELF64_OFF_SIZE = 8; - - protected ERandomAccessFile efile; + + protected ERandomAccessFile efile; protected ELFhdr ehdr; protected Section[] sections; protected String file; - protected byte[] section_strtab; + protected byte[] section_strtab; private int syms = 0; private Symbol[] symbols; - private Symbol[] symtab_symbols; - private Section symtab_sym; - private Symbol[] dynsym_symbols; - private Section dynsym_sym; + private Symbol[] symtab_symbols; + private Section symtab_sym; + private Symbol[] dynsym_symbols; + private Section dynsym_sym; protected String EMPTY_STRING = ""; //$NON-NLS-1$ - public class ELFhdr { + /* e_ident offsets */ public final static int EI_MAG0 = 0; public final static int EI_MAG1 = 1; public final static int EI_MAG2 = 2; public final static int EI_MAG3 = 3; public final static int EI_CLASS = 4; - public final static int EI_DATA = 5; - public final static int EI_VERSION = 6; + public final static int EI_DATA = 5; + public final static int EI_VERSION = 6; public final static int EI_PAD = 7; public final static int EI_NDENT = 16; @@ -70,8 +69,8 @@ public class Elf { public final static int ELFDATANONE = 0; public final static int ELFDATA2LSB = 1; public final static int ELFDATA2MSB = 2; - - /* values of e_type */ + + /* values of e_type */ public final static int ET_NONE = 0; public final static int ET_REL = 1; public final static int ET_EXEC = 2; @@ -79,7 +78,7 @@ public class Elf { public final static int ET_CORE = 4; public final static int ET_LOPROC = 0xff00; public final static int ET_HIPROC = 0xffff; - + /* values of e_machine */ public final static int EM_NONE = 0; public final static int EM_M32 = 1; @@ -105,7 +104,7 @@ public class Elf { public final static int EM_H8_300H = 47; public final static int EM_IA_64 = 50; public final static int EM_AVR = 83; - public final static int EM_FR30 = 84; /* Fujitsu FR30 */ + public final static int EM_FR30 = 84; /* Fujitsu FR30 */ public final static int EM_V850 = 87; public final static int EM_M32R = 88; public final static int EM_MN10300 = 89; @@ -124,54 +123,51 @@ public class Elf { public final static int EM_CYGNUS_FRV = 0x5441; public final static int EM_IQ2000 = 0xFEBA; - public byte e_ident[] = new byte[EI_NDENT]; - public int e_type; /* file type (Elf32_Half) */ - public int e_machine; /* machine type (Elf32_Half) */ - public long e_version; /* version number (Elf32_Word) */ - public IAddress e_entry; /* entry point (Elf32_Addr)*/ - public long e_phoff; /* Program hdr offset (Elf32_Off)*/ - public long e_shoff; /* Section hdr offset (Elf32_Off)*/ - public long e_flags; /* Processor flags (Elf32_Word)*/ - public short e_ehsize; /* sizeof ehdr (Elf32_Half)*/ - public short e_phentsize; /* Program header entry size (Elf32_Half)*/ - public short e_phnum; /* Number of program headers (Elf32_Half)*/ - public short e_shentsize; /* Section header entry size (Elf32_Half)*/ - public short e_shnum; /* Number of section headers (Elf32_Half)*/ - public short e_shstrndx; /* String table index (Elf32_Half)*/ + public byte e_ident[] = new byte[EI_NDENT]; + public int e_type; /* file type (Elf32_Half) */ + public int e_machine; /* machine type (Elf32_Half) */ + public long e_version; /* version number (Elf32_Word) */ + public IAddress e_entry; /* entry point (Elf32_Addr) */ + public long e_phoff; /* Program hdr offset (Elf32_Off) */ + public long e_shoff; /* Section hdr offset (Elf32_Off) */ + public long e_flags; /* Processor flags (Elf32_Word) */ + public short e_ehsize; /* sizeof ehdr (Elf32_Half) */ + public short e_phentsize; /* Program header entry size (Elf32_Half) */ + public short e_phnum; /* Number of program headers (Elf32_Half) */ + public short e_shentsize; /* Section header entry size (Elf32_Half) */ + public short e_shnum; /* Number of section headers (Elf32_Half) */ + public short e_shstrndx; /* String table index (Elf32_Half) */ protected ELFhdr() throws IOException { efile.seek(0); efile.readFully(e_ident); - if ( e_ident[ELFhdr.EI_MAG0] != 0x7f || e_ident[ELFhdr.EI_MAG1] != 'E' || - e_ident[ELFhdr.EI_MAG2] != 'L' || e_ident[ELFhdr.EI_MAG3] != 'F' ) + if (e_ident[ELFhdr.EI_MAG0] != 0x7f || e_ident[ELFhdr.EI_MAG1] != 'E' || e_ident[ELFhdr.EI_MAG2] != 'L' + || e_ident[ELFhdr.EI_MAG3] != 'F') throw new IOException(CCorePlugin.getResourceString("Util.exception.notELF")); //$NON-NLS-1$ efile.setEndian(e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB); e_type = efile.readShortE(); e_machine = efile.readShortE(); e_version = efile.readIntE(); - switch (e_ident[ELFhdr.EI_CLASS]) - { - case ELFhdr.ELFCLASS32: - { + switch (e_ident[ELFhdr.EI_CLASS]) { + case ELFhdr.ELFCLASS32 : { byte[] addrArray = new byte[ELF32_ADDR_SIZE]; efile.readFullyE(addrArray); e_entry = new Addr32(addrArray); - e_phoff = efile.readIntE(); - e_shoff = efile.readIntE(); + e_phoff = efile.readIntE(); + e_shoff = efile.readIntE(); } - break; - case ELFhdr.ELFCLASS64: - { + break; + case ELFhdr.ELFCLASS64 : { byte[] addrArray = new byte[ELF64_ADDR_SIZE]; efile.readFullyE(addrArray); e_entry = new Addr64(addrArray); e_phoff = readUnsignedLong(efile); e_shoff = readUnsignedLong(efile); } - break; - case ELFhdr.ELFCLASSNONE: - default: - throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); + break; + case ELFhdr.ELFCLASSNONE : + default : + throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ } e_flags = efile.readIntE(); e_ehsize = efile.readShortE(); @@ -181,112 +177,118 @@ public class Elf { e_shnum = efile.readShortE(); e_shstrndx = efile.readShortE(); } - - protected ELFhdr(byte [] bytes) throws IOException { - if(bytes.length <= e_ident.length) { + + protected ELFhdr(byte[] bytes) throws IOException { + if (bytes.length <= e_ident.length) { throw new EOFException(CCorePlugin.getResourceString("Util.exception.notELF")); //$NON-NLS-1$ } System.arraycopy(bytes, 0, e_ident, 0, e_ident.length); - if ( e_ident[ELFhdr.EI_MAG0] != 0x7f || e_ident[ELFhdr.EI_MAG1] != 'E' || - e_ident[ELFhdr.EI_MAG2] != 'L' || e_ident[ELFhdr.EI_MAG3] != 'F' ) + if (e_ident[ELFhdr.EI_MAG0] != 0x7f || e_ident[ELFhdr.EI_MAG1] != 'E' || e_ident[ELFhdr.EI_MAG2] != 'L' + || e_ident[ELFhdr.EI_MAG3] != 'F') throw new IOException(CCorePlugin.getResourceString("Util.exception.notELF")); //$NON-NLS-1$ boolean isle = (e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB); int offset = e_ident.length; - e_type = makeShort(bytes, offset, isle); offset += 2; - e_machine = makeShort(bytes, offset, isle); offset += 2; - e_version = makeInt(bytes, offset, isle); offset += 4; - switch (e_ident[ELFhdr.EI_CLASS]) - { - case ELFhdr.ELFCLASS32: - { + e_type = makeShort(bytes, offset, isle); + offset += 2; + e_machine = makeShort(bytes, offset, isle); + offset += 2; + e_version = makeInt(bytes, offset, isle); + offset += 4; + switch (e_ident[ELFhdr.EI_CLASS]) { + case ELFhdr.ELFCLASS32 : { byte[] addrArray = new byte[ELF32_ADDR_SIZE]; - System.arraycopy(bytes, offset, addrArray, 0, ELF32_ADDR_SIZE); offset += ELF32_ADDR_SIZE; + System.arraycopy(bytes, offset, addrArray, 0, ELF32_ADDR_SIZE); + offset += ELF32_ADDR_SIZE; e_entry = new Addr32(addrArray); - e_phoff = makeInt(bytes, offset, isle); offset += ELF32_OFF_SIZE; - e_shoff = makeInt(bytes, offset, isle); offset += ELF32_OFF_SIZE; + e_phoff = makeInt(bytes, offset, isle); + offset += ELF32_OFF_SIZE; + e_shoff = makeInt(bytes, offset, isle); + offset += ELF32_OFF_SIZE; } - break; - case ELFhdr.ELFCLASS64: - { + break; + case ELFhdr.ELFCLASS64 : { byte[] addrArray = new byte[ELF64_ADDR_SIZE]; - System.arraycopy(bytes, offset, addrArray, 0, ELF64_ADDR_SIZE); offset += ELF64_ADDR_SIZE; + System.arraycopy(bytes, offset, addrArray, 0, ELF64_ADDR_SIZE); + offset += ELF64_ADDR_SIZE; e_entry = new Addr64(addrArray); - e_phoff = makeUnsignedLong(bytes, offset, isle); offset += ELF64_OFF_SIZE; - e_shoff = makeUnsignedLong(bytes, offset, isle); offset += ELF64_OFF_SIZE; + e_phoff = makeUnsignedLong(bytes, offset, isle); + offset += ELF64_OFF_SIZE; + e_shoff = makeUnsignedLong(bytes, offset, isle); + offset += ELF64_OFF_SIZE; } - break; - case ELFhdr.ELFCLASSNONE: - default: - throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); + break; + case ELFhdr.ELFCLASSNONE : + default : + throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ } - e_flags = makeInt(bytes, offset, isle); offset += 4; - e_ehsize = makeShort(bytes, offset, isle); offset += 2; - e_phentsize = makeShort(bytes, offset, isle); offset += 2; - e_phnum = makeShort(bytes, offset, isle); offset += 2; - e_shentsize = makeShort(bytes, offset, isle); offset += 2; - e_shnum = makeShort(bytes, offset, isle); offset += 2; - e_shstrndx = makeShort(bytes, offset, isle); offset += 2; - } - - private final short makeShort(byte [] val, int offset, boolean isle) throws IOException { - if (val.length < offset + 2) - throw new IOException(); - if ( isle ) { - return (short)((val[offset + 1] << 8) + val[offset + 0]); - } - return (short)((val[offset + 0] << 8) + val[offset + 1]); - } - - private final long makeInt(byte [] val, int offset, boolean isle) throws IOException - { - if (val.length < offset + 4) - throw new IOException(); - if ( isle ) { - return ((val[offset + 3] << 24) + (val[offset + 2] << 16) + (val[offset + 1] << 8) + val[offset + 0]); - } - return ((val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]); + e_flags = makeInt(bytes, offset, isle); + offset += 4; + e_ehsize = makeShort(bytes, offset, isle); + offset += 2; + e_phentsize = makeShort(bytes, offset, isle); + offset += 2; + e_phnum = makeShort(bytes, offset, isle); + offset += 2; + e_shentsize = makeShort(bytes, offset, isle); + offset += 2; + e_shnum = makeShort(bytes, offset, isle); + offset += 2; + e_shstrndx = makeShort(bytes, offset, isle); + offset += 2; } - private final long makeLong(byte [] val, int offset, boolean isle) throws IOException - { + private final short makeShort(byte[] val, int offset, boolean isle) throws IOException { + if (val.length < offset + 2) + throw new IOException(); + if (isle) { + return (short) ( (val[offset + 1] << 8) + val[offset + 0]); + } + return (short) ( (val[offset + 0] << 8) + val[offset + 1]); + } + + private final long makeInt(byte[] val, int offset, boolean isle) throws IOException { + if (val.length < offset + 4) + throw new IOException(); + if (isle) { + return ( (val[offset + 3] << 24) + (val[offset + 2] << 16) + (val[offset + 1] << 8) + val[offset + 0]); + } + return ( (val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]); + } + + private final long makeLong(byte[] val, int offset, boolean isle) throws IOException { long result = 0; int shift = 0; - if ( isle ) - for(int i=7; i >= 0; i-- ) - { - shift = i*8; - result += ( ((long)val[offset + i]) << shift ) & ( 0xffL << shift ); + if (isle) + for (int i = 7; i >= 0; i--) { + shift = i * 8; + result += ( ((long)val[offset + i]) << shift) & (0xffL << shift); } else - for(int i=0; i <= 7; i++ ) - { - shift = (7-i)*8; - result += ( ((long)val[offset + i]) << shift ) & ( 0xffL << shift ); + for (int i = 0; i <= 7; i++) { + shift = (7 - i) * 8; + result += ( ((long)val[offset + i]) << shift) & (0xffL << shift); } return result; } - - private final long makeUnsignedLong(byte [] val, int offset, boolean isle) throws IOException - { - long result = makeLong(val,offset,isle); - if(result < 0) - { - throw new IOException( "Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + - " given offset is " + Long.toHexString(result)); - } - return result; + + private final long makeUnsignedLong(byte[] val, int offset, boolean isle) throws IOException { + long result = makeLong(val, offset, isle); + if (result < 0) { + throw new IOException("Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + //$NON-NLS-1$ + " given offset is " + Long.toHexString(result)); //$NON-NLS-1$ + } + return result; } - - - + } - public class Section { + public class Section { + /* sh_type */ public final static int SHT_NULL = 0; public final static int SHT_PROGBITS = 1; - public final static int SHT_SYMTAB = 2; + public final static int SHT_SYMTAB = 2; public final static int SHT_STRTAB = 3; public final static int SHT_RELA = 4; public final static int SHT_HASH = 5; @@ -296,14 +298,14 @@ public class Elf { public final static int SHT_REL = 9; public final static int SHT_SHLIB = 10; public final static int SHT_DYNSYM = 11; - + public final static int SHT_LOPROC = 0x70000000; - + /* sh_flags */ public final static int SHF_WRITE = 1; public final static int SHF_ALLOC = 2; public final static int SHF_EXECINTR = 4; - + public long sh_name; public long sh_type; public long sh_flags; @@ -315,30 +317,30 @@ public class Elf { public long sh_addralign; public long sh_entsize; - public byte[] loadSectionData() throws IOException { - byte[] data = new byte[(int)sh_size]; - efile.seek( sh_offset ); - efile.read( data ); - return data; - } + public byte[] loadSectionData() throws IOException { + byte[] data = new byte[(int)sh_size]; + efile.seek(sh_offset); + efile.read(data); + return data; + } public String toString() { try { - if ( section_strtab == null ) { - if ( ehdr.e_shstrndx > sections.length || ehdr.e_shstrndx < 0) + if (section_strtab == null) { + if (ehdr.e_shstrndx > sections.length || ehdr.e_shstrndx < 0) return EMPTY_STRING; int size = (int)sections[ehdr.e_shstrndx].sh_size; - if ( size <= 0 || size > efile.length() ) + if (size <= 0 || size > efile.length()) return EMPTY_STRING; section_strtab = new byte[size]; efile.seek(sections[ehdr.e_shstrndx].sh_offset); efile.read(section_strtab); } int str_size = 0; - if ( sh_name > section_strtab.length) { + if (sh_name > section_strtab.length) { return EMPTY_STRING; } - while( section_strtab[(int)sh_name + str_size] != 0) + while (section_strtab[(int)sh_name + str_size] != 0) str_size++; return new String(section_strtab, (int)sh_name, str_size); } catch (IOException e) { @@ -350,20 +352,21 @@ public class Elf { protected String string_from_elf_section(Elf.Section section, int index) throws IOException { StringBuffer str = new StringBuffer(); byte tmp; - if ( index > section.sh_size ) { - return EMPTY_STRING; - } + if (index > section.sh_size) { + return EMPTY_STRING; + } efile.seek(section.sh_offset + index); - while( true ) { + while (true) { tmp = efile.readByte(); - if ( tmp == 0 ) + if (tmp == 0) break; str.append((char)tmp); } return str.toString(); } - + public class Symbol implements Comparable { + /* Symbol bindings */ public final static int STB_LOCAL = 0; public final static int STB_GLOBAL = 1; @@ -374,33 +377,33 @@ public class Elf { public final static int STT_FUNC = 2; public final static int STT_SECTION = 3; public final static int STT_FILE = 4; - /* Special Indexes */ - public final static int SHN_UNDEF = 0; - public final static int SHN_LORESERVE = 0xffffff00; - public final static int SHN_LOPROC = 0xffffff00; - public final static int SHN_HIPROC = 0xffffff1f; - public final static int SHN_LOOS = 0xffffff20; - public final static int SHN_HIOS = 0xffffff3f; - public final static int SHN_ABS = 0xfffffff1; - public final static int SHN_COMMON = 0xfffffff2; - public final static int SHN_XINDEX = 0xffffffff; - public final static int SHN_HIRESERVE = 0xffffffff; + /* Special Indexes */ + public final static int SHN_UNDEF = 0; + public final static int SHN_LORESERVE = 0xffffff00; + public final static int SHN_LOPROC = 0xffffff00; + public final static int SHN_HIPROC = 0xffffff1f; + public final static int SHN_LOOS = 0xffffff20; + public final static int SHN_HIOS = 0xffffff3f; + public final static int SHN_ABS = 0xfffffff1; + public final static int SHN_COMMON = 0xfffffff2; + public final static int SHN_XINDEX = 0xffffffff; + public final static int SHN_HIRESERVE = 0xffffffff; - /*NOTE: 64 bit and 32 bit ELF sections has different order*/ + /* NOTE: 64 bit and 32 bit ELF sections has different order */ public long st_name; public IAddress st_value; public long st_size; public short st_info; public short st_other; - public short st_shndx; + public short st_shndx; private String name = null; - private Section sym_section; + private Section sym_section; - public Symbol( Section section ) { - sym_section = section; - } + public Symbol(Section section) { + sym_section = section; + } public int st_type() { return st_info & 0xf; @@ -409,63 +412,57 @@ public class Elf { public int st_bind() { return (st_info >> 4) & 0xf; } - + public int compareTo(Object obj) { /* - long thisVal = 0; - long anotherVal = 0; - if ( obj instanceof Symbol ) { - Symbol sym = (Symbol)obj; - thisVal = this.st_value; - anotherVal = sym.st_value; - } else if ( obj instanceof Long ) { - Long val = (Long)obj; - anotherVal = val.longValue(); - thisVal = this.st_value; - } - return (thisVal 0 ) { - symtab_sym = section[0]; - symtab_symbols = loadSymbolsBySection( section[0] ); - } else { - symtab_sym = null; - symtab_symbols = new Symbol[0]; - } + if (section.length > 0) { + symtab_sym = section[0]; + symtab_symbols = loadSymbolsBySection(section[0]); + } else { + symtab_sym = null; + symtab_symbols = new Symbol[0]; + } - section = getSections(Section.SHT_DYNSYM); - if( section.length > 0 ) { - dynsym_sym = section[0]; - dynsym_symbols = loadSymbolsBySection( section[0] ); - } else { - dynsym_sym = null; - dynsym_symbols = new Symbol[0]; - } + section = getSections(Section.SHT_DYNSYM); + if (section.length > 0) { + dynsym_sym = section[0]; + dynsym_symbols = loadSymbolsBySection(section[0]); + } else { + dynsym_sym = null; + dynsym_symbols = new Symbol[0]; + } - if( symtab_sym != null ) { - // sym = symtab_sym; - symbols = symtab_symbols; - } else if( dynsym_sym != null ) { - // sym = dynsym_sym; - symbols = dynsym_symbols; - } + if (symtab_sym != null) { + // sym = symtab_sym; + symbols = symtab_symbols; + } else if (dynsym_sym != null) { + // sym = dynsym_sym; + symbols = dynsym_symbols; + } } } - public Symbol[] getSymbols() { - return symbols; - } + public Symbol[] getSymbols() { + return symbols; + } - public Symbol[] getDynamicSymbols() { - return dynsym_symbols; - } + public Symbol[] getDynamicSymbols() { + return dynsym_symbols; + } - public Symbol[] getSymtabSymbols() { - return symtab_symbols; - } + public Symbol[] getSymtabSymbols() { + return symtab_symbols; + } - - /* return the address of the function that address is in */ - public Symbol getSymbol( IAddress vma ) { - if ( symbols == null ) { + public Symbol getSymbol(IAddress vma) { + if (symbols == null) { return null; } //@@@ If this works, move it to a single instance in this class. SymbolComparator symbol_comparator = new SymbolComparator(); - + int ndx = Arrays.binarySearch(symbols, vma, symbol_comparator); - if ( ndx > 0 ) + if (ndx > 0) return symbols[ndx]; - if ( ndx == -1 ) { + if (ndx == -1) { return null; } ndx = -ndx - 1; - return symbols[ndx-1]; + return symbols[ndx - 1]; } /* - public long swapInt( long val ) { - if ( ehdr.e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB ) { - short tmp[] = new short[4]; - tmp[0] = (short)(val & 0x00ff); - tmp[1] = (short)((val >> 8) & 0x00ff); - tmp[2] = (short)((val >> 16) & 0x00ff); - tmp[3] = (short)((val >> 24) & 0x00ff); - return ((tmp[0] << 24) + (tmp[1] << 16) + (tmp[2] << 8) + tmp[3]); - } - return val; + * public long swapInt( long val ) { if ( ehdr.e_ident[ELFhdr.EI_DATA] == + * ELFhdr.ELFDATA2LSB ) { short tmp[] = new short[4]; tmp[0] = (short)(val & + * 0x00ff); tmp[1] = (short)((val >> 8) & 0x00ff); tmp[2] = (short)((val >> + * 16) & 0x00ff); tmp[3] = (short)((val >> 24) & 0x00ff); return ((tmp[0] < < + * 24) + (tmp[1] < < 16) + (tmp[2] < < 8) + tmp[3]); } return val; } + * + * public int swapShort( short val ) { if ( ehdr.e_ident[ELFhdr.EI_DATA] == + * ELFhdr.ELFDATA2LSB ) { short tmp[] = new short[2]; tmp[0] = (short)(val & + * 0x00ff); tmp[1] = (short)((val >> 8) & 0x00ff); return (short)((tmp[0] < < + * 8) + tmp[1]); } return val; } + */ + public String getFilename() { + return file; } - public int swapShort( short val ) { - if ( ehdr.e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB ) { - short tmp[] = new short[2]; - tmp[0] = (short)(val & 0x00ff); - tmp[1] = (short)((val >> 8) & 0x00ff); - return (short)((tmp[0] << 8) + tmp[1]); + protected long readUnsignedLong(ERandomAccessFile file) throws IOException { + long result = file.readLongE(); + if (result < 0) { + throw new IOException("Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + //$NON-NLS-1$ + " given offset is " + Long.toHexString(result)); //$NON-NLS-1$ } - return val; + return result; } -*/ - public String getFilename() { - return file; - } - - private final long readUnsignedLong(ERandomAccessFile file) throws IOException - { - long result = file.readLongE(); - if(result < 0) - { - throw new IOException( "Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + - " given offset is " + Long.toHexString(result)); - } - return result; - } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ElfHelper.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ElfHelper.java index ecab483b951..c85163efc06 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ElfHelper.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/ElfHelper.java @@ -10,23 +10,20 @@ *******************************************************************************/ package org.eclipse.cdt.utils.elf; - import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Vector; /** - * ElfHelper is a wrapper class for the Elf class - * to provide higher level API for sorting/searching the ELF data. - * - * @see Elf + * ElfHelper is a wrapper class for the Elf class + * to provide higher level API for sorting/searching the ELF data. + * + * @see Elf */ public class ElfHelper { private Elf elf; - private Elf.ELFhdr hdr; - private Elf.Attribute attrib; private Elf.Symbol[] dynsyms; private Elf.Symbol[] symbols; private Elf.Section[] sections; @@ -40,6 +37,7 @@ public class ElfHelper { } public class Sizes { + public long text; public long data; public long bss; @@ -81,35 +79,46 @@ public class ElfHelper { } } - /** Common code used by all constructors */ - private void commonSetup() throws IOException { - hdr = elf.getELFhdr(); - attrib = elf.getAttributes(); - } - /** * Create a new ElfHelper using an existing Elf * object. - * @param elf An existing Elf object to wrap. - * @throws IOException Error processing the Elf file. + * + * @param elf + * An existing Elf object to wrap. + * @throws IOException + * Error processing the Elf file. */ public ElfHelper(Elf elf) throws IOException { this.elf = elf; - commonSetup(); } /** * Create a new ElfHelper based on the given filename. * - * @param filename The file to use for creating a new Elf object. - * @throws IOException Error processing the Elf file. + * @param filename + * The file to use for creating a new Elf object. + * @throws IOException + * Error processing the Elf file. * @see Elf#Elf( String ) */ public ElfHelper(String filename) throws IOException { elf = new Elf(filename); - commonSetup(); } + /** + * Create a new ElfHelper based on the given filename. + * + * @param filename + * The file to use for creating a new Elf object. + * @throws IOException + * Error processing the Elf file. + * @see Elf#Elf( String ) + */ + public ElfHelper(String filename, long fileoffset) throws IOException { + elf = new Elf(filename, fileoffset); + } + + /** Give back the Elf object that this helper is wrapping */ public Elf getElf() { return elf; @@ -134,7 +143,7 @@ public class ElfHelper { } } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -158,7 +167,7 @@ public class ElfHelper { } } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -173,7 +182,7 @@ public class ElfHelper { v.add(dynsyms[i]); } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -185,7 +194,7 @@ public class ElfHelper { loadSections(); for (int i = 0; i < symbols.length; i++) { - if (symbols[i].st_bind() == Elf.Symbol.STB_GLOBAL && symbols[i].st_type() == Elf.Symbol.STT_FUNC) { + if ( symbols[i].st_type() == Elf.Symbol.STT_FUNC) { int idx = symbols[i].st_shndx; if (idx < Elf.Symbol.SHN_HIPROC && idx > Elf.Symbol.SHN_LOPROC) { String name = symbols[i].toString(); @@ -197,7 +206,7 @@ public class ElfHelper { } } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -209,7 +218,7 @@ public class ElfHelper { loadSections(); for (int i = 0; i < symbols.length; i++) { - if (symbols[i].st_bind() == Elf.Symbol.STB_GLOBAL && symbols[i].st_type() == Elf.Symbol.STT_OBJECT) { + if ( symbols[i].st_type() == Elf.Symbol.STT_OBJECT) { int idx = symbols[i].st_shndx; if (idx < Elf.Symbol.SHN_HIPROC && idx > Elf.Symbol.SHN_LOPROC) { String name = symbols[i].toString(); @@ -221,7 +230,7 @@ public class ElfHelper { } } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -241,7 +250,7 @@ public class ElfHelper { } } - Elf.Symbol[] ret = (Elf.Symbol[]) v.toArray(new Elf.Symbol[0]); + Elf.Symbol[] ret = (Elf.Symbol[])v.toArray(new Elf.Symbol[v.size()]); Arrays.sort(ret, new SymbolSortCompare()); return ret; } @@ -255,7 +264,7 @@ public class ElfHelper { if (dynamics[i].d_tag == Elf.Dynamic.DT_NEEDED) v.add(dynamics[i]); } - return (Elf.Dynamic[]) v.toArray(new Elf.Dynamic[0]); + return (Elf.Dynamic[])v.toArray(new Elf.Dynamic[v.size()]); } public String getSoname() throws IOException { @@ -344,7 +353,7 @@ public class ElfHelper { if (sections[i].sh_type != Elf.Section.SHT_NOBITS) { if (sections[i].sh_flags == (Elf.Section.SHF_WRITE | Elf.Section.SHF_ALLOC)) { data += sections[i].sh_size; - } else if ((sections[i].sh_flags & Elf.Section.SHF_ALLOC) != 0) { + } else if ( (sections[i].sh_flags & Elf.Section.SHF_ALLOC) != 0) { text += sections[i].sh_size; } } else { @@ -357,4 +366,4 @@ public class ElfHelper { return new Sizes(text, data, bss); } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java deleted file mode 100644 index 849016ce65f..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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.utils.elf.parser; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.utils.Symbol; -import org.eclipse.cdt.utils.elf.AR; -import org.eclipse.cdt.utils.elf.Elf; -import org.eclipse.cdt.utils.elf.ElfHelper; -import org.eclipse.core.runtime.IPath; - -/** - * ARMember - */ -public class ARMember extends ElfBinaryObject { - AR.ARHeader header; - - public ARMember(IBinaryParser parser, IPath p, AR.ARHeader h) throws IOException { - super(parser, p); - header = h; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = super.getContents(); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - return ""; //$NON-NLS-1$ - } - - protected ElfHelper getElfHelper() throws IOException { - if (header != null) { - return new ElfHelper(header.getElf()); - } - throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$ - } - - protected void addSymbols(Elf.Symbol[] array, int type, List list) { - for (int i = 0; i < array.length; i++) { - Symbol sym = new Symbol(this, array[i].toString(), type, array[i].st_value, array[i].st_size); - list.add(sym); - } - } - -} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryArchive.java similarity index 72% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryArchive.java index e239b95966b..7d6541765c6 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryArchive.java @@ -17,18 +17,19 @@ import org.eclipse.cdt.core.IBinaryParser; 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.AR; import org.eclipse.cdt.utils.BinaryFile; -import org.eclipse.cdt.utils.elf.AR; +import org.eclipse.cdt.utils.AR.ARHeader; import org.eclipse.core.runtime.IPath; /** */ -public class BinaryArchive extends BinaryFile implements IBinaryArchive { +public class ElfBinaryArchive extends BinaryFile implements IBinaryArchive { ArrayList children; - public BinaryArchive(IBinaryParser parser, IPath p) throws IOException { - super(parser, p); + public ElfBinaryArchive(IBinaryParser parser, IPath p) throws IOException { + super(parser, p, IBinaryFile.ARCHIVE); new AR(p.toOSString()).dispose(); // check file type children = new ArrayList(5); } @@ -43,10 +44,7 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { try { ar = new AR(getPath().toOSString()); AR.ARHeader[] headers = ar.getHeaders(); - for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]); - children.add(bin); - } + addArchiveMembers(headers, children); } catch (IOException e) { //e.printStackTrace(); } @@ -59,9 +57,13 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { } /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() + * @param headers + * @param children2 */ - public int getType() { - return IBinaryFile.ARCHIVE; + protected void addArchiveMembers(ARHeader[] headers, ArrayList children2) { + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new ElfBinaryObject(getBinaryParser(), getPath(), headers[i]); + children.add(bin); + } } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryExecutable.java new file mode 100644 index 00000000000..9ec9c52ecce --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryExecutable.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.elf.parser; + +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class ElfBinaryExecutable extends ElfBinaryObject implements IBinaryExecutable { + + + public ElfBinaryExecutable(ElfParser parser, IPath p) { + super(parser, p, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java index a20a245e4b6..7244fed58cb 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.utils.elf.parser; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,6 +20,7 @@ import java.util.List; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.ISymbol; +import org.eclipse.cdt.utils.AR; import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.Symbol; import org.eclipse.cdt.utils.elf.Elf; @@ -31,16 +34,36 @@ public class ElfBinaryObject extends BinaryObjectAdapter { private BinaryObjectInfo info; private ISymbol[] symbols; + private final AR.ARHeader header; - public ElfBinaryObject(IBinaryParser parser, IPath path) { - super(parser, path); + public ElfBinaryObject(IBinaryParser parser, IPath p, AR.ARHeader h){ + super(parser, p, IBinaryFile.OBJECT); + header = h; + } + + public ElfBinaryObject(IBinaryParser parser, IPath p, int type){ + super(parser, p, type); + header = null; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() + * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName() */ - public int getType() { - return IBinaryFile.OBJECT; + public String getName() { + if (header != null) { + return header.getObjectName(); + } + return super.getName(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getContents() + */ + public InputStream getContents() throws IOException { + if (getPath() != null && header != null) { + return new ByteArrayInputStream(header.getObjectData()); + } + return super.getContents(); } /* (non-Javadoc) @@ -74,6 +97,9 @@ public class ElfBinaryObject extends BinaryObjectAdapter { } protected ElfHelper getElfHelper() throws IOException { + if (header != null) { + return new ElfHelper(header.getArchiveName(), header.getObjectDataOffset()); + } return new ElfHelper(getPath().toOSString()); } @@ -126,9 +152,9 @@ public class ElfBinaryObject extends BinaryObjectAdapter { protected void loadSymbols(ElfHelper helper) throws IOException { ArrayList list = new ArrayList(); - addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, list); +// addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, list); addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, list); - addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, list); +// addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, list); addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, list); list.trimToSize(); @@ -143,4 +169,18 @@ public class ElfBinaryObject extends BinaryObjectAdapter { } } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.equals(Elf.class)) { + try { + return new Elf(getPath().toOSString()); + } catch (IOException e) { + } + } + return super.getAdapter(adapter); + } + } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryShared.java new file mode 100644 index 00000000000..0e8396e126f --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryShared.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.elf.parser; + +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class ElfBinaryShared extends ElfBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param p + */ + public ElfBinaryShared(ElfParser parser, IPath p) { + super(parser, p, IBinaryFile.SHARED); + } +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java index 29f2ec18fbf..1f1712b2f4d 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java @@ -16,7 +16,7 @@ import java.io.IOException; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.utils.elf.AR; +import org.eclipse.cdt.utils.AR; import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf.Attribute; import org.eclipse.core.runtime.IPath; @@ -105,43 +105,22 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { - return new BinaryArchive(this, path); + return new ElfBinaryArchive(this, path); } protected IBinaryObject createBinaryObject(IPath path) throws IOException { - return new ElfBinaryObject(this, path); + return new ElfBinaryObject(this, path, IBinaryFile.OBJECT); } protected IBinaryExecutable createBinaryExecutable(IPath path) throws IOException { - return new ElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new ElfBinaryExecutable(this, path); } protected IBinaryShared createBinaryShared(IPath path) throws IOException { - return new ElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + return new ElfBinaryShared(this, path); } protected IBinaryObject createBinaryCore(IPath path) throws IOException { - return new ElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + return new ElfBinaryObject(this, path, IBinaryFile.CORE); } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryArchive.java new file mode 100644 index 00000000000..fcb30b81363 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryArchive.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.elf.parser; + +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.utils.AR.ARHeader; +import org.eclipse.core.runtime.IPath; + + +public class GNUElfBinaryArchive extends ElfBinaryArchive { + + /** + * @param parser + * @param p + * @throws IOException + */ + public GNUElfBinaryArchive(IBinaryParser parser, IPath p) throws IOException { + super(parser, p); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.elf.parser.BinaryArchive#addArchiveMembers(org.eclipse.cdt.utils.elf.AR.ARHeader[], java.util.ArrayList) + */ + protected void addArchiveMembers(ARHeader[] headers, ArrayList children2) { + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new GNUElfBinaryObject(getBinaryParser(), getPath(), headers[i]); + children.add(bin); + } + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryExecutable.java new file mode 100644 index 00000000000..83181154b15 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryExecutable.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.elf.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class GNUElfBinaryExecutable extends GNUElfBinaryObject implements IBinaryExecutable { + + + public GNUElfBinaryExecutable(IBinaryParser parser, IPath p) { + super(parser, p, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryObject.java index 20d5e54c0db..c1d5c63043f 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryObject.java @@ -15,10 +15,14 @@ import java.math.BigInteger; import java.util.List; import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.utils.Addr2line; import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.IGnuToolFactory; import org.eclipse.cdt.utils.Objdump; +import org.eclipse.cdt.utils.AR.ARHeader; import org.eclipse.cdt.utils.elf.Elf; +import org.eclipse.cdt.utils.elf.ElfHelper; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -27,37 +31,49 @@ import org.eclipse.core.runtime.Path; */ public class GNUElfBinaryObject extends ElfBinaryObject { - private Addr2line addr2line; + private Addr2line autoDisposeAddr2line; + private Addr2line symbolLoadingAddr2line; + private CPPFilt symbolLoadingCPPFilt; + long starttime; + + /** + * @param parser + * @param path + * @param header + */ + public GNUElfBinaryObject(IBinaryParser parser, IPath path, ARHeader header) { + super(parser, path, header); + } /** * @param parser * @param path + * @param type */ - public GNUElfBinaryObject(GNUElfParser parser, IPath path) { - super(parser, path); + public GNUElfBinaryObject(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); } public Addr2line getAddr2line(boolean autodisposing) { if (!autodisposing) { - GNUElfParser parser = (GNUElfParser) getBinaryParser(); - return parser.getAddr2line(getPath()); + return getAddr2line(); } - if (addr2line == null) { - GNUElfParser parser = (GNUElfParser) getBinaryParser(); - addr2line = parser.getAddr2line(getPath()); - if (addr2line != null) { - timestamp = System.currentTimeMillis(); + if (autoDisposeAddr2line == null) { + autoDisposeAddr2line = getAddr2line(); + if (autoDisposeAddr2line != null) { + starttime = System.currentTimeMillis(); Runnable worker = new Runnable() { public void run() { - long diff = System.currentTimeMillis() - timestamp; + + long diff = System.currentTimeMillis() - starttime; while (diff < 10000) { try { Thread.sleep(10000); } catch (InterruptedException e) { break; } - diff = System.currentTimeMillis() - timestamp; + diff = System.currentTimeMillis() - starttime; } stopAddr2Line(); } @@ -65,32 +81,47 @@ public class GNUElfBinaryObject extends ElfBinaryObject { new Thread(worker, "Addr2line Reaper").start(); //$NON-NLS-1$ } } else { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); // reset autodispose timeout } - return addr2line; + return autoDisposeAddr2line; } synchronized void stopAddr2Line() { - if (addr2line != null) { - addr2line.dispose(); + if (autoDisposeAddr2line != null) { + autoDisposeAddr2line.dispose(); } - addr2line = null; + autoDisposeAddr2line = null; } + private Addr2line getAddr2line() { + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getAddr2line(getPath()); + } + return null; + } + protected CPPFilt getCPPFilt() { - GNUElfParser parser = (GNUElfParser) getBinaryParser(); - return parser.getCPPFilt(); + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getCPPFilt(); + } + return null; } protected Objdump getObjdump() { - GNUElfParser parser = (GNUElfParser) getBinaryParser(); - return parser.getObjdump(getPath()); + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getObjdump(getPath()); + } + return null; } /** + * @throws IOException * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() */ - public InputStream getContents() { + public InputStream getContents() throws IOException { InputStream stream = null; Objdump objdump = getObjdump(); if (objdump != null) { @@ -108,6 +139,24 @@ public class GNUElfBinaryObject extends ElfBinaryObject { return stream; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#loadSymbols(org.eclipse.cdt.utils.elf.ElfHelper) + */ + protected void loadSymbols(ElfHelper helper) throws IOException { + symbolLoadingAddr2line = getAddr2line(false); + symbolLoadingCPPFilt = getCPPFilt(); + super.loadSymbols(helper); + if (symbolLoadingAddr2line != null) { + symbolLoadingAddr2line.dispose(); + symbolLoadingAddr2line = null; + } + if (symbolLoadingCPPFilt != null) { + symbolLoadingCPPFilt.dispose(); + symbolLoadingCPPFilt = null; + } + } + /* * (non-Javadoc) * @@ -115,30 +164,30 @@ public class GNUElfBinaryObject extends ElfBinaryObject { * int, java.util.List) */ protected void addSymbols(Elf.Symbol[] array, int type, List list) { - CPPFilt cppfilt = getCPPFilt(); - Addr2line addr2line = getAddr2line(false); for (int i = 0; i < array.length; i++) { String name = array[i].toString(); - if (cppfilt != null) { + if (symbolLoadingCPPFilt != null) { try { - name = cppfilt.getFunction(name); + name = symbolLoadingCPPFilt.getFunction(name); } catch (IOException e1) { - cppfilt = null; + symbolLoadingCPPFilt.dispose(); + symbolLoadingCPPFilt = null; } } IAddress addr = array[i].st_value; long size = array[i].st_size; - if (addr2line != null) { + if (symbolLoadingAddr2line != null) { try { - String filename = addr2line.getFileName(addr); + String filename = symbolLoadingAddr2line.getFileName(addr); // Addr2line returns the funny "??" when it can not find // the file. IPath file = (filename != null && !filename.equals("??")) ? new Path(filename) : Path.EMPTY; //$NON-NLS-1$ - int startLine = addr2line.getLineNumber(addr); - int endLine = addr2line.getLineNumber(addr.add(BigInteger.valueOf(size - 1))); + int startLine = symbolLoadingAddr2line.getLineNumber(addr); + int endLine = symbolLoadingAddr2line.getLineNumber(addr.add(BigInteger.valueOf(size - 1))); list.add(new GNUSymbol(this, name, type, addr, size, file, startLine, endLine)); } catch (IOException e) { - addr2line = null; + symbolLoadingAddr2line.dispose(); + symbolLoadingAddr2line = null; // the symbol still needs to be added list.add(new GNUSymbol(this, name, type, addr, size)); } @@ -146,12 +195,6 @@ public class GNUElfBinaryObject extends ElfBinaryObject { list.add(new GNUSymbol(this, name, type, addr, size)); } } - if (cppfilt != null) { - cppfilt.dispose(); - } - if (addr2line != null) { - addr2line.dispose(); - } } /* diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryShared.java new file mode 100644 index 00000000000..0285e44ef6c --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryShared.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.elf.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class GNUElfBinaryShared extends GNUElfBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param p + */ + public GNUElfBinaryShared(IBinaryParser parser, IPath p) { + super(parser, p, IBinaryFile.SHARED); + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java index 167f9252b30..488ed13ea97 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java @@ -12,19 +12,16 @@ package org.eclipse.cdt.utils.elf.parser; import java.io.IOException; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.utils.Addr2line; -import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.DefaultGnuToolFactory; import org.eclipse.cdt.utils.IGnuToolFactory; -import org.eclipse.cdt.utils.Objdump; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; /** * GNUElfParser */ -public class GNUElfParser extends ElfParser implements IGnuToolFactory { - +public class GNUElfParser extends ElfParser { + private IGnuToolFactory toolFactory; + /** * @see org.eclipse.cdt.core.model.IBinaryParser#getFormat() */ @@ -36,147 +33,56 @@ public class GNUElfParser extends ElfParser implements IGnuToolFactory { * @see org.eclipse.cdt.utils.elf.parser.ElfParser#createBinaryCore(org.eclipse.core.runtime.IPath) */ protected IBinaryObject createBinaryCore(IPath path) throws IOException { - return new GNUElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + return new GNUElfBinaryObject(this, path, IBinaryFile.CORE); } /* (non-Javadoc) * @see org.eclipse.cdt.utils.elf.parser.ElfParser#createBinaryExecutable(org.eclipse.core.runtime.IPath) */ protected IBinaryExecutable createBinaryExecutable(IPath path) throws IOException { - return new GNUElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new GNUElfBinaryExecutable(this, path); } /* (non-Javadoc) * @see org.eclipse.cdt.utils.elf.parser.ElfParser#createBinaryObject(org.eclipse.core.runtime.IPath) */ protected IBinaryObject createBinaryObject(IPath path) throws IOException { - return new GNUElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.OBJECT; - } - }; + return new GNUElfBinaryObject(this, path, IBinaryFile.OBJECT); } /* (non-Javadoc) * @see org.eclipse.cdt.utils.elf.parser.ElfParser#createBinaryShared(org.eclipse.core.runtime.IPath) */ protected IBinaryShared createBinaryShared(IPath path) throws IOException { - return new GNUElfBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + return new GNUElfBinaryShared(this, path); } + /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getAddr2line(org.eclipse.core.runtime.IPath) + * @see org.eclipse.cdt.utils.elf.parser.ElfParser#createBinaryArchive(org.eclipse.core.runtime.IPath) */ - public Addr2line getAddr2line(IPath path) { - IPath addr2LinePath = getAddr2linePath(); - Addr2line addr2line = null; - if (addr2LinePath != null && !addr2LinePath.isEmpty()) { - try { - addr2line = new Addr2line(addr2LinePath.toOSString(), path.toOSString()); - } catch (IOException e1) { - } - } - return addr2line; + protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { + return new GNUElfBinaryArchive(this, path); } - + + /** + * @return + */ + protected IGnuToolFactory createGNUToolFactory() { + return new DefaultGnuToolFactory(this); + } + /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getCPPFilt() + * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) */ - public CPPFilt getCPPFilt() { - IPath cppFiltPath = getCPPFiltPath(); - CPPFilt cppfilt = null; - if (cppFiltPath != null && ! cppFiltPath.isEmpty()) { - try { - cppfilt = new CPPFilt(cppFiltPath.toOSString()); - } catch (IOException e2) { + public Object getAdapter(Class adapter) { + if (adapter.equals(IGnuToolFactory.class)) { + if (toolFactory == null) { + toolFactory = createGNUToolFactory(); } + return toolFactory; } - return cppfilt; + // TODO Auto-generated method stub + return super.getAdapter(adapter); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getObjdump(org.eclipse.core.runtime.IPath) - */ - public Objdump getObjdump(IPath path) { - IPath objdumpPath = getObjdumpPath(); - String objdumpArgs = getObjdumpArgs(); - Objdump objdump = null; - if (objdumpPath != null && !objdumpPath.isEmpty()) { - try { - objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString()); - } catch (IOException e1) { - } - } - return objdump; - } - - protected IPath getAddr2linePath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "addr2line"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getObjdumpPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdump"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "objdump"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected String getObjdumpArgs() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = ""; //$NON-NLS-1$ - } - return value; - } - - protected IPath getCPPFiltPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "c++filt"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getStripPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("strip"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "strip"; //$NON-NLS-1$ - } - return new Path(value); - } - } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUSymbol.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUSymbol.java index 136bea42a02..61138fe6bb5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUSymbol.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUSymbol.java @@ -20,12 +20,11 @@ import org.eclipse.core.runtime.IPath; public class GNUSymbol extends Symbol { - public GNUSymbol(GNUElfBinaryObject binary, String name, int type, IAddress addr, long size, IPath sourceFile, int startLine, int endLine) { + public GNUSymbol(ElfBinaryObject binary, String name, int type, IAddress addr, long size, IPath sourceFile, int startLine, int endLine) { super(binary, name, type, addr, size, sourceFile, startLine, endLine); - // TODO Auto-generated constructor stub } - public GNUSymbol(GNUElfBinaryObject binary, String name, int type, IAddress addr, long size) { + public GNUSymbol(ElfBinaryObject binary, String name, int type, IAddress addr, long size) { super(binary, name, type, addr, size); } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/AR.java index cd36b08d449..256f4ade40c 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/AR.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/AR.java @@ -194,12 +194,8 @@ public class AR { * @return A new MachO object. * @see MachO#MachO( String, long ) */ - public MachO getMachO() throws IOException { - return new MachO(filename, macho_offset); - } - - public MachO getMachO(boolean filter_on) throws IOException { - return new MachO(filename, macho_offset, filter_on); + public long getObjectDataOffset() throws IOException { + return macho_offset; } public byte[] getObjectData() throws IOException { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachOHelper.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachOHelper.java index 8a33d32f13e..f2258eac01b 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachOHelper.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachOHelper.java @@ -18,8 +18,6 @@ import java.util.Vector; public class MachOHelper { private MachO macho; - private MachO.MachOhdr hdr; - private MachO.Attribute attrib; private MachO.Symbol[] dynsyms; private MachO.Symbol[] symbols; private MachO.Section[] sections; @@ -60,11 +58,6 @@ public class MachOHelper { } } - /** Common code used by all constructors */ - private void commonSetup() throws IOException { - hdr = macho.getMachOhdr(); - attrib = macho.getAttributes(); - } /** * Create a new MachOHelper using an existing MachO @@ -74,7 +67,6 @@ public class MachOHelper { */ public MachOHelper(MachO macho) throws IOException { this.macho = macho; - commonSetup(); } /** @@ -86,12 +78,22 @@ public class MachOHelper { */ public MachOHelper(String filename) throws IOException { macho = new MachO(filename); - commonSetup(); } + /** + * Create a new MachOHelper based on the given filename. + * + * @param filename The file to use for creating a new MachO object. + * @throws IOException Error processing the MachO file. + * @see MachO#MachO( String ) + */ + public MachOHelper(String filename, long offset) throws IOException { + macho = new MachO(filename, offset); + } + + public MachOHelper(String filename, boolean filton) throws IOException { macho = new MachO(filename, filton); - commonSetup(); } /** Give back the MachO object that this helper is wrapping */ diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/ARMember.java deleted file mode 100644 index 7d7cd09e0e9..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/ARMember.java +++ /dev/null @@ -1,80 +0,0 @@ -/********************************************************************** - * 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.utils.macho.parser; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.utils.Addr2line; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.CPPFilt; -import org.eclipse.cdt.utils.Symbol; -import org.eclipse.cdt.utils.macho.AR; -import org.eclipse.cdt.utils.macho.MachO; -import org.eclipse.cdt.utils.macho.MachOHelper; -import org.eclipse.core.runtime.IPath; - -/** - * ARMember - */ -public class ARMember extends MachOBinaryObject { - AR.ARHeader header; - - public ARMember(IBinaryParser parser, IPath p, AR.ARHeader h) throws IOException { - super(parser, p); - header = h; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = super.getContents(); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - return ""; //$NON-NLS-1$ - } - - protected MachOHelper getMachOHelper() throws IOException { - if (header != null) { - return new MachOHelper(header.getMachO()); - } - throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$ - } - - protected void addSymbols(MachO.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt, List list) { - for (int i = 0; i < array.length; i++) { - list.add(new Symbol(this, array[i].toString(), type, new Addr32(array[i].n_value), 4)); - } - } - -} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryArchive.java similarity index 69% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/BinaryArchive.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryArchive.java index a7b3e1e1710..b063d4dd257 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryArchive.java @@ -23,12 +23,12 @@ import org.eclipse.core.runtime.IPath; /** */ -public class BinaryArchive extends BinaryFile implements IBinaryArchive { +public class MachOBinaryArchive extends BinaryFile implements IBinaryArchive { ArrayList children; - public BinaryArchive(IBinaryParser parser, IPath p) throws IOException { - super(parser, p); + public MachOBinaryArchive(IBinaryParser parser, IPath p) throws IOException { + super(parser, p, IBinaryFile.ARCHIVE); new AR(p.toOSString()).dispose(); // check file type children = new ArrayList(5); } @@ -44,7 +44,7 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { ar = new AR(getPath().toOSString()); AR.ARHeader[] headers = ar.getHeaders(); for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]); + IBinaryObject bin = new MachOBinaryObject(getBinaryParser(), getPath(), headers[i]); children.add(bin); } } catch (IOException e) { @@ -56,25 +56,5 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { children.trimToSize(); } return (IBinaryObject[]) children.toArray(new IBinaryObject[0]); - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.ARCHIVE; - } - - /** - * @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/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryExecutable.java new file mode 100644 index 00000000000..a9969561705 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryExecutable.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.macho.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class MachOBinaryExecutable extends MachOBinaryObject implements IBinaryExecutable { + + /** + * @param parser + * @param path + * @param isCoreFile + */ + public MachOBinaryExecutable(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryObject.java index 22803d78b36..3ec8448b713 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryObject.java @@ -10,7 +10,9 @@ ***********************************************************************/ package org.eclipse.cdt.utils.macho.parser; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,6 +24,7 @@ import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.CPPFilt; import org.eclipse.cdt.utils.Symbol; +import org.eclipse.cdt.utils.macho.AR; import org.eclipse.cdt.utils.macho.MachO; import org.eclipse.cdt.utils.macho.MachOHelper; import org.eclipse.core.runtime.IPath; @@ -34,16 +37,24 @@ public class MachOBinaryObject extends BinaryObjectAdapter { private BinaryObjectInfo info; private ISymbol[] symbols; + private AR.ARHeader header; - public MachOBinaryObject(IBinaryParser parser, IPath path) { - super(parser, path); + /** + * @param parser + * @param path + * @param header + */ + public MachOBinaryObject(IBinaryParser parser, IPath path, AR.ARHeader header) { + super(parser, path, IBinaryFile.OBJECT); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() + /** + * @param parser + * @param path + * @param type */ - public int getType() { - return IBinaryFile.OBJECT; + public MachOBinaryObject(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); } /* (non-Javadoc) @@ -76,9 +87,33 @@ public class MachOBinaryObject extends BinaryObjectAdapter { return info; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getContents() + */ + public InputStream getContents() throws IOException { + if (getPath() != null && header != null) { + return new ByteArrayInputStream(header.getObjectData()); + } + return super.getContents(); + } + protected MachOHelper getMachOHelper() throws IOException { + if (header != null) { + return new MachOHelper(getPath().toOSString(), header.getObjectDataOffset()); + } return new MachOHelper(getPath().toOSString()); } + + /** + * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName() + */ + public String getName() { + if (header != null) { + return header.getObjectName(); + } + return super.getName(); + } protected void loadAll() throws IOException { MachOHelper helper = null; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryShared.java new file mode 100644 index 00000000000..fc22a09457e --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOBinaryShared.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.macho.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class MachOBinaryShared extends MachOBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param path + * @param type + */ + protected MachOBinaryShared(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.SHARED); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java index 5d5c240f51d..ff65af4c2d3 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java @@ -131,43 +131,22 @@ public class MachOParser extends AbstractCExtension implements IBinaryParser { * @return */ protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { - return new BinaryArchive(this, path); + return new MachOBinaryArchive(this, path); } protected IBinaryObject createBinaryObject(IPath path) throws IOException { - return new MachOBinaryObject(this, path); + return new MachOBinaryObject(this, path, IBinaryFile.OBJECT); } protected IBinaryExecutable createBinaryExecutable(IPath path) throws IOException { - return new MachOBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new MachOBinaryExecutable(this, path); } protected IBinaryShared createBinaryShared(IPath path) throws IOException { - return new MachOBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + return new MachOBinaryShared(this, path); } protected IBinaryObject createBinaryCore(IPath path) throws IOException { - return new MachOBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + return new MachOBinaryObject(this, path, IBinaryFile.CORE); } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/AR.java index c83936ed8a0..75fa09aac3a 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/AR.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/AR.java @@ -104,8 +104,8 @@ public class AR { * @return A new SOM object. * @see SOM#SOM( String, long ) */ - public SOM getSOM() throws IOException { - return new SOM(filename, somOffset); + public long getObjectDataOffset() { + return somOffset; } } @@ -227,7 +227,7 @@ public class AR { return true; } - private RandomAccessFile getRandomAccessFile () throws IOException { + protected RandomAccessFile getRandomAccessFile () throws IOException { if (file == null) { file = new RandomAccessFile(filename, "r"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/SOM.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/SOM.java index ce0a03b820b..b400ef3bcfd 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/SOM.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/SOM.java @@ -338,7 +338,7 @@ public class SOM { public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("SYMBOL TABLE ENTRY").append(NL); //$NON-NLS-1$ - buffer.append("symbol_name = "); + buffer.append("symbol_name = "); //$NON-NLS-1$ try { buffer.append(getName(getStringTable())).append(NL); } @@ -393,7 +393,7 @@ public class SOM { public SOM(String filename, long offset) throws IOException { this.filename = filename; - commonSetup(new RandomAccessFile(filename, "r"), offset); + commonSetup(new RandomAccessFile(filename, "r"), offset); //$NON-NLS-1$ } void commonSetup(RandomAccessFile file, long offset) throws IOException { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/ARMember.java deleted file mode 100644 index 11b7794d423..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/ARMember.java +++ /dev/null @@ -1,107 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation 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: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.utils.som.parser; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.CPPFilt; -import org.eclipse.cdt.utils.Symbol; -import org.eclipse.cdt.utils.som.AR; -import org.eclipse.cdt.utils.som.SOM; -import org.eclipse.core.runtime.IPath; - -/** - * A member of a SOM archive - * - * @author vhirsl - */ -public class ARMember extends SOMBinaryObject { - private AR.ARHeader header; - - /** - * @param parser - * @param path - */ - public ARMember(IBinaryParser parser, IPath path, AR.ARHeader header) { - super(parser, path); - this.header = header; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.som.parser.SOMBinaryObject#addSymbols(org.eclipse.cdt.utils.som.SOM.Symbol[], byte[], org.eclipse.cdt.utils.Addr2line, org.eclipse.cdt.utils.CPPFilt, org.eclipse.cdt.utils.CygPath, java.util.List) - */ - protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, List list) { - CPPFilt cppfilt = getCPPFilt(); - for (int i = 0; i < peSyms.length; i++) { - if (peSyms[i].isFunction() || peSyms[i].isVariable()) { - String name = peSyms[i].getName(table); - if (name == null || name.trim().length() == 0 || - !Character.isJavaIdentifierStart(name.charAt(0))) { - continue; - } - if (cppfilt != null) { - try { - name = cppfilt.getFunction(name); - } catch (IOException e1) { - cppfilt = null; - } - } - Symbol sym = new Symbol(this, name, peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE, new Addr32(peSyms[i].symbol_value), 1); - - list.add(sym); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.som.parser.SOMBinaryObject#getSOM() - */ - protected SOM getSOM() throws IOException { - if (header != null) { - return header.getSOM(); - } - throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = super.getContents(); - } - return stream; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - return ""; //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryArchive.java similarity index 81% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/BinaryArchive.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryArchive.java index 5713f1d0ce6..308c383631e 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryArchive.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IPath; * * @author vhirsl */ -public class BinaryArchive extends BinaryFile implements IBinaryArchive { +public class SOMBinaryArchive extends BinaryFile implements IBinaryArchive { private ArrayList children; /** @@ -34,19 +34,12 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { * @param path * @throws IOException */ - public BinaryArchive(IBinaryParser parser, IPath path) throws IOException { - super(parser, path); + public SOMBinaryArchive(IBinaryParser parser, IPath path) throws IOException { + super(parser, path, IBinaryFile.ARCHIVE); new AR(path.toOSString()).dispose(); // check file type children = new ArrayList(5); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.ARCHIVE; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.IBinaryParser.IBinaryArchive#getObjects() */ @@ -58,7 +51,7 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { ar = new AR(getPath().toOSString()); AR.ARHeader[] headers = ar.getHeaders(); for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]); + IBinaryObject bin = new SOMBinaryObject(getBinaryParser(), getPath(), headers[i]); children.add(bin); } } catch (IOException e) { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryExecutable.java new file mode 100644 index 00000000000..3e08d27c23a --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryExecutable.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.som.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class SOMBinaryExecutable extends SOMBinaryObject implements IBinaryExecutable { + + /** + * @param parser + * @param path + * @param header + */ + public SOMBinaryExecutable(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.EXECUTABLE); + } +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryObject.java index b9b155ff7c7..222fe83b745 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryObject.java @@ -26,8 +26,11 @@ import org.eclipse.cdt.utils.Addr2line; import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.IGnuToolFactory; import org.eclipse.cdt.utils.Objdump; +import org.eclipse.cdt.utils.som.AR; import org.eclipse.cdt.utils.som.SOM; +import org.eclipse.cdt.utils.som.AR.ARHeader; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -37,19 +40,35 @@ import org.eclipse.core.runtime.Path; * @author vhirsl */ public class SOMBinaryObject extends BinaryObjectAdapter { + Addr2line addr2line; BinaryObjectInfo info; ISymbol[] symbols; + long starttime; + private ARHeader header; /** * @param parser * @param path + * @param header */ - public SOMBinaryObject(IBinaryParser parser, IPath path) { - super(parser, path); + public SOMBinaryObject(IBinaryParser parser, IPath path, AR.ARHeader header) { + super(parser, path, IBinaryFile.OBJECT); + this.header = header; } - /* (non-Javadoc) + /** + * @param parser + * @param path + * @param type + */ + public SOMBinaryObject(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); + } + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbols() */ public ISymbol[] getSymbols() { @@ -63,7 +82,9 @@ public class SOMBinaryObject extends BinaryObjectAdapter { return symbols; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo() */ protected BinaryObjectInfo getBinaryObjectInfo() { @@ -77,18 +98,28 @@ public class SOMBinaryObject extends BinaryObjectAdapter { return info; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName() */ - public int getType() { - return IBinaryFile.OBJECT; + public String getName() { + if (header != null) { + return header.getObjectName(); + } + return super.getName(); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getContents() */ - public InputStream getContents() { + public InputStream getContents() throws IOException { InputStream stream = null; + if (getPath() != null && header != null) { + return new ByteArrayInputStream(header.getObjectData()); + } Objdump objdump = getObjdump(); if (objdump != null) { try { @@ -103,8 +134,11 @@ public class SOMBinaryObject extends BinaryObjectAdapter { } return stream; } - + protected SOM getSOM() throws IOException { + if (header != null) { + return new SOM(getPath().toOSString(), header.getObjectDataOffset()); + } return new SOM(getPath().toOSString()); } @@ -159,8 +193,7 @@ public class SOMBinaryObject extends BinaryObjectAdapter { for (int i = 0; i < peSyms.length; i++) { if (peSyms[i].isFunction() || peSyms[i].isVariable()) { String name = peSyms[i].getName(table); - if (name == null || name.trim().length() == 0 || - !Character.isJavaIdentifierStart(name.charAt(0))) { + if (name == null || name.trim().length() == 0 || !Character.isJavaIdentifierStart(name.charAt(0))) { continue; } int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE; @@ -175,8 +208,9 @@ public class SOMBinaryObject extends BinaryObjectAdapter { } if (addr2line != null) { try { - String filename = addr2line.getFileName(addr); - // Addr2line returns the funny "??" when it can not find the file. + String filename = addr2line.getFileName(addr); + // Addr2line returns the funny "??" when it can not find + // the file. if (filename != null && filename.equals("??")) { //$NON-NLS-1$ filename = null; } @@ -205,25 +239,23 @@ public class SOMBinaryObject extends BinaryObjectAdapter { public Addr2line getAddr2line(boolean autodisposing) { if (!autodisposing) { - SOMParser parser = (SOMParser) getBinaryParser(); - return parser.getAddr2line(getPath()); + return getAddr2line(); } if (addr2line == null) { - SOMParser parser = (SOMParser) getBinaryParser(); - addr2line = parser.getAddr2line(getPath()); + addr2line = getAddr2line(); if (addr2line != null) { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); Runnable worker = new Runnable() { public void run() { - long diff = System.currentTimeMillis() - timestamp; + long diff = System.currentTimeMillis() - starttime; while (diff < 10000) { try { Thread.sleep(10000); } catch (InterruptedException e) { break; } - diff = System.currentTimeMillis() - timestamp; + diff = System.currentTimeMillis() - starttime; } stopAddr2Line(); } @@ -231,7 +263,7 @@ public class SOMBinaryObject extends BinaryObjectAdapter { new Thread(worker, "Addr2line Reaper").start(); //$NON-NLS-1$ } } else { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); } return addr2line; } @@ -243,17 +275,36 @@ public class SOMBinaryObject extends BinaryObjectAdapter { addr2line = null; } + /** + * @return + */ + private Addr2line getAddr2line() { + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getAddr2line(getPath()); + } + return null; + } + protected CPPFilt getCPPFilt() { - SOMParser parser = (SOMParser)getBinaryParser(); - return parser.getCPPFilt(); + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getCPPFilt(); + } + return null; } protected Objdump getObjdump() { - SOMParser parser = (SOMParser)getBinaryParser(); - return parser.getObjdump(getPath()); + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getObjdump(getPath()); + } + return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class adapter) { @@ -264,4 +315,4 @@ public class SOMBinaryObject extends BinaryObjectAdapter { } return super.getAdapter(adapter); } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryShared.java new file mode 100644 index 00000000000..789b78516e1 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMBinaryShared.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.som.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class SOMBinaryShared extends SOMBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param path + * @param type + */ + protected SOMBinaryShared(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.SHARED); + } +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMParser.java index d17f552548e..7f16c1424aa 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SOMParser.java @@ -16,22 +16,19 @@ import java.io.IOException; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.utils.Addr2line; -import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.DefaultGnuToolFactory; import org.eclipse.cdt.utils.IGnuToolFactory; -import org.eclipse.cdt.utils.Objdump; import org.eclipse.cdt.utils.som.AR; import org.eclipse.cdt.utils.som.SOM; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; /** * HP-UX SOM binary parser * * @author vhirsl */ -public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnuToolFactory { +public class SOMParser extends AbstractCExtension implements IBinaryParser { + private DefaultGnuToolFactory toolFactory; /* (non-Javadoc) * @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], org.eclipse.core.runtime.IPath) @@ -116,53 +113,32 @@ public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnu * @param path * @return */ - private IBinaryFile createBinaryExecutable(IPath path) { - return new SOMBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + private IBinaryExecutable createBinaryExecutable(IPath path) { + return new SOMBinaryExecutable(this, path); } /** * @param path * @return */ - private IBinaryFile createBinaryShared(IPath path) { - return new SOMBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + private IBinaryShared createBinaryShared(IPath path) { + return new SOMBinaryShared(this, path); } /** * @param path * @return */ - private IBinaryFile createBinaryObject(IPath path) { - return new SOMBinaryObject(this, path); + private IBinaryObject createBinaryObject(IPath path) { + return new SOMBinaryObject(this, path, IBinaryFile.OBJECT); } /** * @param path * @return */ - private IBinaryFile createBinaryCore(IPath path) { - return new SOMBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + private IBinaryObject createBinaryCore(IPath path) { + return new SOMBinaryObject(this, path, IBinaryFile.CORE); } /** @@ -170,98 +146,27 @@ public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnu * @return * @throws IOException */ - private IBinaryFile createBinaryArchive(IPath path) throws IOException { - return new BinaryArchive(this, path); + private IBinaryArchive createBinaryArchive(IPath path) throws IOException { + return new SOMBinaryArchive(this, path); } - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolFactory#getAddr2line(org.eclipse.core.runtime.IPath) + /** + * @return */ - public Addr2line getAddr2line(IPath path) { - IPath addr2LinePath = getAddr2linePath(); - Addr2line addr2line = null; - if (addr2LinePath != null && !addr2LinePath.isEmpty()) { - try { - addr2line = new Addr2line(addr2LinePath.toOSString(), path.toOSString()); - } catch (IOException e1) { - } - } - return addr2line; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolFactory#getCPPFilt() - */ - public CPPFilt getCPPFilt() { - IPath cppFiltPath = getCPPFiltPath(); - CPPFilt cppfilt = null; - if (cppFiltPath != null && ! cppFiltPath.isEmpty()) { - try { - cppfilt = new CPPFilt(cppFiltPath.toOSString()); - } catch (IOException e2) { - } - } - return cppfilt; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolFactory#getObjdump(org.eclipse.core.runtime.IPath) - */ - public Objdump getObjdump(IPath path) { - IPath objdumpPath = getObjdumpPath(); - String objdumpArgs = getObjdumpArgs(); - Objdump objdump = null; - if (objdumpPath != null && !objdumpPath.isEmpty()) { - try { - objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString()); - } catch (IOException e1) { - } - } - return objdump; - } - - protected IPath getAddr2linePath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "addr2line"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getObjdumpPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdump"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "objdump"; //$NON-NLS-1$ - } - return new Path(value); + protected DefaultGnuToolFactory createGNUToolFactory() { + return new DefaultGnuToolFactory(this); } - protected String getObjdumpArgs() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = ""; //$NON-NLS-1$ + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.equals(IGnuToolFactory.class)) { + if (toolFactory == null) { + toolFactory = createGNUToolFactory(); + } + return toolFactory; } - return value; - } - - protected IPath getCPPFiltPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "c++filt"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getStripPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("strip"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "strip"; //$NON-NLS-1$ - } - return new Path(value); + return super.getAdapter(adapter); } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SomSymbol.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SomSymbol.java index 3e202a560cc..9f17525853a 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SomSymbol.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/som/parser/SomSymbol.java @@ -38,7 +38,6 @@ public class SomSymbol extends Symbol { */ public SomSymbol(BinaryObjectAdapter binary, String name, int type, IAddress addr, long size, IPath sourceFile, int startLine, int endLine) { super(binary, name, type, addr, size, sourceFile, startLine, endLine); - // TODO Auto-generated constructor stub } /** @@ -50,7 +49,6 @@ public class SomSymbol extends Symbol { */ public SomSymbol(BinaryObjectAdapter binary, String name, int type, IAddress addr, long size) { super(binary, name, type, addr, size); - // TODO Auto-generated constructor stub } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/AR.java index 17e2c04d90d..81412837e6a 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/AR.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/AR.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.CCorePlugin; */ public class AR { protected String filename; - protected RandomAccessFile file; + private RandomAccessFile file; private ARHeader header; private MemberHeader[] memberHeaders; @@ -55,7 +55,7 @@ public class AR { public ARHeader() throws IOException { try { - getRandomAccessFile(); + RandomAccessFile file = getRandomAccessFile(); file.seek(0); file.read(fl_magic); if (isARHeader(fl_magic)) { @@ -210,6 +210,7 @@ public class AR { // // Read in the archive header data. Fixed sizes. // + RandomAccessFile file = getRandomAccessFile(); file.read(ar_size); file.read(ar_nxtmem); file.read(ar_prvmem); @@ -251,21 +252,13 @@ public class AR { return filename; } - /** - * Create a new XCOFF32 object for the object file. - * - * @throws IOException - * Not a valid XCOFF32 object file. - * @return A new XCOFF32 object. - * @see XCoff32#XCoff32( String, long ) - */ - public XCoff32 getXCoff() throws IOException { - return new XCoff32(filename, file_offset); + public long getObjectDataOffset() { + return file_offset; } - + public byte[] getObjectData() throws IOException { byte[] temp = new byte[(int) size]; - file = getRandomAccessFile(); + RandomAccessFile file = getRandomAccessFile(); file.seek(file_offset); file.read(temp); dispose(); @@ -349,7 +342,7 @@ public class AR { /** * Remove the padding from the archive header strings. */ - private String removeBlanks(String str) { + protected String removeBlanks(String str) { while (str.charAt(str.length() - 1) == ' ') str = str.substring(0, str.length() - 1); return str; @@ -359,7 +352,7 @@ public class AR { return extractFiles(outdir, null); } - private RandomAccessFile getRandomAccessFile () throws IOException { + protected RandomAccessFile getRandomAccessFile () throws IOException { if (file == null) { file = new RandomAccessFile(filename, "r"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/XCoff32.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/XCoff32.java index b5fea4bca2b..d6a94e676f8 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/XCoff32.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/XCoff32.java @@ -687,7 +687,7 @@ public class XCoff32 { public XCoff32(String filename, long offset) throws IOException { this.filename = filename; - commonSetup(new RandomAccessFile(filename, "r"), offset); + commonSetup(new RandomAccessFile(filename, "r"), offset); //$NON-NLS-1$ } void commonSetup(RandomAccessFile file, long offset) throws IOException { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/ARMember.java deleted file mode 100644 index e3530dba688..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/ARMember.java +++ /dev/null @@ -1,107 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation 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: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.utils.xcoff.parser; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.CPPFilt; -import org.eclipse.cdt.utils.Symbol; -import org.eclipse.cdt.utils.xcoff.AR; -import org.eclipse.cdt.utils.xcoff.XCoff32; -import org.eclipse.core.runtime.IPath; - -/** - * A member of an XCOFF32 archive - * - * @author vhirsl - */ -public class ARMember extends XCOFFBinaryObject { - private AR.MemberHeader header; - - /** - * @param parser - * @param path - */ - public ARMember(IBinaryParser parser, IPath path, AR.MemberHeader header) { - super(parser, path); - this.header = header; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() - */ - public InputStream getContents() { - InputStream stream = null; - if (path != null && header != null) { - try { - stream = new ByteArrayInputStream(header.getObjectData()); - } catch (IOException e) { - } - } - if (stream == null) { - stream = super.getContents(); - } - return stream; - } - - /** - * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getShortName() - */ - public String getName() { - if (header != null) { - return header.getObjectName(); - } - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.xcoff.parser.XCOFFBinaryObject#addSymbols(org.eclipse.cdt.utils.xcoff.XCoff32.Symbol[], byte[], org.eclipse.cdt.utils.Addr2line, org.eclipse.cdt.utils.CPPFilt, org.eclipse.cdt.utils.CygPath, java.util.List) - */ - protected void addSymbols(XCoff32.Symbol[] peSyms, byte[] table, List list) { - CPPFilt cppfilt = getCPPFilt(); - for (int i = 0; i < peSyms.length; i++) { - if (peSyms[i].isFunction() || peSyms[i].isVariable()) { - String name = peSyms[i].getName(table); - if (name == null || name.trim().length() == 0 /*|| - !Character.isJavaIdentifierStart(name.charAt(0))*/) { - continue; - } - if (cppfilt != null) { - try { - name = cppfilt.getFunction(name); - } catch (IOException e1) { - cppfilt = null; - } - } - Symbol sym = new Symbol(this, name, peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE, new Addr32(peSyms[i].n_value), 1); - - list.add(sym); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.xcoff.parser.XCOFFBinaryObject#getXCoff32() - */ - protected XCoff32 getXCoff32() throws IOException { - if (header != null) { - return header.getXCoff(); - } - throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFF32Parser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFF32Parser.java index 1c4a11aabec..21417e18c6c 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFF32Parser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFF32Parser.java @@ -16,25 +16,26 @@ import java.io.IOException; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.utils.Addr2line; -import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.DefaultGnuToolFactory; import org.eclipse.cdt.utils.IGnuToolFactory; -import org.eclipse.cdt.utils.Objdump; import org.eclipse.cdt.utils.xcoff.AR; import org.eclipse.cdt.utils.xcoff.XCoff32; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; /** * XCOFF 32bit binary parser for AIX * * @author vhirsl */ -public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser, IGnuToolFactory { +public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], org.eclipse.core.runtime.IPath) + private IGnuToolFactory toolFactory; + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], + * org.eclipse.core.runtime.IPath) */ public IBinaryFile getBinary(byte[] hints, IPath path) throws IOException { if (path == null) { @@ -52,26 +53,26 @@ public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser, // continue, the array was to small. } } - - //Take a second run at it if the data array failed. - if(attribute == null) { + + //Take a second run at it if the data array failed. + if (attribute == null) { attribute = XCoff32.getAttributes(path.toOSString()); - } - + } + if (attribute != null) { switch (attribute.getType()) { case XCoff32.Attribute.XCOFF_TYPE_EXE : binary = createBinaryExecutable(path); break; - + case XCoff32.Attribute.XCOFF_TYPE_SHLIB : binary = createBinaryShared(path); break; - + case XCoff32.Attribute.XCOFF_TYPE_OBJ : binary = createBinaryObject(path); break; - + case XCoff32.Attribute.XCOFF_TYPE_CORE : binary = createBinaryCore(path); break; @@ -84,28 +85,37 @@ public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser, return binary; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath) */ public IBinaryFile getBinary(IPath path) throws IOException { return getBinary(null, path); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.IBinaryParser#getFormat() */ public String getFormat() { return "XCOFF32"; //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], org.eclipse.core.runtime.IPath) + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], + * org.eclipse.core.runtime.IPath) */ public boolean isBinary(byte[] hints, IPath path) { return XCoff32.isXCOFF32Header(hints) || AR.isARHeader(hints); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.IBinaryParser#getHintBufferSize() */ public int getHintBufferSize() { @@ -117,151 +127,61 @@ public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser, * @return */ private IBinaryFile createBinaryExecutable(IPath path) { - return new XCOFFBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.EXECUTABLE; - } - }; + return new XCOFFBinaryExecutable(this, path); } /** * @param path * @return */ - private IBinaryFile createBinaryShared(IPath path) { - return new XCOFFBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.SHARED; - } - }; + private IBinaryShared createBinaryShared(IPath path) { + return new XCOFFBinaryShared(this, path); } /** * @param path * @return */ - private IBinaryFile createBinaryObject(IPath path) { - return new XCOFFBinaryObject(this, path); + private IBinaryObject createBinaryObject(IPath path) { + return new XCOFFBinaryObject(this, path, IBinaryFile.OBJECT); } /** * @param path * @return */ - private IBinaryFile createBinaryCore(IPath path) { - return new XCOFFBinaryObject(this, path) { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.CORE; - } - }; + private IBinaryObject createBinaryCore(IPath path) { + return new XCOFFBinaryObject(this, path, IBinaryFile.CORE); } /** * @param path - * @return - * @throws IOException + * @return @throws + * IOException */ private IBinaryFile createBinaryArchive(IPath path) throws IOException { - return new BinaryArchive(this, path); + return new XCOFFBinaryArchive(this, path); } - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getAddr2line(org.eclipse.core.runtime.IPath) + /** + * @return */ - public Addr2line getAddr2line(IPath path) { - IPath addr2LinePath = getAddr2linePath(); - Addr2line addr2line = null; - if (addr2LinePath != null && !addr2LinePath.isEmpty()) { - try { - addr2line = new Addr2line(addr2LinePath.toOSString(), path.toOSString()); - } catch (IOException e1) { - } - } - return addr2line; + private DefaultGnuToolFactory createGNUToolFactory() { + return new DefaultGnuToolFactory(this); } - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getCPPFilt() + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ - public CPPFilt getCPPFilt() { - IPath cppFiltPath = getCPPFiltPath(); - CPPFilt cppfilt = null; - if (cppFiltPath != null && ! cppFiltPath.isEmpty()) { - try { - cppfilt = new CPPFilt(cppFiltPath.toOSString()); - } catch (IOException e2) { + public Object getAdapter(Class adapter) { + if (adapter.equals(IGnuToolFactory.class)) { + if (toolFactory == null) { + toolFactory = createGNUToolFactory(); } + return toolFactory; } - return cppfilt; + return super.getAdapter(adapter); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.utils.IGnuToolProvider#getObjdump(org.eclipse.core.runtime.IPath) - */ - public Objdump getObjdump(IPath path) { - IPath objdumpPath = getObjdumpPath(); - String objdumpArgs = getObjdumpArgs(); - Objdump objdump = null; - if (objdumpPath != null && !objdumpPath.isEmpty()) { - try { - objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString()); - } catch (IOException e1) { - } - } - return objdump; - } - - protected IPath getAddr2linePath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "addr2line"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getObjdumpPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdump"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "objdump"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected String getObjdumpArgs() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = ""; //$NON-NLS-1$ - } - return value; - } - - protected IPath getCPPFiltPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "c++filt"; //$NON-NLS-1$ - } - return new Path(value); - } - - protected IPath getStripPath() { - ICExtensionReference ref = getExtensionReference(); - String value = ref.getExtensionData("strip"); //$NON-NLS-1$ - if (value == null || value.length() == 0) { - value = "strip"; //$NON-NLS-1$ - } - return new Path(value); - } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryArchive.java similarity index 81% rename from core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/BinaryArchive.java rename to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryArchive.java index 7024c12dd08..0db5a2bb2cb 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryArchive.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IPath; * * @author vhirsl */ -public class BinaryArchive extends BinaryFile implements IBinaryArchive { +public class XCOFFBinaryArchive extends BinaryFile implements IBinaryArchive { private ArrayList children; /** @@ -34,18 +34,12 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { * @param path * @throws IOException */ - public BinaryArchive(IBinaryParser parser, IPath path) throws IOException { - super(parser, path); + public XCOFFBinaryArchive(IBinaryParser parser, IPath path) throws IOException { + super(parser, path, IBinaryFile.ARCHIVE); new AR(path.toOSString()).dispose(); // check file type children = new ArrayList(5); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() - */ - public int getType() { - return IBinaryFile.ARCHIVE; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.IBinaryParser.IBinaryArchive#getObjects() @@ -58,7 +52,7 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive { ar = new AR(getPath().toOSString()); AR.MemberHeader[] headers = ar.getHeaders(); for (int i = 0; i < headers.length; i++) { - IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]); + IBinaryObject bin = new XCOFFBinaryObject(getBinaryParser(), getPath(), headers[i]); children.add(bin); } } catch (IOException e) { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryExecutable.java new file mode 100644 index 00000000000..38fd8ff2de6 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryExecutable.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.xcoff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + + +public class XCOFFBinaryExecutable extends XCOFFBinaryObject implements IBinaryFile { + + /** + * @param parser + * @param path + * @param type + */ + public XCOFFBinaryExecutable(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryObject.java index 918713776e2..ac94cd98426 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryObject.java @@ -24,7 +24,9 @@ import org.eclipse.cdt.utils.Addr2line; import org.eclipse.cdt.utils.Addr32; import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.cdt.utils.IGnuToolFactory; import org.eclipse.cdt.utils.Objdump; +import org.eclipse.cdt.utils.xcoff.AR; import org.eclipse.cdt.utils.xcoff.XCoff32; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -38,15 +40,27 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { Addr2line addr2line; BinaryObjectInfo info; ISymbol[] symbols; + long starttime; + private AR.MemberHeader header; /** * @param parser * @param path + * @param type */ - public XCOFFBinaryObject(IBinaryParser parser, IPath path) { - super(parser, path); + public XCOFFBinaryObject(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); } + /** + * @param parser + * @param path + * @param header + */ + public XCOFFBinaryObject(IBinaryParser parser, IPath path, AR.MemberHeader header) { + super(parser, path, IBinaryFile.OBJECT); + this.header = header; + } /* * (non-Javadoc) * @@ -78,29 +92,31 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { } return info; } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType() + + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName() */ - public int getType() { - return IBinaryFile.OBJECT; + public String getName() { + if (header != null) { + return header.getObjectName(); + } + return super.getName(); } /** + * @throws IOException * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents() */ - public InputStream getContents() { + public InputStream getContents() throws IOException { InputStream stream = null; + if (getPath() != null && header != null) { + return new ByteArrayInputStream(header.getObjectData()); + } Objdump objdump = getObjdump(); if (objdump != null) { - try { - byte[] contents = objdump.getOutput(); - stream = new ByteArrayInputStream(contents); - } catch (IOException e) { - // Nothing - } + byte[] contents = objdump.getOutput(); + stream = new ByteArrayInputStream(contents); } if (stream == null) { stream = super.getContents(); @@ -109,6 +125,9 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { } protected XCoff32 getXCoff32() throws IOException { + if (header != null) { + return new XCoff32(getPath().toOSString(), header.getObjectDataOffset()); + } return new XCoff32(getPath().toOSString()); } @@ -210,25 +229,24 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { public Addr2line getAddr2line(boolean autodisposing) { if (!autodisposing) { - XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser(); - return parser.getAddr2line(getPath()); + return getAddr2line(); } if (addr2line == null) { XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser(); - addr2line = parser.getAddr2line(getPath()); + addr2line = getAddr2line(); if (addr2line != null) { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); Runnable worker = new Runnable() { public void run() { - long diff = System.currentTimeMillis() - timestamp; + long diff = System.currentTimeMillis() - starttime; while (diff < 10000) { try { Thread.sleep(10000); } catch (InterruptedException e) { break; } - diff = System.currentTimeMillis() - timestamp; + diff = System.currentTimeMillis() - starttime; } stopAddr2Line(); } @@ -236,7 +254,7 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { new Thread(worker, "Addr2line Reaper").start(); //$NON-NLS-1$ } } else { - timestamp = System.currentTimeMillis(); + starttime = System.currentTimeMillis(); } return addr2line; } @@ -248,14 +266,31 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { addr2line = null; } - protected CPPFilt getCPPFilt() { - XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser(); - return parser.getCPPFilt(); + /** + * @return + */ + private Addr2line getAddr2line() { + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getAddr2line(getPath()); + } + return null; } - protected Objdump getObjdump() { - XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser(); - return parser.getObjdump(getPath()); + private CPPFilt getCPPFilt() { + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getCPPFilt(); + } + return null; + } + + private Objdump getObjdump() { + IGnuToolFactory factory = (IGnuToolFactory)getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getObjdump(getPath()); + } + return null; } /* @@ -265,7 +300,7 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter { */ public Object getAdapter(Class adapter) { if (adapter == Addr2line.class) { - return getAddr2line(false); + return getAddr2line(); } else if (adapter == CPPFilt.class) { return getCPPFilt(); } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryShared.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryShared.java new file mode 100644 index 00000000000..91a142ee648 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCOFFBinaryShared.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004 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.utils.xcoff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + + +public class XCOFFBinaryShared extends XCOFFBinaryObject implements IBinaryShared { + + /** + * @param parser + * @param path + * @param type + */ + public XCOFFBinaryShared(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.SHARED); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCoffSymbol.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCoffSymbol.java index f062e85d44e..bd701ba00f9 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCoffSymbol.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/xcoff/parser/XCoffSymbol.java @@ -37,7 +37,6 @@ public class XCoffSymbol extends Symbol { public XCoffSymbol(BinaryObjectAdapter binary, String name, int type, IAddress addr, long size, IPath sourceFile, int startLine, int endLine) { super(binary, name, type, addr, size, sourceFile, startLine, endLine); - // TODO Auto-generated constructor stub } /** @@ -49,7 +48,6 @@ public class XCoffSymbol extends Symbol { */ public XCoffSymbol(BinaryObjectAdapter binary, String name, int type, IAddress addr, long size) { super(binary, name, type, addr, size); - // TODO Auto-generated constructor stub } /* (non-Javadoc)