1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

IBinaryParser extends IAdaptable.

Move the code so Coff and Elf parsers could share
more of the code.
This commit is contained in:
Alain Magloire 2004-03-05 02:26:39 +00:00
parent 70dac4bf81
commit f9a2675180
30 changed files with 1004 additions and 1192 deletions

View file

@ -1,3 +1,17 @@
2004-03-04 Alain Magloire
Large cleanup(?) of the BinaryParser classes.
They now extends IAdaptable.
* src/org/eclipse/cdt/core/IBinaryParser.java
* utils/org/eclipse/cdt/utils/BinaryFile.java
* utils/org/eclipse/cdt/utils/BinaryObjectAdapter.java
* utils/org/eclipse/cdt/utils/Symbol.java
* utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java
* utils/org/eclipse/cdt/utils/elf/parser/GNUElfBinaryObject.java
* utils/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java
* utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java
2004-03-04 Hoda Amer
The CModelBuilder is reporting to the TranslationUnit
whether parsing was successful or not.

View file

@ -10,10 +10,11 @@ import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
/**
*/
public class NullBinaryParser implements IBinaryParser {
public class NullBinaryParser extends PlatformObject implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)

View file

@ -1,10 +1,15 @@
/**********************************************************************
* Copyright (c) 2002,2003,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.core;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.io.IOException;
import java.io.InputStream;
@ -13,20 +18,53 @@ import org.eclipse.core.runtime.IPath;
/**
*/
public interface IBinaryParser {
public interface IBinaryParser extends IAdaptable {
/**
* Represents a binary file for example an ELF executable.
*/
interface IBinaryFile extends IAdaptable {
/**
* Binary is an object, can be safely typecast to IBinaryObject
*/
static final int OBJECT = 0x1;
/**
* Binary is an executable, can be typecast to IBinaryExectuable
*/
static final int EXECUTABLE = 0x02;
/**
* Binary is a DLL, can be use as a IBinaryShared
*/
static final int SHARED = 0x04;
/**
* Binary is an archive, IBinaryArchive
*/
static final int ARCHIVE = 0x08;
/**
* Binary is a core file, an IBinaryFile
*/
static final int CORE = 0x10;
/**
* Filename of the binary
* @return the path
*/
IPath getPath();
/**
* Binary type
* @return the type of the binary
*/
int getType();
/**
*
* @return the binary contents.
*/
InputStream getContents();
}
@ -42,8 +80,16 @@ public interface IBinaryParser {
*/
interface IBinaryObject extends IBinaryFile {
/**
* True if the binary contains debug information
* @return true if debug information
*/
boolean hasDebug();
/**
* CPU name
* @return String - cpu name
*/
String getCPU();
long getText();
@ -51,13 +97,30 @@ public interface IBinaryParser {
long getData();
long getBSS();
/**
* The endian
* @return boolean - true for little endian
*/
boolean isLittleEndian();
/**
* Symbols of the object
* @return ISymbol[] arrays of symbols
*/
ISymbol[] getSymbols();
/**
* Symbo at this address.
* @param addr
* @return ISymbol
*/
ISymbol getSymbol(long addr);
/**
* The name of the object
* @return String
*/
String getName();
}
@ -66,6 +129,11 @@ public interface IBinaryParser {
* An executable.
*/
interface IBinaryExecutable extends IBinaryObject {
/**
* Needed shared libraries for this executable
* @return String[] array
*/
String[] getNeededSharedLibs();
}
@ -73,20 +141,72 @@ public interface IBinaryParser {
* A DLL.
*/
interface IBinaryShared extends IBinaryExecutable {
/**
* The Share Object name.
* @return
*/
String getSoName();
}
interface ISymbol extends Comparable {
/**
* Symbol is type function.
*/
static final int FUNCTION = 0x01;
/**
* Symbol is type variable
*/
static final int VARIABLE = 0x02;
/**
* Name of the Symbol
* @return
*/
String getName();
/**
* Address of the symbol
* @return
*/
long getAddress();
/**
* Size of the symbol.
* @return
*/
long getSize();
/**
* Start linenumber of the symbol in the source
* @return
*/
int getStartLine();
/**
* End line number of the symbol in the source
* @return
*/
int getEndLine();
/**
* Source filename of the symbol.
* @return
*/
IPath getFilename();
/**
* Type of the symbol
* @return
*/
int getType();
/**
* Line number corresponding to the address offset.
* @param offset
* @return
*/
int getLineNumber(long offset);
}

View file

@ -1,10 +1,15 @@
/**********************************************************************
* Copyright (c) 2002,2003,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;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;

View file

@ -8,19 +8,15 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.utils.elf.parser;
package org.eclipse.cdt.utils;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.IToolsProvider;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.cdt.utils.elf.Elf.Attribute;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
@ -30,34 +26,16 @@ import org.eclipse.core.runtime.PlatformObject;
public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
protected IPath path;
protected IToolsProvider toolsProvider;
protected long timestamp;
protected IBinaryParser parser;
public BinaryFile(IPath p) {
path = p;
public BinaryFile(IBinaryParser parser, IPath path) {
this.path = path;
this.parser = parser;
}
public void setToolsProvider(IToolsProvider p) {
toolsProvider = p;
}
public Addr2line getAddr2Line() {
if (toolsProvider != null)
return toolsProvider.getAddr2Line(path);
return null;
}
public CPPFilt getCPPFilt() {
if (toolsProvider != null)
return toolsProvider.getCPPFilt();
return null;
}
public Objdump getObjdump() {
if (toolsProvider != null) {
return toolsProvider.getObjdump(path);
}
return null;
public IBinaryParser getBinaryParser() {
return parser;
}
/**
@ -78,19 +56,9 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
public InputStream getContents() {
InputStream stream = null;
if (path != null) {
Objdump objdump = getObjdump();
if (objdump != null) {
try {
byte[] contents = objdump.getOutput();
stream = new ByteArrayInputStream(contents);
} catch (IOException e) {
// Nothing
}
} else {
try {
stream = new FileInputStream(path.toFile());
} catch (IOException e) {
}
try {
stream = new FileInputStream(path.toFile());
} catch (IOException e) {
}
}
if (stream == null) {
@ -99,11 +67,6 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
return stream;
}
/**
* @return
*/
protected abstract Attribute getAttribute();
protected boolean hasChanged() {
long modification = getPath().toFile().lastModified();
boolean changed = modification != timestamp;

View file

@ -0,0 +1,210 @@
/**********************************************************************
* Copyright (c) 2002,2003,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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
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 {
protected ISymbol[] NO_SYMBOLS = new ISymbol[0];
public class BinaryObjectInfo {
public long bss;
public long data;
public long text;
public boolean hasDebug;
public boolean isLittleEndian;
public String soname;
public String[] needed;
public String cpu;
public BinaryObjectInfo() {
cpu = soname = ""; //$NON-NLS-1$
needed = new String[0];
}
}
public BinaryObjectAdapter(IBinaryParser parser, IPath path) {
super(parser, path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbol(long)
*/
public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols();
int insertion = Arrays.binarySearch(syms, new Long(addr));
if (insertion >= 0) {
return syms[insertion];
}
if (insertion == -1) {
return null;
}
insertion = -insertion - 1;
ISymbol symbol = syms[insertion - 1];
if (addr < (symbol.getAddress() + symbol.getSize())) {
return syms[insertion - 1];
}
return null;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS()
*/
public long getBSS() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.bss;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getCPU()
*/
public String getCPU() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.cpu;
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getData()
*/
public long getData() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.data;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getText()
*/
public long getText() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.text;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#hasDebug()
*/
public boolean hasDebug() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.hasDebug;
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#isLittleEndian()
*/
public boolean isLittleEndian() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.isLittleEndian;
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs()
*/
public String[] getNeededSharedLibs() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.needed;
}
return new String[0];
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName()
*/
public String getSoName() {
BinaryObjectInfo info = getBinaryObjectInfo();
if (info != null) {
return info.soname;
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
*/
public String getName() {
return getPath().lastSegment().toString();
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents()
*/
public InputStream getContents() {
InputStream stream = null;
Objdump objdump = getObjdump();
if (objdump != null) {
try {
byte[] contents = objdump.getOutput();
stream = new ByteArrayInputStream(contents);
} catch (IOException e) {
// Nothing
}
}
if (stream == null) {
stream = super.getContents();
}
return stream;
}
public String toString() {
return getName();
}
public Addr2line getAddr2line() {
return null;
}
public CPPFilt getCPPFilt() {
return null;
}
public Objdump getObjdump() {
return null;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols()
*/
public abstract ISymbol[] getSymbols();
protected abstract BinaryObjectInfo getBinaryObjectInfo();
}

View file

@ -12,7 +12,6 @@ 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;
@ -20,11 +19,7 @@ import org.eclipse.core.runtime.Path;
/*
* CygwinToolsProvider
*/
public class CygwinToolsProvider extends ToolsProvider implements ICygwinToolsProvider {
public CygwinToolsProvider(ICExtension cextension) {
super(cextension);
}
public class CygwinToolsProvider extends ToolsProvider {
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.ICygwinToolsProvider#getCygPath()
@ -41,7 +36,7 @@ public class CygwinToolsProvider extends ToolsProvider implements ICygwinToolsPr
return cygpath;
}
public IPath getCygPathPath() {
protected IPath getCygPathPath() {
ICExtensionReference ref = getExtensionReference();
String value = ref.getExtensionData("cygpath"); //$NON-NLS-1$
if (value == null || value.length() == 0) {

View file

@ -1,19 +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;
/**
*/
public interface ICygwinToolsProvider extends IToolsProvider {
CygPath getCygPath();
}

View file

@ -1,39 +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;
import org.eclipse.core.runtime.IPath;
/**
*/
public interface IToolsProvider {
/**
* Return Addr2Line for this executable
* @param path, the executable
* @return
*/
Addr2line getAddr2Line(IPath path);
/**
* Return CPPFilt to translate mangle names
* @return
*/
CPPFilt getCPPFilt();
/**
* Return Objdump for this executable
* @param path, the executable
* @return
*/
Objdump getObjdump(IPath path);
}

View file

@ -8,17 +8,16 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.utils.elf.parser;
package org.eclipse.cdt.utils;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.core.runtime.IPath;
public class Symbol implements ISymbol, Comparable {
BinaryObject binary;
BinaryObjectAdapter binary;
long timestamp;
Addr2line addr2line;
@ -30,7 +29,7 @@ public class Symbol implements ISymbol, Comparable {
public int type;
public long size;
public Symbol(BinaryObject bin) {
public Symbol(BinaryObjectAdapter bin) {
binary = bin;
}
/**
@ -114,7 +113,7 @@ public class Symbol implements ISymbol, Comparable {
synchronized Addr2line startAddr2Line () {
if (addr2line == null) {
addr2line = binary.getAddr2Line();
addr2line = binary.getAddr2line();
if (addr2line != null) {
timestamp = System.currentTimeMillis();
Runnable worker = new Runnable () {

View file

@ -12,7 +12,7 @@ package org.eclipse.cdt.utils;
import java.io.IOException;
import org.eclipse.cdt.core.ICExtension;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -20,19 +20,10 @@ import org.eclipse.core.runtime.Path;
/*
* ToolsProvider
*/
public class ToolsProvider implements IToolsProvider {
public class ToolsProvider extends AbstractCExtension {
ICExtension cextension;
public ToolsProvider(ICExtension cext) {
cextension = cext;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getAddr2Line(org.eclipse.core.runtime.IPath)
*/
public Addr2line getAddr2Line(IPath path) {
IPath addr2LinePath = getAddr2LinePath();
public Addr2line getAddr2line(IPath path) {
IPath addr2LinePath = getAddr2linePath();
Addr2line addr2line = null;
if (addr2LinePath != null && !addr2LinePath.isEmpty()) {
try {
@ -43,9 +34,6 @@ public class ToolsProvider implements IToolsProvider {
return addr2line;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
IPath cppFiltPath = getCPPFiltPath();
CPPFilt cppfilt = null;
@ -58,9 +46,6 @@ public class ToolsProvider implements IToolsProvider {
return cppfilt;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getObjdump(org.eclipse.core.runtime.IPath)
*/
public Objdump getObjdump(IPath path) {
IPath objdumpPath = getObjdumpPath();
String objdumpArgs = getObjdumpArgs();
@ -74,11 +59,7 @@ public class ToolsProvider implements IToolsProvider {
return objdump;
}
ICExtensionReference getExtensionReference() {
return cextension.getExtensionReference();
}
IPath getAddr2LinePath() {
protected IPath getAddr2linePath() {
ICExtensionReference ref = getExtensionReference();
String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$
if (value == null || value.length() == 0) {
@ -87,7 +68,7 @@ public class ToolsProvider implements IToolsProvider {
return new Path(value);
}
IPath getObjdumpPath() {
protected IPath getObjdumpPath() {
ICExtensionReference ref = getExtensionReference();
String value = ref.getExtensionData("objdump"); //$NON-NLS-1$
if (value == null || value.length() == 0) {
@ -96,7 +77,7 @@ public class ToolsProvider implements IToolsProvider {
return new Path(value);
}
String getObjdumpArgs() {
protected String getObjdumpArgs() {
ICExtensionReference ref = getExtensionReference();
String value = ref.getExtensionData("objdumpArgs"); //$NON-NLS-1$
if (value == null || value.length() == 0) {
@ -105,7 +86,7 @@ public class ToolsProvider implements IToolsProvider {
return value;
}
IPath getCPPFiltPath() {
protected IPath getCPPFiltPath() {
ICExtensionReference ref = getExtensionReference();
String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$
if (value == null || value.length() == 0) {
@ -114,4 +95,13 @@ public class ToolsProvider implements IToolsProvider {
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);
}
}

View file

@ -16,11 +16,12 @@ 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.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.ICygwinToolsProvider;
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;
@ -28,11 +29,11 @@ import org.eclipse.core.runtime.IPath;
/**
*/
public class ARMember extends BinaryObject {
public class ARMember extends PEBinaryObject {
PEArchive.ARHeader header;
public ARMember(IPath p, PEArchive.ARHeader h, ICygwinToolsProvider provider) throws IOException {
super(p, h.getPE(), provider);
public ARMember(IBinaryParser parser, IPath path, PEArchive.ARHeader h) throws IOException {
super(parser, path);
header = h;
}

View file

@ -8,11 +8,12 @@ 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.BinaryFile;
import org.eclipse.cdt.utils.coff.PEArchive;
import org.eclipse.cdt.utils.coff.PE.Attribute;
import org.eclipse.core.runtime.IPath;
/**
@ -21,9 +22,9 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
ArrayList children;
public BinaryArchive(IPath p) throws IOException {
super(p);
new PEArchive(p.toOSString()).dispose(); // check file type
public BinaryArchive(IBinaryParser parser, IPath path) throws IOException {
super(parser, path);
new PEArchive(path.toOSString()).dispose(); // check file type
children = new ArrayList(5);
}
@ -38,7 +39,7 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
ar = new PEArchive(getPath().toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
IBinaryObject bin = new ARMember(path, headers[i], toolsProvider);
IBinaryObject bin = new ARMember(getBinaryParser(), path, headers[i]);
children.add(bin);
}
} catch (IOException e) {
@ -52,13 +53,6 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
return (IBinaryObject[])children.toArray(new IBinaryObject[0]);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/
public IPath getPath() {
return path;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
@ -78,11 +72,4 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
public void delete(IBinaryObject[] objs) throws IOException {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.coff.parser.BinaryFile#getAttribute()
*/
protected Attribute getAttribute() {
return null;
}
}

View file

@ -1,41 +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.coff.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.core.runtime.IPath;
/**
*/
public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
public BinaryExecutable(IPath path) throws IOException {
super(path);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs()
*/
public String[] getNeededSharedLibs() {
return new String[0];
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.EXECUTABLE;
}
}

View file

@ -1,121 +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.coff.parser;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.ICygwinToolsProvider;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.cdt.utils.coff.PE.Attribute;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
/**
*
*/
public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
protected IPath path;
protected ICygwinToolsProvider toolsProvider;
protected long timestamp;
public BinaryFile(IPath p) {
path = p;
}
public void setToolsProvider(ICygwinToolsProvider p) {
toolsProvider = p;
}
public Addr2line getAddr2Line() {
if (toolsProvider != null)
return toolsProvider.getAddr2Line(path);
return null;
}
public CPPFilt getCPPFilt() {
if (toolsProvider != null)
return toolsProvider.getCPPFilt();
return null;
}
public CygPath getCygPath() {
if (toolsProvider != null)
return toolsProvider.getCygPath();
return null;
}
public Objdump getObjdump() {
if (toolsProvider != null) {
return toolsProvider.getObjdump(path);
}
return null;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/
public IPath getPath() {
return path;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public abstract int getType();
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents()
*/
public InputStream getContents() {
InputStream stream = null;
if (path != null) {
Objdump objdump = getObjdump();
if (objdump != null) {
try {
byte[] contents = objdump.getOutput();
stream = new ByteArrayInputStream(contents);
} catch (IOException e) {
// Nothing
}
} else {
try {
stream = new FileInputStream(path.toFile());
} catch (IOException e) {
}
}
}
if (stream == null) {
stream = new ByteArrayInputStream(new byte[0]);
}
return stream;
}
/**
* @return
*/
protected abstract Attribute getAttribute();
protected boolean hasChanged() {
long modification = getPath().toFile().lastModified();
boolean changed = modification != timestamp;
timestamp = modification;
return changed;
}
}

View file

@ -1,51 +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.coff.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.core.runtime.IPath;
/**
*/
public class BinaryShared extends BinaryExecutable implements IBinaryShared {
String soname;
public BinaryShared(IPath path) throws IOException {
super(path);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName()
*/
public String getSoName() {
if (hasChanged()) {
try {
loadInformation();
} catch (IOException e) {
}
}
if (soname != null) {
return soname;
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.SHARED;
}
}

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2002,2003,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.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.core.runtime.IPath;
/*
* CygwinPEBinaryObject
*/
public class CygwinPEBinaryObject extends PEBinaryObject {
/**
* @param parser
* @param path
*/
public CygwinPEBinaryObject(CygwinPEParser parser, IPath path) {
super(parser, path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
*/
public Addr2line getAddr2line() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
return parser.getAddr2line(getPath());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
return parser.getCPPFilt();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
*/
public Objdump getObjdump() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
return parser.getObjdump(getPath());
}
}

View file

@ -10,31 +10,12 @@
***********************************************************************/
package org.eclipse.cdt.utils.coff.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.CygwinToolsProvider;
import org.eclipse.cdt.utils.ICygwinToolsProvider;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.core.runtime.IPath;
/**
*/
public class CygwinPEParser extends PEParser implements IBinaryParser, ICygwinToolsProvider {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath)
*/
public IBinaryFile getBinary(byte[] hints, IPath path) throws IOException {
IBinaryFile binary = super.getBinary(hints, path);
if (binary instanceof BinaryFile) {
((BinaryFile)binary).setToolsProvider(this);
}
return binary;
}
public class CygwinPEParser extends PEParser {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getFormat()
@ -43,31 +24,64 @@ public class CygwinPEParser extends PEParser implements IBinaryParser, ICygwinTo
return "Cygwin PE"; //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.ICygwinToolsProvider#getCygPath()
/**
* @param path
* @return
*/
public CygPath getCygPath() {
return new CygwinToolsProvider(this).getCygPath();
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;
}
};
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getAddr2Line(org.eclipse.core.runtime.IPath)
/**
* @param path
* @return
*/
public Addr2line getAddr2Line(IPath path) {
return new CygwinToolsProvider(this).getAddr2Line(path);
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;
}
};
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getCPPFilt()
/**
* @param path
* @return
*/
public CPPFilt getCPPFilt() {
return new CygwinToolsProvider(this).getCPPFilt();
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;
}
};
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.IToolsProvider#getObjdump(org.eclipse.core.runtime.IPath)
/**
* @param path
* @return
*/
public Objdump getObjdump(IPath path) {
return new CygwinToolsProvider(this).getObjdump(path);
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;
}
};
}
}

View file

@ -15,102 +15,35 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.BinaryObjectAdapter;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.ICygwinToolsProvider;
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.PE.Attribute;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
*/
public class BinaryObject extends BinaryFile implements IBinaryObject {
public class PEBinaryObject extends BinaryObjectAdapter {
PE.Attribute attribute;
BinaryObjectInfo info;
ISymbol[] symbols;
int type = IBinaryFile.OBJECT;
private ISymbol[] NO_SYMBOLS = new ISymbol[0];
public BinaryObject(IPath p) throws IOException {
super(p);
}
public BinaryObject(IPath p, PE pe, ICygwinToolsProvider provider) throws IOException {
super(p);
setToolsProvider(provider);
loadInformation(pe);
pe.dispose();
hasChanged();
}
public void setType(int t) {
type = t;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbol(long)
*/
public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols();
int insertion = Arrays.binarySearch(syms, new Long(addr));
if (insertion >= 0) {
return syms[insertion];
}
if (insertion == -1) {
return null;
}
insertion = -insertion - 1;
ISymbol symbol = syms[insertion - 1];
if (addr < (symbol.getAddress() + symbol.getSize())) {
return syms[insertion - 1];
}
return null;
public PEBinaryObject(IBinaryParser parser, IPath path) {
super(parser, path);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return type;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS()
*/
public long getBSS() {
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getCPU()
*/
public String getCPU() {
Attribute attr = getAttribute();
if (attr != null) {
return attribute.getCPU();
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getData()
*/
public long getData() {
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
*/
public String getName() {
return getPath().lastSegment().toString();
return IBinaryFile.CORE;
}
/**
@ -119,100 +52,68 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
public ISymbol[] getSymbols() {
if (hasChanged() || symbols == null) {
try {
loadInformation();
loadAll();
} catch (IOException e) {
}
if (symbols == null) {
symbols = NO_SYMBOLS;
}
}
return symbols;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getText()
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo()
*/
public long getText() {
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#hasDebug()
*/
public boolean hasDebug() {
Attribute attr = getAttribute();
if (attr != null) {
return attr.hasDebug();
protected BinaryObjectInfo getBinaryObjectInfo() {
if (hasChanged() || info == null) {
try {
loadInfo();
} catch (IOException e) {
info = new BinaryObjectInfo();
}
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#isLittleEndian()
*/
public boolean isLittleEndian() {
Attribute attr = getAttribute();
if (attr != null) {
return attr.isLittleEndian();
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs()
*/
public String[] getNeededSharedLibs() {
return new String[0];
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName()
*/
public String getSoName() {
return ""; //$NON-NLS-1$
return null;
}
protected PE getPE() throws IOException {
return new PE(getPath().toOSString());
}
protected PE.Attribute getAttribute() {
if (hasChanged()) {
PE pe = null;
try {
pe = getPE();
loadAttributes(pe);
} catch (IOException e) {
} finally {
if (pe != null) {
try {
pe.dispose();
} catch (IOException e1) {
}
}
protected void loadAll() throws IOException {
PE pe = null;
try {
pe = getPE();
loadInfo(pe);
loadSymbols(pe);
} finally {
if (pe != null) {
pe.dispose();
}
}
return attribute;
}
protected void loadInformation() throws IOException {
PE pe = getPE();
loadInformation(pe);
pe.dispose();
protected void loadInfo() throws IOException {
PE pe = null;
try {
pe = getPE();
loadInfo(pe);
} finally {
if (pe != null) {
pe.dispose();
}
}
}
private void loadInformation(PE pe) throws IOException {
loadAttributes(pe);
loadSymbols(pe);
protected void loadInfo(PE pe) throws IOException {
info = new BinaryObjectInfo();
PE.Attribute attribute = getPE().getAttribute();
info.isLittleEndian = attribute.isLittleEndian();
info.hasDebug = attribute.hasDebug();
info.cpu = attribute.getCPU();
}
private void loadAttributes(PE pe) throws IOException {
attribute = pe.getAttribute();
}
private void loadSymbols(PE pe) throws IOException {
protected void loadSymbols(PE pe) throws IOException {
ArrayList list = new ArrayList();
Addr2line addr2line = getAddr2Line();
Addr2line addr2line = getAddr2line();
CPPFilt cppfilt = getCPPFilt();
CygPath cygpath = getCygPath();
@ -252,6 +153,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
try {
sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) {
cppfilt = null;
}
}
@ -275,6 +177,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
}
sym.startLine = addr2line.getLineNumber(sym.addr);
} catch (IOException e) {
addr2line = null;
}
}
list.add(sym);
@ -282,4 +185,11 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
}
}
/**
* @return
*/
private CygPath getCygPath() {
return null;
}
}

View file

@ -14,9 +14,9 @@ package org.eclipse.cdt.utils.coff.parser;
import java.io.EOFException;
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.CygwinToolsProvider;
import org.eclipse.cdt.utils.coff.PE;
import org.eclipse.cdt.utils.coff.PEArchive;
import org.eclipse.cdt.utils.coff.PEConstants;
@ -25,7 +25,7 @@ import org.eclipse.core.runtime.IPath;
/**
*/
public class PEParser extends AbstractCExtension implements IBinaryParser {
public class PEParser extends CygwinToolsProvider implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)
@ -42,7 +42,7 @@ public class PEParser extends AbstractCExtension implements IBinaryParser {
throw new IOException(CCorePlugin.getResourceString("Util.exception.nullPath")); //$NON-NLS-1$
}
BinaryFile binary = null;
IBinaryFile binary = null;
try {
PE.Attribute attribute = null;
if (hints != null && hints.length > 0) {
@ -60,27 +60,25 @@ public class PEParser extends AbstractCExtension implements IBinaryParser {
if (attribute != null) {
switch (attribute.getType()) {
case Attribute.PE_TYPE_EXE :
binary = new BinaryExecutable(path);
binary = createBinaryExecutable(path);
break;
case Attribute.PE_TYPE_SHLIB :
binary = new BinaryShared(path);
binary = createBinaryShared(path);
break;
case Attribute.PE_TYPE_OBJ :
binary = new BinaryObject(path);
binary = createBinaryObject(path);
break;
case Attribute.PE_TYPE_CORE :
BinaryObject obj = new BinaryObject(path);
obj.setType(IBinaryFile.CORE);
binary = obj;
binary = createBinaryCore(path);
break;
}
}
} catch (IOException e) {
// Is it an Archive?
binary = new BinaryArchive(path);
binary = createBinaryArchive(path);
}
return binary;
@ -133,4 +131,72 @@ public class PEParser extends AbstractCExtension implements IBinaryParser {
return 512;
}
/**
* @param path
* @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;
}
};
}
/**
* @param path
* @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;
}
};
}
/**
* @param path
* @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;
}
};
}
/**
* @param path
* @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;
}
};
}
/**
* @param path
* @return
*/
protected IBinaryArchive createBinaryArchive(IPath path) throws IOException {
return new BinaryArchive(this, path);
}
}

View file

@ -1,152 +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.coff.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.core.runtime.IPath;
public class Symbol implements ISymbol {
BinaryObject binary;
Addr2line addr2line;
long timestamp;
public IPath filename;
public int startLine;
public int endLine;
public long addr;
public long size;
public String name;
public int type;
public Symbol(BinaryObject bin) {
binary = bin;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getInitialFilename()
*/
public IPath getFilename() {
return filename;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getName()
*/
public String getName() {
return name;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getType()
*/
public int getType() {
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getAdress()
*/
public long getAddress() {
return addr;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getEndLine()
*/
public int getEndLine() {
return endLine;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getStartLine()
*/
public int getStartLine() {
return startLine;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getLineNumber(long)
*/
public int getLineNumber(long offset) {
int line = -1;
try {
Addr2line addressToLine = startAddr2Line();
if (addressToLine != null) {
line = addressToLine.getLineNumber(addr + offset);
}
} catch (IOException e) {
}
return line;
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object obj) {
long thisVal = 0;
long anotherVal = 0;
if (obj instanceof Symbol) {
Symbol sym = (Symbol) obj;
thisVal = this.addr;
anotherVal = sym.addr;
} else if (obj instanceof Long) {
Long val = (Long) obj;
anotherVal = val.longValue();
thisVal = (long) this.addr;
}
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getSize()
*/
public long getSize() {
return size;
}
synchronized Addr2line startAddr2Line () {
if (addr2line == null) {
addr2line = binary.getAddr2Line();
if (addr2line != null) {
timestamp = System.currentTimeMillis();
Runnable worker = new Runnable () {
public void run() {
long diff = System.currentTimeMillis() - timestamp;
while (diff < 10000) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
break;
}
diff = System.currentTimeMillis() - timestamp;
}
stopAddr2Line();
}
};
new Thread(worker, "Addr2line Reaper").start(); //$NON-NLS-1$
}
} else {
timestamp = System.currentTimeMillis();
}
return addr2line;
}
synchronized void stopAddr2Line() {
if (addr2line != null) {
addr2line.dispose();
}
addr2line = null;
}
}

View file

@ -16,21 +16,23 @@ 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.CPPFilt;
import org.eclipse.cdt.utils.IToolsProvider;
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 BinaryObject {
public class ARMember extends ElfBinaryObject {
AR.ARHeader header;
public ARMember(IPath p, AR.ARHeader h, IToolsProvider provider) throws IOException {
super(p, new ElfHelper(h.getElf()), provider);
public ARMember(IBinaryParser parser, IPath p, AR.ARHeader h) throws IOException {
super(parser, p);
header = h;
}

View file

@ -13,9 +13,11 @@ 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.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.utils.BinaryFile;
import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.cdt.utils.elf.Elf.Attribute;
import org.eclipse.core.runtime.IPath;
@ -25,10 +27,9 @@ import org.eclipse.core.runtime.IPath;
public class BinaryArchive extends BinaryFile implements IBinaryArchive {
ArrayList children;
long timestamp;
public BinaryArchive(IPath p) throws IOException {
super(p);
public BinaryArchive(IBinaryParser parser, IPath p) throws IOException {
super(parser, p);
new AR(p.toOSString()).dispose(); // check file type
children = new ArrayList(5);
}
@ -44,7 +45,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(getPath(), headers[i], toolsProvider);
IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]);
children.add(bin);
}
} catch (IOException e) {
@ -77,11 +78,4 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
public void delete(IBinaryObject[] objs) throws IOException {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.elf.parser.BinaryFile#getAttribute()
*/
protected Attribute getAttribute() {
return null;
}
}

View file

@ -1,50 +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.elf.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.core.runtime.IPath;
/**
*/
public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
public BinaryExecutable(IPath path) throws IOException {
super(path);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryExecutable#getNeededSharedLibs()
*/
public String[] getNeededSharedLibs() {
if (hasChanged()) {
try {
loadInformation();
} catch (IOException e) {
}
}
if (needed != null) {
return needed;
}
return new String[0];
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.EXECUTABLE;
}
}

View file

@ -1,298 +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.elf.parser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.IToolsProvider;
import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.cdt.utils.elf.ElfHelper;
import org.eclipse.cdt.utils.elf.Elf.Attribute;
import org.eclipse.cdt.utils.elf.ElfHelper.Sizes;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
*/
public class BinaryObject extends BinaryFile implements IBinaryObject {
protected String soname;
protected String[] needed;
protected int type = IBinaryFile.OBJECT;
private Sizes sizes;
private Attribute attribute;
private ISymbol[] symbols;
private ISymbol[] NO_SYMBOLS = new ISymbol[0];
public BinaryObject(IPath path) throws IOException {
super(path);
}
public BinaryObject(IPath path, ElfHelper helper, IToolsProvider provider) throws IOException {
super(path);
setToolsProvider(provider);
loadInformation(helper);
helper.dispose();
hasChanged();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbol(long)
*/
public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols();
int insertion = Arrays.binarySearch(syms, new Long(addr));
if (insertion >= 0) {
return syms[insertion];
}
if (insertion == -1) {
return null;
}
insertion = -insertion - 1;
ISymbol symbol = syms[insertion - 1];
if (addr < (symbol.getAddress() + symbol.getSize())) {
return syms[insertion - 1];
}
return null;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS()
*/
public long getBSS() {
Sizes sz = getSizes();
if (sz != null) {
return sizes.bss;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getCPU()
*/
public String getCPU() {
Attribute attr = getAttribute();
if (attr != null) {
return attribute.getCPU();
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getData()
*/
public long getData() {
Sizes sz = getSizes();
if (sz != null) {
return sizes.data;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getText()
*/
public long getText() {
Sizes sz = getSizes();
if (sz != null) {
return sizes.text;
}
return 0;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#hasDebug()
*/
public boolean hasDebug() {
Attribute attr = getAttribute();
if (attr != null) {
return attribute.hasDebug();
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#isLittleEndian()
*/
public boolean isLittleEndian() {
Attribute attr = getAttribute();
if (attr != null) {
return attribute.isLittleEndian();
}
return false;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return type;
}
public void setType(int t) {
type = t;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols()
*/
public ISymbol[] getSymbols() {
if (hasChanged() || symbols == null) {
try {
loadInformation();
} catch (IOException e) {
}
if (symbols == null) {
symbols = NO_SYMBOLS;
}
}
return symbols;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
*/
public String getName() {
return getPath().lastSegment().toString();
}
public String toString() {
return getName();
}
protected Attribute getAttribute() {
if (hasChanged()) {
ElfHelper helper = null;
try {
helper = getElfHelper();
loadAttributes(helper);
} catch (IOException e) {
} finally {
if (helper != null) {
helper.dispose();
}
}
}
return attribute;
}
protected Sizes getSizes() {
if (hasChanged()) {
ElfHelper helper = null;
try {
helper = getElfHelper();
loadAttributes(helper);
} catch (IOException e) {
} finally {
if (helper != null) {
helper.dispose();
}
}
}
return sizes;
}
protected ElfHelper getElfHelper() throws IOException {
return new ElfHelper(getPath().toOSString());
}
protected void loadInformation() throws IOException {
ElfHelper helper = null;
try {
helper = getElfHelper();
loadInformation(helper);
} finally {
if (helper != null) {
helper.dispose();
}
}
}
private void loadInformation(ElfHelper helper) throws IOException {
loadAttributes(helper);
loadSymbols(helper);
}
private void loadAttributes(ElfHelper helper) throws IOException {
Elf.Dynamic[] sharedlibs = helper.getNeeded();
needed = new String[sharedlibs.length];
for (int i = 0; i < sharedlibs.length; i++) {
needed[i] = sharedlibs[i].toString();
}
sizes = helper.getSizes();
soname = helper.getSoname();
attribute = helper.getElf().getAttributes();
}
private void loadSymbols(ElfHelper helper) throws IOException {
ArrayList list = new ArrayList();
// Hack should be remove when Elf is clean
helper.getElf().setCppFilter(false);
Addr2line addr2line = getAddr2Line();
CPPFilt cppfilt = getCPPFilt();
addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, addr2line, cppfilt, list);
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, addr2line, cppfilt, list);
addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, addr2line, cppfilt, list);
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, addr2line, cppfilt, list);
list.trimToSize();
if (addr2line != null) {
addr2line.dispose();
}
if (cppfilt != null) {
cppfilt.dispose();
}
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
Arrays.sort(symbols);
list.clear();
}
protected void addSymbols(Elf.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt, List list) {
for (int i = 0; i < array.length; i++) {
Symbol sym = new Symbol(this);
sym.type = type;
sym.name = array[i].toString();
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) {
}
}
sym.addr = array[i].st_value;
sym.size = array[i].st_size;
sym.filename = null;
sym.startLine = 0;
sym.endLine = sym.startLine;
if (addr2line != null) {
try {
String filename = addr2line.getFileName(sym.addr);
// Addr2line returns the funny "??" when it can not find the file.
sym.filename = (filename != null && !filename.equals("??")) ? new Path(filename) : null; //$NON-NLS-1$
sym.startLine = addr2line.getLineNumber(sym.addr);
sym.endLine = addr2line.getLineNumber(sym.addr + sym.size - 1);
} catch (IOException e) {
}
}
list.add(sym);
}
}
}

View file

@ -1,50 +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.elf.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.core.runtime.IPath;
/**
*/
public class BinaryShared extends BinaryExecutable implements IBinaryShared {
public BinaryShared(IPath path) throws IOException {
super(path);
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryShared#getSoName()
*/
public String getSoName() {
if (hasChanged()) {
try {
loadInformation();
} catch (IOException e) {
}
}
if (soname != null) {
return soname;
}
return ""; //$NON-NLS-1$
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.SHARED;
}
}

View file

@ -0,0 +1,186 @@
/**********************************************************************
* Copyright (c) 2002,2003,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 java.util.Arrays;
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.*;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.BinaryObjectAdapter;
import org.eclipse.cdt.utils.CPPFilt;
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;
/*
* ElfBinaryObject
*/
public class ElfBinaryObject extends BinaryObjectAdapter {
private BinaryObjectInfo info;
private ISymbol[] symbols;
public ElfBinaryObject(IBinaryParser parser, IPath path) {
super(parser, path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.OBJECT;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbols()
*/
public ISymbol[] getSymbols() {
// Call the hasChanged first, to initialize the timestamp
if (hasChanged() || symbols == null) {
try {
loadAll();
} catch (IOException e) {
symbols = NO_SYMBOLS;
}
}
return symbols;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo()
*/
protected BinaryObjectInfo getBinaryObjectInfo() {
// Call the hasChanged first, to initialize the timestamp
if (hasChanged() || info == null) {
try {
loadInfo();
} catch (IOException e) {
info = new BinaryObjectInfo();
}
}
return info;
}
protected ElfHelper getElfHelper() throws IOException {
return new ElfHelper(getPath().toOSString());
}
protected void loadAll() throws IOException {
ElfHelper helper = null;
try {
helper = getElfHelper();
loadInfo(helper);
loadSymbols(helper);
} finally {
if (helper != null) {
helper.dispose();
}
}
}
protected void loadInfo() throws IOException {
ElfHelper helper = null;
try {
helper = getElfHelper();
loadInfo(helper);
} finally {
if (helper != null) {
helper.dispose();
}
}
}
protected void loadInfo(ElfHelper helper) throws IOException {
info = new BinaryObjectInfo();
Elf.Dynamic[] sharedlibs = helper.getNeeded();
info.needed = new String[sharedlibs.length];
for (int i = 0; i < sharedlibs.length; i++) {
info.needed[i] = sharedlibs[i].toString();
}
ElfHelper.Sizes sizes = helper.getSizes();
info.bss = sizes.bss;
info.data = sizes.data;
info.text = sizes.text;
info.soname = helper.getSoname();
Elf.Attribute attribute = helper.getElf().getAttributes();
info.isLittleEndian = attribute.isLittleEndian();
info.hasDebug = attribute.hasDebug();
info.cpu = attribute.getCPU();
}
protected void loadSymbols(ElfHelper helper) throws IOException {
ArrayList list = new ArrayList();
// Hack should be remove when Elf is clean
helper.getElf().setCppFilter(false);
Addr2line addr2line = getAddr2line();
CPPFilt cppfilt = getCPPFilt();
addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, addr2line, cppfilt, list);
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, addr2line, cppfilt, list);
addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, addr2line, cppfilt, list);
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, addr2line, cppfilt, list);
list.trimToSize();
if (addr2line != null) {
addr2line.dispose();
}
if (cppfilt != null) {
cppfilt.dispose();
}
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
Arrays.sort(symbols);
list.clear();
}
protected void addSymbols(Elf.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt, List list) {
for (int i = 0; i < array.length; i++) {
Symbol sym = new Symbol(this);
sym.type = type;
sym.name = array[i].toString();
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) {
cppfilt = null;
}
}
sym.addr = array[i].st_value;
sym.size = array[i].st_size;
sym.filename = null;
sym.startLine = 0;
sym.endLine = sym.startLine;
if (addr2line != null) {
try {
String filename = addr2line.getFileName(sym.addr);
// Addr2line returns the funny "??" when it can not find the file.
sym.filename = (filename != null && !filename.equals("??")) ? new Path(filename) : null; //$NON-NLS-1$
sym.startLine = addr2line.getLineNumber(sym.addr);
sym.endLine = addr2line.getLineNumber(sym.addr + sym.size - 1);
} catch (IOException e) {
addr2line = null;
}
}
list.add(sym);
}
}
}

View file

@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2002,2003 QNX Software Systems and others.
* Copyright (c) 2002,2003,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
@ -13,9 +13,9 @@ package org.eclipse.cdt.utils.elf.parser;
import java.io.EOFException;
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.ToolsProvider;
import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.cdt.utils.elf.Elf.Attribute;
@ -23,7 +23,7 @@ import org.eclipse.core.runtime.IPath;
/**
*/
public class ElfParser extends AbstractCExtension implements IBinaryParser {
public class ElfParser extends ToolsProvider implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)
@ -38,7 +38,7 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
throw new IOException(CCorePlugin.getResourceString("Util.exception.nullPath")); //$NON-NLS-1$
}
BinaryFile binary = null;
IBinaryFile binary = null;
try {
Elf.Attribute attribute = null;
if (hints != null && hints.length > 0) {
@ -57,26 +57,24 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
if (attribute != null) {
switch (attribute.getType()) {
case Attribute.ELF_TYPE_EXE :
binary = new BinaryExecutable(path);
binary = createBinaryExecutable(path);
break;
case Attribute.ELF_TYPE_SHLIB :
binary = new BinaryShared(path);
binary = createBinaryShared(path);
break;
case Attribute.ELF_TYPE_OBJ :
binary = new BinaryObject(path);
binary = createBinaryObject(path);
break;
case Attribute.ELF_TYPE_CORE :
BinaryObject obj = new BinaryObject(path);
obj.setType(IBinaryFile.CORE);
binary = obj;
binary = createBinaryCore(path);
break;
}
}
} catch (IOException e) {
binary = new BinaryArchive(path);
binary = createBinaryArchive(path);
}
return binary;
}
@ -101,4 +99,49 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
public int getHintBufferSize() {
return 128;
}
/**
* @param path
* @return
*/
protected IBinaryArchive createBinaryArchive(IPath path) throws IOException {
return new BinaryArchive(this, path);
}
protected IBinaryObject createBinaryObject(IPath path) throws IOException {
return new ElfBinaryObject(this, path);
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
}

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2002,2003,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.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.core.runtime.IPath;
/*
* GNUBinaryObject
*/
public class GNUElfBinaryObject extends ElfBinaryObject {
/**
* @param parser
* @param path
*/
public GNUElfBinaryObject(GNUElfParser parser, IPath path) {
super(parser, path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
*/
public Addr2line getAddr2line() {
GNUElfParser parser = (GNUElfParser)getBinaryParser();
return parser.getAddr2line(getPath());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
GNUElfParser parser = (GNUElfParser)getBinaryParser();
return parser.getCPPFilt();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
*/
public Objdump getObjdump() {
GNUElfParser parser = (GNUElfParser)getBinaryParser();
return parser.getObjdump(getPath());
}
}

View file

@ -12,29 +12,12 @@ package org.eclipse.cdt.utils.elf.parser;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.IToolsProvider;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.cdt.utils.ToolsProvider;
import org.eclipse.core.runtime.IPath;
/**
* GNUElfParser
*/
public class GNUElfParser extends ElfParser implements IBinaryParser, IToolsProvider {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath)
*/
public IBinaryFile getBinary(byte[] data, IPath path) throws IOException {
IBinaryFile binary = super.getBinary(data, path);
if (binary instanceof BinaryFile) {
((BinaryFile)binary).setToolsProvider(this);
}
return binary;
}
public class GNUElfParser extends ElfParser {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getFormat()
@ -43,19 +26,59 @@ public class GNUElfParser extends ElfParser implements IBinaryParser, IToolsProv
return "GNU ELF"; //$NON-NLS-1$
}
public Addr2line getAddr2Line(IPath path) {
ToolsProvider provider = new ToolsProvider(this);
return provider.getAddr2Line(path);
/* (non-Javadoc)
* @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;
}
};
}
/* (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;
}
};
}
public Objdump getObjdump(IPath path) {
ToolsProvider provider = new ToolsProvider(this);
return provider.getObjdump(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;
}
};
}
public CPPFilt getCPPFilt() {
return new ToolsProvider(this).getCPPFilt();
/* (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;
}
};
}
}