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

added new IBinaryMEthods, cleanup all parser so that their hierarchy is cleaner, ie. straight Elf parser is nolonger a toolls provider, this come from the GNU parser

This commit is contained in:
David Inglis 2004-07-15 17:29:47 +00:00
parent 6bf1fa6737
commit 75d6d6a68d
36 changed files with 1141 additions and 612 deletions

View file

@ -24,6 +24,7 @@ public class Addr2line {
private BufferedReader stdout;
private BufferedWriter stdin;
private String lastaddr, lastsymbol, lastline;
private boolean isDisposed = false;
public Addr2line(String command, String[] params, String file) throws IOException {
init(command, params, file);
@ -128,6 +129,7 @@ public class Addr2line {
} catch (IOException e) {
}
addr2line.destroy();
isDisposed = true;
}
}

View file

@ -10,14 +10,11 @@
*******************************************************************************/
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.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.core.runtime.IPath;
@ -164,42 +161,10 @@ public abstract class BinaryObjectAdapter extends BinaryFile implements IBinaryO
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()
*/

View file

@ -24,6 +24,7 @@ public class CPPFilt {
private Process cppfilt;
private BufferedReader stdout;
private BufferedWriter stdin;
private boolean isDisposed = false;
public CPPFilt(String command, String[] params) throws IOException {
init(command, params);
@ -70,5 +71,6 @@ public class CPPFilt {
catch (IOException e) {
}
cppfilt.destroy();
isDisposed = true;
}
}

View file

@ -1,48 +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;
import java.io.IOException;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/*
* CygwinToolsProvider
*/
public class CygwinToolsProvider extends ToolsProvider {
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.ICygwinToolsProvider#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);
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* 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;
/*
* CygwinToolsProvider
*/
public interface ICygwinToolsFactroy extends IGnuToolFactory {
public CygPath getCygPath();
}

View file

@ -0,0 +1,24 @@
/*
* Created on Jul 5, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.eclipse.cdt.utils;
import org.eclipse.core.runtime.IPath;
/**
* @author DInglis
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface IGnuToolFactory {
public abstract Addr2line getAddr2line(IPath path);
public abstract CPPFilt getCPPFilt();
public abstract Objdump getObjdump(IPath path);
}

View file

@ -10,86 +10,111 @@
*******************************************************************************/
package org.eclipse.cdt.utils;
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.core.runtime.IPath;
public class Symbol implements ISymbol, Comparable {
BinaryObjectAdapter binary;
long timestamp;
Addr2line addr2line;
protected final BinaryObjectAdapter binary;
private final String name;
public IPath filename;
public int startLine;
public int endLine;
public long addr;
public String name;
public int type;
public long size;
private final long addr;
private final int type;
private final long size;
private final int startLine;
private final int endLine;
private final IPath sourceFile;
public Symbol(BinaryObjectAdapter bin) {
binary = bin;
public Symbol(BinaryObjectAdapter binary, String name, int type, long addr, long size, IPath sourceFile, int startLine, int endLine) {
this.binary = binary;
this.name = name;
this.type = type;
this.addr = addr;
this.size = size;
this.startLine = startLine;
this.endLine = endLine;
this.sourceFile = sourceFile;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getInitialFilename()
public Symbol(BinaryObjectAdapter binary, String name, int type, long addr, long size) {
this.binary = binary;
this.name = name;
this.type = type;
this.addr = addr;
this.size = size;
this.startLine = -1;
this.endLine = -1;
this.sourceFile = null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getBinarObject()
*/
public IBinaryObject getBinarObject() {
return binary;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getFilename()
*/
public IPath getFilename() {
return filename;
return sourceFile;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getName()
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getName()
*/
public String getName() {
return name;
}
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getType()
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getType()
*/
public int getType() {
return type;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getAdress()
*/
public long getAddress() {
return addr;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getEndLine()
*/
public int getEndLine() {
return endLine;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getStartLine()
*/
public int getStartLine() {
return startLine;
}
/* (non-Javadoc)
/*
* (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;
return -1;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.ISymbol#getSize()
*/
public long getSize() {
@ -110,39 +135,4 @@ public class Symbol implements ISymbol, Comparable {
}
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
}
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

@ -1,107 +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;
import java.io.IOException;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/*
* ToolsProvider
*/
public class ToolsProvider extends AbstractCExtension {
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;
}
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;
}
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);
}
}

View file

@ -58,7 +58,7 @@ public class ReadMemoryAccess {
}
public short getUnsignedByte(int offset) {
return (short)bytes[offset];
return bytes[offset];
}
public short getShort() {
@ -167,7 +167,7 @@ public class ReadMemoryAccess {
}
public static long getUnsignedIntLE(byte[] b) {
return (long)(((b[3] & 0xff) << 24) |
return (((b[3] & 0xff) << 24) |
((b[2] & 0xff) << 16) |
((b[1] & 0xff) << 8) |
(b[0] & 0xff));
@ -182,7 +182,7 @@ public class ReadMemoryAccess {
}
public static int getIntLE(byte[] b) {
return (int)(((b[3] & 0xff) << 24) |
return (((b[3] & 0xff) << 24) |
((b[2] & 0xff) << 16) |
((b[1] & 0xff) << 8) |
(b[0] & 0xff));
@ -209,7 +209,7 @@ public class ReadMemoryAccess {
}
public static int getIntBE(byte[] b) {
return (int)(((b[0] & 0xff) << 24) |
return (((b[0] & 0xff) << 24) |
((b[1] & 0xff) << 16) |
((b[2] & 0xff) << 8) |
(b[3] & 0xff));
@ -224,7 +224,7 @@ public class ReadMemoryAccess {
}
public static long getUnsignedIntBE(byte[] b) {
return (long)(((b[0] & 0xff) << 24) |
return (((b[0] & 0xff) << 24) |
((b[1] & 0xff) << 16) |
((b[2] & 0xff) << 8) |
(b[3] & 0xff));
@ -263,7 +263,7 @@ public class ReadMemoryAccess {
((long)(b[3] & 0xff) << 24) |
((long)(b[2] & 0xff) << 16) |
((long)(b[1] & 0xff) << 8) |
((long)(b[0] & 0xff));
(b[0] & 0xff);
}
@ -293,7 +293,7 @@ public class ReadMemoryAccess {
((long)(b[4] & 0xff) << 24) |
((long)(b[5] & 0xff) << 16) |
((long)(b[6] & 0xff) << 8) |
((long)(b[7] & 0xff));
(b[7] & 0xff);
}
}

View file

@ -18,9 +18,6 @@ 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.Symbol;
import org.eclipse.cdt.utils.coff.Coff;
import org.eclipse.cdt.utils.coff.PE;
@ -71,7 +68,7 @@ public class ARMember extends PEBinaryObject {
throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$
}
protected void addSymbols(Coff.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cypath, List list) {
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);
@ -79,12 +76,8 @@ public class ARMember extends PEBinaryObject {
!Character.isJavaIdentifierStart(name.charAt(0))) {
continue;
}
Symbol sym = new Symbol(this);
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
sym.name = name;
sym.addr = peSyms[i].n_value;
list.add(sym);
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
list.add(new Symbol(this, name, type, peSyms[i].n_value, 1));
}
}
}

View file

@ -65,17 +65,4 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
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 {
}
}

View file

@ -1,25 +1,34 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
* reserved. This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
* Contributors: QNX Software Systems - Initial API and implementation
******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
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.Objdump;
import org.eclipse.cdt.utils.coff.Coff;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/*
* CygwinPEBinaryObject
* CygwinPEBinaryObject
*/
public class CygwinPEBinaryObject extends PEBinaryObject {
private Addr2line addr2line;
/**
* @param parser
* @param path
@ -28,28 +37,176 @@ public class CygwinPEBinaryObject extends PEBinaryObject {
super(parser, path);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
*/
public Addr2line getAddr2line() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
return parser.getAddr2line(getPath());
protected Addr2line getAddr2line(boolean autodisposing) {
if (!autodisposing) {
CygwinPEParser parser = (CygwinPEParser) getBinaryParser();
return parser.getAddr2line(getPath());
}
if (addr2line == null) {
CygwinPEParser parser = (CygwinPEParser) getBinaryParser();
addr2line = parser.getAddr2line(getPath());
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;
}
/* (non-Javadoc)
synchronized void stopAddr2Line() {
if (addr2line != null) {
addr2line.dispose();
}
addr2line = null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
protected CPPFilt getCPPFilt() {
CygwinPEParser parser = (CygwinPEParser) getBinaryParser();
return parser.getCPPFilt();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
*/
public Objdump getObjdump() {
CygwinPEParser parser = (CygwinPEParser)getBinaryParser();
protected Objdump getObjdump() {
CygwinPEParser parser = (CygwinPEParser) getBinaryParser();
return parser.getObjdump(getPath());
}
}
/**
* @return
*/
protected CygPath getCygPath() {
CygwinPEParser parser = (CygwinPEParser) getBinaryParser();
return parser.getCygPath();
}
/**
* @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;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.coff.parser.PEBinaryObject#addSymbols(org.eclipse.cdt.utils.coff.Coff.Symbol[],
* 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);
if (name == null || name.trim().length() == 0 || !Character.isJavaIdentifierStart(name.charAt(0))) {
continue;
}
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
int addr = peSyms[i].n_value;
int size = 4;
if (cppfilt != null) {
try {
name = cppfilt.getFunction(name);
} catch (IOException e1) {
cppfilt = null;
}
}
if (addr2line != null) {
try {
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;
}
if (filename != null) {
if (cygpath != null) {
filename = cygpath.getFileName(filename);
}
}
IPath file = filename != null ? new Path(filename) : Path.EMPTY;
int startLine = addr2line.getLineNumber(addr);
int endLine = addr2line.getLineNumber(addr + size - 1);
list.add(new CygwinSymbol(this, name, type, addr, size, file, startLine, endLine));
} catch (IOException e) {
addr2line = null;
}
} else {
list.add(new CygwinSymbol(this, name, type, addr, size));
}
}
}
if (cppfilt != null) {
cppfilt.dispose();
}
if (cygpath != null) {
cygpath.dispose();
}
if (addr2line != null) {
addr2line.dispose();
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
if (adapter == Addr2line.class) {
return getAddr2line(false);
} else if (adapter == CPPFilt.class) {
return getCPPFilt();
} else if (adapter == CygPath.class) {
return getCygPath();
}
return super.getAdapter(adapter);
}
}

View file

@ -10,12 +10,21 @@
*******************************************************************************/
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.ICygwinToolsFactroy;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
*/
public class CygwinPEParser extends PEParser {
public class CygwinPEParser extends PEParser implements ICygwinToolsFactroy {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getFormat()
@ -84,4 +93,119 @@ public class CygwinPEParser extends PEParser {
};
}
/* (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;
}
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);
}
}

View file

@ -0,0 +1,66 @@
/*
* Created on Jul 6, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.eclipse.cdt.utils.coff.parser;
import java.io.IOException;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.Symbol;
import org.eclipse.core.runtime.IPath;
/**
* @author DInglis
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
class CygwinSymbol extends Symbol {
/**
* @param binary
* @param name
* @param type
* @param addr
* @param size
* @param sourceFile
* @param startLine
* @param endLine
*/
public CygwinSymbol(CygwinPEBinaryObject binary, String name, int type, long addr, long size, IPath sourceFile, int startLine,
int endLine) {
super(binary, name, type, addr, size, sourceFile, startLine, endLine);
}
/**
* @param binary
* @param name
* @param type
* @param addr
* @param size
*/
public CygwinSymbol(CygwinPEBinaryObject binary, String name, int type, long addr, long size) {
super(binary, name, type, addr, size);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.Symbol#getLineNumber(long)
*/
public int getLineNumber(long offset) {
int line = -1;
Addr2line addr2line = ((CygwinPEBinaryObject)binary).getAddr2line(true);
if (addr2line != null) {
try {
return addr2line.getLineNumber(getAddress() + offset);
} catch (IOException e) {
// ignore
}
}
return line;
}
}

View file

@ -18,15 +18,11 @@ 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.Addr2line;
import org.eclipse.cdt.utils.BinaryObjectAdapter;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.Symbol;
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;
/**
*/
@ -34,7 +30,7 @@ public class PEBinaryObject extends BinaryObjectAdapter {
BinaryObjectInfo info;
ISymbol[] symbols;
public PEBinaryObject(IBinaryParser parser, IPath path) {
super(parser, path);
}
@ -60,7 +56,9 @@ public class PEBinaryObject extends BinaryObjectAdapter {
return symbols;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo()
*/
protected BinaryObjectInfo getBinaryObjectInfo() {
@ -113,83 +111,26 @@ public class PEBinaryObject extends BinaryObjectAdapter {
protected void loadSymbols(PE pe) throws IOException {
ArrayList list = new ArrayList();
Addr2line addr2line = getAddr2line();
CPPFilt cppfilt = getCPPFilt();
CygPath cygpath = getCygPath();
Coff.Symbol[] peSyms = pe.getSymbols();
byte[] table = pe.getStringTable();
addSymbols(peSyms, table, addr2line, cppfilt, cygpath, list);
addSymbols(peSyms, table, list);
if (addr2line != null) {
addr2line.dispose();
}
if (cppfilt != null) {
cppfilt.dispose();
}
if (cygpath != null) {
cygpath.dispose();
}
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
symbols = (ISymbol[]) list.toArray(NO_SYMBOLS);
Arrays.sort(symbols);
list.clear();
}
protected void addSymbols(Coff.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
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()) {
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))) {
if (name == null || name.trim().length() == 0 || !Character.isJavaIdentifierStart(name.charAt(0))) {
continue;
}
Symbol sym = new Symbol(this);
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
sym.addr = peSyms[i].n_value;
sym.name = name;
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) {
cppfilt = null;
}
}
sym.filename = null;
sym.startLine = 0;
sym.endLine = 0;
if (addr2line != null) {
try {
String filename = addr2line.getFileName(sym.addr);
// Addr2line returns the funny "??" when it can not find the file.
if (filename != null && filename.equals("??")) { //$NON-NLS-1$
filename = null;
}
if (filename != null) {
if (cygpath != null) {
sym.filename = new Path(cygpath.getFileName(filename));
} else {
sym.filename = new Path(filename);
}
}
sym.startLine = addr2line.getLineNumber(sym.addr);
} catch (IOException e) {
addr2line = null;
}
}
list.add(sym);
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
list.add(new Symbol(this, name, type, peSyms[i].n_value, 1));
}
}
}
/**
* @return
*/
private CygPath getCygPath() {
return null;
}
}
}

View file

@ -14,18 +14,19 @@ 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;
import org.eclipse.cdt.utils.coff.PE.Attribute;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
/**
*/
public class PEParser extends CygwinToolsProvider implements IBinaryParser {
public class PEParser extends AbstractCExtension implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)

View file

@ -41,9 +41,8 @@ public class ERandomAccessFile extends RandomAccessFile {
throw new EOFException();
if ( isle ) {
return (short)((val[1] << 8) + val[0]);
} else {
return (short)((val[0] << 8) + val[1]);
}
return (short)((val[0] << 8) + val[1]);
}
public final long readIntE() throws IOException
@ -56,9 +55,8 @@ public class ERandomAccessFile extends RandomAccessFile {
throw new EOFException();
if ( isle ) {
return ((val[3] << 24) + (val[2] << 16) + (val[1] << 8) + val[0]);
} else {
return ((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
}
return ((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
}
public void setFileOffset( long offset ) throws IOException {

View file

@ -18,8 +18,6 @@ import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
// test checkin
public class Elf {
@ -27,8 +25,6 @@ public class Elf {
protected ELFhdr ehdr;
protected Section[] sections;
protected Addr2line addr2line;
protected CPPFilt cppFilt;
protected String file;
protected byte[] section_strtab;
@ -184,9 +180,8 @@ public class Elf {
throw new IOException();
if ( isle ) {
return (short)((val[offset + 1] << 8) + val[offset + 0]);
} else {
return (short)((val[offset + 0] << 8) + val[offset + 1]);
}
return (short)((val[offset + 0] << 8) + val[offset + 1]);
}
private final long makeInt(byte [] val, int offset, boolean isle) throws IOException
@ -195,9 +190,8 @@ public class Elf {
throw new IOException();
if ( isle ) {
return ((val[offset + 3] << 24) + (val[offset + 2] << 16) + (val[offset + 1] << 8) + val[offset + 0]);
} else {
return ((val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]);
}
return ((val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]);
}
@ -729,12 +723,6 @@ public class Elf {
}
public void dispose() {
if (addr2line != null) {
addr2line.dispose();
}
if (cppFilt != null) {
cppFilt.dispose();
}
try {
if (efile != null) {
efile.close();

View file

@ -17,8 +17,6 @@ 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.Symbol;
import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.cdt.utils.elf.Elf;
@ -70,12 +68,9 @@ public class ARMember extends ElfBinaryObject {
throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$
}
protected void addSymbols(Elf.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt, List list) {
protected void addSymbols(Elf.Symbol[] array, int type, List list) {
for (int i = 0; i < array.length; i++) {
Symbol sym = new Symbol(this);
sym.type = type;
sym.name = array[i].toString();
sym.addr = array[i].st_value;
Symbol sym = new Symbol(this, array[i].toString(), type, array[i].st_value, array[i].st_size);
list.add(sym);
}
}

View file

@ -64,17 +64,4 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
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 {
}
}

View file

@ -18,14 +18,11 @@ 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.Symbol;
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
@ -128,56 +125,20 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
protected void loadSymbols(ElfHelper helper) throws IOException {
ArrayList list = new ArrayList();
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);
addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, list);
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, list);
addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, list);
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, 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) {
protected void addSymbols(Elf.Symbol[] array, int type, 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);
list.add(new Symbol(this, array[i].toString(), type, array[i].st_value, array[i].st_size));
}
}

View file

@ -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 ToolsProvider implements IBinaryParser {
public class ElfParser extends AbstractCExtension implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)

View file

@ -1,25 +1,32 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
* reserved. This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
* Contributors: QNX Software Systems - Initial API and implementation
******************************************************************************/
package org.eclipse.cdt.utils.elf.parser;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/*
* GNUBinaryObject
* GNUBinaryObject
*/
public class GNUElfBinaryObject extends ElfBinaryObject {
private Addr2line addr2line;
/**
* @param parser
* @param path
@ -28,28 +35,131 @@ public class GNUElfBinaryObject extends ElfBinaryObject {
super(parser, path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
*/
public Addr2line getAddr2line() {
GNUElfParser parser = (GNUElfParser)getBinaryParser();
return parser.getAddr2line(getPath());
public Addr2line getAddr2line(boolean autodisposing) {
if (!autodisposing) {
GNUElfParser parser = (GNUElfParser) getBinaryParser();
return parser.getAddr2line(getPath());
}
if (addr2line == null) {
GNUElfParser parser = (GNUElfParser) getBinaryParser();
addr2line = parser.getAddr2line(getPath());
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;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
GNUElfParser parser = (GNUElfParser)getBinaryParser();
synchronized void stopAddr2Line() {
if (addr2line != null) {
addr2line.dispose();
}
addr2line = null;
}
protected 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();
protected Objdump getObjdump() {
GNUElfParser parser = (GNUElfParser) getBinaryParser();
return parser.getObjdump(getPath());
}
}
/**
* @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
}
objdump.dispose();
}
if (stream == null) {
stream = super.getContents();
}
return stream;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.elf.parser.ElfBinaryObject#addSymbols(org.eclipse.cdt.utils.elf.Elf.Symbol[],
* 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) {
try {
name = cppfilt.getFunction(name);
} catch (IOException e1) {
cppfilt = null;
}
}
long addr = array[i].st_value;
long size = array[i].st_size;
if (addr2line != null) {
try {
String filename = addr2line.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 + size - 1);
list.add(new GNUSymbol(this, name, type, addr, size, file, startLine, endLine));
} catch (IOException e) {
}
} else {
list.add(new GNUSymbol(this, name, type, addr, size));
}
}
if (cppfilt != null) {
cppfilt.dispose();
}
if (addr2line != null) {
addr2line.dispose();
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
if (adapter == Addr2line.class) {
return getAddr2line(false);
} else if (adapter == CPPFilt.class) {
return getCPPFilt();
}
return super.getAdapter(adapter);
}
}

View file

@ -12,12 +12,18 @@ 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.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 {
public class GNUElfParser extends ElfParser implements IGnuToolFactory {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getFormat()
@ -81,4 +87,96 @@ public class GNUElfParser extends ElfParser {
}
};
}
/* (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 = 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);
}
}

View file

@ -0,0 +1,45 @@
/*******************************************************************************
* 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 org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.Symbol;
import org.eclipse.core.runtime.IPath;
public class GNUSymbol extends Symbol {
public GNUSymbol(GNUElfBinaryObject binary, String name, int type, long 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, long addr, long size) {
super(binary, name, type, addr, size);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.Symbol#getLineNumber(long)
*/
public int getLineNumber(long offset) {
int line = -1;
Addr2line addr2line = ((GNUElfBinaryObject)binary).getAddr2line(true);
if (addr2line != null) {
try {
return addr2line.getLineNumber(getAddress() + offset);
} catch (IOException e) {
// ignore
}
}
return line;
}
}

View file

@ -57,7 +57,7 @@ public class ERandomAccessFile extends RandomAccessFile {
public final long readLongE() throws IOException
{
return (long)readIntE();
return readIntE();
}
public void setFileOffset( long offset ) throws IOException {

View file

@ -8,8 +8,8 @@ package org.eclipse.cdt.utils.macho;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector;
import java.util.Comparator;
import java.util.Vector;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.utils.CPPFilt;
@ -200,7 +200,7 @@ public class MachO {
((val[offset + 1] & 0xff) << 8) |
(val[offset + 0] & 0xff));
} else {
return (int)(((val[offset + 0] & 0xff) << 24) |
return (((val[offset + 0] & 0xff) << 24) |
((val[offset + 1] & 0xff) << 16) |
((val[offset + 2] & 0xff) << 8) |
(val[offset + 3] & 0xff));
@ -685,7 +685,7 @@ public class MachO {
} else if ( obj instanceof Long ) {
Long val = (Long)obj;
anotherVal = val.longValue();
thisVal = (long)this.n_value;
thisVal = this.n_value;
}
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
@ -1540,7 +1540,7 @@ public class MachO {
tmp[1] = (short)((val >> 8) & 0x00ff);
tmp[2] = (short)((val >> 16) & 0x00ff);
tmp[3] = (short)((val >> 24) & 0x00ff);
return (long)((tmp[0] << 24) + (tmp[1] << 16) + (tmp[2] << 8) + tmp[3]);
return ((tmp[0] << 24) + (tmp[1] << 16) + (tmp[2] << 8) + tmp[3]);
}
return val;
}

View file

@ -72,11 +72,7 @@ public class ARMember extends MachOBinaryObject {
protected void addSymbols(MachO.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();
sym.addr = array[i].n_value;
list.add(sym);
list.add(new Symbol(this, array[i].toString(), type, array[i].n_value, 4));
}
}

View file

@ -18,9 +18,9 @@ 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.BinaryObjectAdapter;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.Symbol;
import org.eclipse.cdt.utils.macho.MachO;
import org.eclipse.cdt.utils.macho.MachOHelper;
import org.eclipse.core.runtime.IPath;
@ -120,6 +120,11 @@ public class MachOBinaryObject extends BinaryObjectAdapter {
info.cpu = attribute.getCPU();
}
protected CPPFilt getCPPFilt() {
MachOParser parser = (MachOParser) getBinaryParser();
return parser.getCPPFilt();
}
protected void loadSymbols(MachOHelper helper) throws IOException {
ArrayList list = new ArrayList();
// Hack should be remove when Elf is clean
@ -144,26 +149,19 @@ public class MachOBinaryObject extends BinaryObjectAdapter {
protected void addSymbols(MachO.Symbol[] array, int type, 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();
String name = array[i].toString();
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
name = cppfilt.getFunction(name);
} catch (IOException e1) {
cppfilt = null;
}
}
sym.addr = array[i].n_value;
sym.size = 0;
sym.filename = null;
sym.startLine = 0;
sym.endLine = sym.startLine;
long addr = array[i].n_value;
int size = 0;
String filename = array[i].getFilename();
sym.filename = (filename != null) ? new Path(filename) : null; //$NON-NLS-1$
sym.startLine = array[i].getLineNumber(sym.addr);
sym.endLine = array[i].getLineNumber(sym.addr + sym.size - 1);
list.add(sym);
IPath filePath = (filename != null) ? new Path(filename) : null; //$NON-NLS-1$
list.add(new Symbol(this, name, type, array[i].n_value, size, filePath, array[i].getLineNumber(addr), array[i].getLineNumber(addr + size - 1)));
}
}

View file

@ -13,17 +13,20 @@ package org.eclipse.cdt.utils.macho.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.core.ICExtensionReference;
import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.macho.AR;
import org.eclipse.cdt.utils.macho.MachO;
import org.eclipse.cdt.utils.macho.MachO.Attribute;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
*/
public class MachOParser extends ToolsProvider implements IBinaryParser {
public class MachOParser extends AbstractCExtension implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)
@ -100,6 +103,29 @@ public class MachOParser extends ToolsProvider implements IBinaryParser {
return 128;
}
/* (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;
}
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);
}
/**
* @param path
* @return

View file

@ -271,7 +271,7 @@ public class Spawner extends Process {
public void run() {
try {
pid = exec0(cmdarray, envp, dirpath, channels);
} catch (IOException e) {
} catch (Exception e) {
pid = -1;
errMesg = e.getMessage();
}

View file

@ -18,9 +18,7 @@ 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.Symbol;
import org.eclipse.cdt.utils.xcoff.AR;
import org.eclipse.cdt.utils.xcoff.XCoff32;
@ -73,7 +71,8 @@ public class ARMember extends XCOFFBinaryObject {
/* (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, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List 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);
@ -81,18 +80,14 @@ public class ARMember extends XCOFFBinaryObject {
!Character.isJavaIdentifierStart(name.charAt(0))*/) {
continue;
}
Symbol sym = new Symbol(this);
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
sym.addr = peSyms[i].n_value;
sym.name = name;
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
name = cppfilt.getFunction(name);
} catch (IOException e1) {
cppfilt = null;
}
}
Symbol sym = new Symbol(this, name, peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE, peSyms[i].n_value, 1);
list.add(sym);
}

View file

@ -71,5 +71,4 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
}
return (IBinaryObject[]) children.toArray(new IBinaryObject[0]);
}
}

View file

@ -13,19 +13,25 @@ package org.eclipse.cdt.utils.xcoff.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.core.ICExtensionReference;
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.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 ToolsProvider implements IBinaryParser {
public class XCOFF32Parser extends AbstractCExtension implements IBinaryParser, IGnuToolFactory {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], org.eclipse.core.runtime.IPath)
@ -168,4 +174,94 @@ public class XCOFF32Parser extends ToolsProvider implements IBinaryParser {
return new BinaryArchive(this, path);
}
/* (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 = 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);
}
}

View file

@ -1,16 +1,16 @@
/**********************************************************************
* 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
/*******************************************************************************
* 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
**********************************************************************/
* 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.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -21,9 +21,7 @@ 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.Objdump;
import org.eclipse.cdt.utils.Symbol;
import org.eclipse.cdt.utils.xcoff.XCoff32;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -34,6 +32,7 @@ import org.eclipse.core.runtime.Path;
* @author vhirsl
*/
public class XCOFFBinaryObject extends BinaryObjectAdapter {
Addr2line addr2line;
BinaryObjectInfo info;
ISymbol[] symbols;
@ -45,7 +44,9 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter {
super(parser, path);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbols()
*/
public ISymbol[] getSymbols() {
@ -59,7 +60,9 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter {
return symbols;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo()
*/
protected BinaryObjectInfo getBinaryObjectInfo() {
@ -73,12 +76,35 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter {
return info;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType()
*/
public int getType() {
return IBinaryFile.OBJECT;
}
/**
* @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;
}
protected XCoff32 getXCoff32() throws IOException {
return new XCoff32(getPath().toOSString());
@ -119,103 +145,127 @@ public class XCOFFBinaryObject extends BinaryObjectAdapter {
protected void loadSymbols(XCoff32 xcoff) throws IOException {
ArrayList list = new ArrayList();
Addr2line addr2line = getAddr2line();
CPPFilt cppfilt = getCPPFilt();
CygPath cygpath = getCygPath();
XCoff32.Symbol[] peSyms = xcoff.getSymbols();
byte[] table = xcoff.getStringTable();
addSymbols(peSyms, table, addr2line, cppfilt, cygpath, list);
addSymbols(peSyms, table, list);
if (addr2line != null) {
addr2line.dispose();
}
if (cppfilt != null) {
cppfilt.dispose();
}
if (cygpath != null) {
cygpath.dispose();
}
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
symbols = (ISymbol[]) list.toArray(NO_SYMBOLS);
Arrays.sort(symbols);
list.clear();
}
protected void addSymbols(XCoff32.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
protected void addSymbols(XCoff32.Symbol[] peSyms, byte[] table, List list) {
CPPFilt cppfilt = getCPPFilt();
Addr2line addr2line = getAddr2line(false);
for (int i = 0; i < peSyms.length; i++) {
if (peSyms[i].isFunction() || peSyms[i].isVariable()) {
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;
}
Symbol sym = new Symbol(this);
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
sym.addr = peSyms[i].n_value;
sym.name = name;
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
int addr = peSyms[i].n_value;
int size = 4;
if (cppfilt != null) {
try {
sym.name = cppfilt.getFunction(sym.name);
name = cppfilt.getFunction(name);
} catch (IOException e1) {
cppfilt = null;
}
}
sym.filename = null;
sym.startLine = 0;
sym.endLine = 0;
if (addr2line != null) {
try {
String filename = addr2line.getFileName(sym.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;
}
if (filename != null) {
if (cygpath != null) {
sym.filename = new Path(cygpath.getFileName(filename));
} else {
sym.filename = new Path(filename);
}
}
sym.startLine = addr2line.getLineNumber(sym.addr);
IPath file = filename != null ? new Path(filename) : Path.EMPTY;
int startLine = addr2line.getLineNumber(addr);
int endLine = addr2line.getLineNumber(addr + size - 1);
list.add(new XCoffSymbol(this, name, type, addr, size, file, startLine, endLine));
} catch (IOException e) {
addr2line = null;
}
} else {
list.add(new XCoffSymbol(this, name, type, addr, size));
}
list.add(sym);
}
}
if (cppfilt != null) {
cppfilt.dispose();
}
if (addr2line != null) {
addr2line.dispose();
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
*/
public Addr2line getAddr2line() {
XCOFF32Parser parser = (XCOFF32Parser)getBinaryParser();
return parser.getAddr2line(getPath());
public Addr2line getAddr2line(boolean autodisposing) {
if (!autodisposing) {
XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser();
return parser.getAddr2line(getPath());
}
if (addr2line == null) {
XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser();
addr2line = parser.getAddr2line(getPath());
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;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
*/
public CPPFilt getCPPFilt() {
XCOFF32Parser parser = (XCOFF32Parser)getBinaryParser();
synchronized void stopAddr2Line() {
if (addr2line != null) {
addr2line.dispose();
}
addr2line = null;
}
protected CPPFilt getCPPFilt() {
XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser();
return parser.getCPPFilt();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
*/
public Objdump getObjdump() {
XCOFF32Parser parser = (XCOFF32Parser)getBinaryParser();
protected Objdump getObjdump() {
XCOFF32Parser parser = (XCOFF32Parser) getBinaryParser();
return parser.getObjdump(getPath());
}
private CygPath getCygPath() {
return null;
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
if (adapter == Addr2line.class) {
return getAddr2line(false);
} else if (adapter == CPPFilt.class) {
return getCPPFilt();
}
return super.getAdapter(adapter);
}
}
}

View file

@ -0,0 +1,69 @@
/*
* Created on Jul 6, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.eclipse.cdt.utils.xcoff.parser;
import java.io.IOException;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.BinaryObjectAdapter;
import org.eclipse.cdt.utils.Symbol;
import org.eclipse.core.runtime.IPath;
/**
* @author DInglis
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class XCoffSymbol extends Symbol {
/**
* @param binary
* @param name
* @param type
* @param addr
* @param size
* @param sourceFile
* @param startLine
* @param endLine
*/
public XCoffSymbol(BinaryObjectAdapter binary, String name, int type, long addr, long size, IPath sourceFile, int startLine,
int endLine) {
super(binary, name, type, addr, size, sourceFile, startLine, endLine);
// TODO Auto-generated constructor stub
}
/**
* @param binary
* @param name
* @param type
* @param addr
* @param size
*/
public XCoffSymbol(BinaryObjectAdapter binary, String name, int type, long addr, long size) {
super(binary, name, type, addr, size);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.Symbol#getLineNumber(long)
*/
public int getLineNumber(long offset) {
int line = -1;
Addr2line addr2line = ((XCOFFBinaryObject)binary).getAddr2line(true);
if (addr2line != null) {
try {
return addr2line.getLineNumber(getAddress() + offset);
} catch (IOException e) {
// ignore
}
}
return line;
}
}