mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
major binary parser cleanup see change log
This commit is contained in:
parent
726c0f77b1
commit
24cdf54262
61 changed files with 2204 additions and 1941 deletions
|
@ -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
|
||||
|
|
329
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java
Normal file
329
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/AR.java
Normal file
|
@ -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 <code>AR</code> 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 <code>ARHeader</code> 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 <code>efile</code> file location.
|
||||
*
|
||||
* @param offset
|
||||
* Offset into the string table for first character of the name.
|
||||
* @throws IOException
|
||||
* <code>offset</code> 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 "/<number>", 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 <code>AR</code> 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("!<arch>") != 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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];
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 <code>AR</code> 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 {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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;
|
||||
|
||||
/**
|
||||
* <code>ElfHelper</code> is a wrapper class for the <code>Elf</code> class
|
||||
* to provide higher level API for sorting/searching the ELF data.
|
||||
*
|
||||
* @see Elf
|
||||
* <code>ElfHelper</code> is a wrapper class for the <code>Elf</code> 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 <code>ElfHelper</code> using an existing <code>Elf</code>
|
||||
* 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 <code>ElfHelper</code> 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 <code>ElfHelper</code> 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 <code>MachOHelper</code> using an existing <code>MachO</code>
|
||||
|
@ -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 <code>MachOHelper</code> 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 */
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
}
|
|
@ -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) {
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue