mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-18 22:45:23 +02:00
2004-07-19 Vladimir Hirsl
Support for SOM/XCoff * utils/org/eclipse/cdt/utils/som/* * utils/org/eclipse/cdt/utils/xcoff/*
This commit is contained in:
parent
3bc91cc510
commit
16fa4e7c7f
10 changed files with 87 additions and 206 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-07-19 Vladimir Hirsl
|
||||
|
||||
Support for SOM/XCoff
|
||||
* utils/org/eclipse/cdt/utils/som/*
|
||||
* utils/org/eclipse/cdt/utils/xcoff/*
|
||||
|
||||
2004-07-17 Brad Jarvinen.
|
||||
|
||||
Fix Pr 70252
|
||||
|
|
|
@ -30,6 +30,7 @@ GNUElfParser.name=GNU Elf Parser
|
|||
PEWindowsParser.name=PE Windows Parser
|
||||
CygwinPEParser.name=Cygwin PE Parser
|
||||
XCOFF32Parser.name=AIX XCOFF32 Parser
|
||||
SOMParser.name=HP-UX SOM Parser
|
||||
|
||||
CDTGNUCErrorParser.name=CDT GNU C/C++ Error Parser
|
||||
CDTGNUAssemblerErrorParser.name=CDT GNU Assembler Error Parser
|
||||
|
|
|
@ -107,6 +107,16 @@
|
|||
</run>
|
||||
</cextension>
|
||||
</extension>
|
||||
<extension
|
||||
id="SOM"
|
||||
name="%SOMParser.name"
|
||||
point="org.eclipse.cdt.core.BinaryParser">
|
||||
<cextension>
|
||||
<run
|
||||
class="org.eclipse.cdt.utils.som.parser.SOMParser">
|
||||
</run>
|
||||
</cextension>
|
||||
</extension>
|
||||
<!-- This is for backward compatibility: an Typo was introduce in on of the realease
|
||||
and "ELF" instead of "Elf" -->
|
||||
<extension
|
||||
|
|
|
@ -20,7 +20,9 @@ import org.eclipse.cdt.core.IBinaryParser;
|
|||
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
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.som.AR;
|
||||
import org.eclipse.cdt.utils.som.SOM;
|
||||
|
@ -45,8 +47,7 @@ public class ARMember extends SOMBinaryObject {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.som.parser.SOMBinaryObject#addSymbols(org.eclipse.cdt.utils.som.SOM.Symbol[], byte[], org.eclipse.cdt.utils.Addr2line, org.eclipse.cdt.utils.CPPFilt, org.eclipse.cdt.utils.CygPath, java.util.List)
|
||||
*/
|
||||
protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, List list) {
|
||||
CPPFilt cppfilt = getCPPFilt();
|
||||
protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
|
||||
for (int i = 0; i < peSyms.length; i++) {
|
||||
if (peSyms[i].isFunction() || peSyms[i].isVariable()) {
|
||||
String name = peSyms[i].getName(table);
|
||||
|
@ -54,14 +55,18 @@ public class ARMember extends SOMBinaryObject {
|
|||
!Character.isJavaIdentifierStart(name.charAt(0))) {
|
||||
continue;
|
||||
}
|
||||
Symbol sym = new Symbol(this);
|
||||
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
|
||||
sym.addr = peSyms[i].symbol_value;
|
||||
|
||||
sym.name = name;
|
||||
if (cppfilt != null) {
|
||||
try {
|
||||
name = cppfilt.getFunction(name);
|
||||
sym.name = cppfilt.getFunction(sym.name);
|
||||
} catch (IOException e1) {
|
||||
cppfilt = null;
|
||||
}
|
||||
}
|
||||
Symbol sym = new Symbol(this, name, peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE, peSyms[i].symbol_value, 1);
|
||||
|
||||
list.add(sym);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.utils.som.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;
|
||||
|
@ -23,9 +21,10 @@ 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.som.SOM;
|
||||
import org.eclipse.cdt.utils.som.parser.SOMParser;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -35,7 +34,6 @@ import org.eclipse.core.runtime.Path;
|
|||
* @author vhirsl
|
||||
*/
|
||||
public class SOMBinaryObject extends BinaryObjectAdapter {
|
||||
Addr2line addr2line;
|
||||
BinaryObjectInfo info;
|
||||
ISymbol[] symbols;
|
||||
|
||||
|
@ -82,26 +80,6 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
|
|||
return IBinaryFile.OBJECT;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.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 SOM getSOM() throws IOException {
|
||||
return new SOM(getPath().toOSString());
|
||||
}
|
||||
|
@ -141,19 +119,30 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
|
|||
|
||||
protected void loadSymbols(SOM som) throws IOException {
|
||||
ArrayList list = new ArrayList();
|
||||
Addr2line addr2line = getAddr2line();
|
||||
CPPFilt cppfilt = getCPPFilt();
|
||||
CygPath cygpath = getCygPath();
|
||||
|
||||
SOM.Symbol[] peSyms = som.getSymbols();
|
||||
byte[] table = som.getStringTable();
|
||||
addSymbols(peSyms, table, list);
|
||||
addSymbols(peSyms, table, addr2line, cppfilt, cygpath, list);
|
||||
|
||||
if (addr2line != null) {
|
||||
addr2line.dispose();
|
||||
}
|
||||
if (cppfilt != null) {
|
||||
cppfilt.dispose();
|
||||
}
|
||||
if (cygpath != null) {
|
||||
cygpath.dispose();
|
||||
}
|
||||
|
||||
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
|
||||
Arrays.sort(symbols);
|
||||
list.clear();
|
||||
}
|
||||
|
||||
protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, List list) {
|
||||
CPPFilt cppfilt = getCPPFilt();
|
||||
Addr2line addr2line = getAddr2line(false);
|
||||
protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
|
||||
for (int i = 0; i < peSyms.length; i++) {
|
||||
if (peSyms[i].isFunction() || peSyms[i].isVariable()) {
|
||||
String name = peSyms[i].getName(table);
|
||||
|
@ -161,105 +150,72 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
|
|||
!Character.isJavaIdentifierStart(name.charAt(0))) {
|
||||
continue;
|
||||
}
|
||||
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
|
||||
int addr = peSyms[i].symbol_value;
|
||||
int size = 4;
|
||||
Symbol sym = new Symbol(this);
|
||||
sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
|
||||
sym.addr = peSyms[i].symbol_value;
|
||||
|
||||
sym.name = name;
|
||||
if (cppfilt != null) {
|
||||
try {
|
||||
name = cppfilt.getFunction(name);
|
||||
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(addr);
|
||||
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;
|
||||
}
|
||||
|
||||
IPath file = filename != null ? new Path(filename) : Path.EMPTY;
|
||||
int startLine = addr2line.getLineNumber(addr);
|
||||
int endLine = addr2line.getLineNumber(addr + size - 1);
|
||||
list.add(new SomSymbol(this, name, type, addr, size, file, startLine, endLine));
|
||||
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;
|
||||
// the symbol still needs to be added
|
||||
list.add(new SomSymbol(this, name, type, addr, size));
|
||||
}
|
||||
} else {
|
||||
list.add(new SomSymbol(this, name, type, addr, size));
|
||||
}
|
||||
list.add(sym);
|
||||
}
|
||||
}
|
||||
if (cppfilt != null) {
|
||||
cppfilt.dispose();
|
||||
}
|
||||
if (addr2line != null) {
|
||||
addr2line.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public Addr2line getAddr2line(boolean autodisposing) {
|
||||
if (!autodisposing) {
|
||||
SOMParser parser = (SOMParser) getBinaryParser();
|
||||
return parser.getAddr2line(getPath());
|
||||
}
|
||||
if (addr2line == null) {
|
||||
SOMParser parser = (SOMParser) 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#getAddr2line()
|
||||
*/
|
||||
public Addr2line getAddr2line() {
|
||||
SOMParser parser = (SOMParser)getBinaryParser();
|
||||
return parser.getAddr2line(getPath());
|
||||
}
|
||||
|
||||
synchronized void stopAddr2Line() {
|
||||
if (addr2line != null) {
|
||||
addr2line.dispose();
|
||||
}
|
||||
addr2line = null;
|
||||
}
|
||||
|
||||
protected CPPFilt getCPPFilt() {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
|
||||
*/
|
||||
public CPPFilt getCPPFilt() {
|
||||
SOMParser parser = (SOMParser)getBinaryParser();
|
||||
return parser.getCPPFilt();
|
||||
}
|
||||
|
||||
protected Objdump getObjdump() {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
|
||||
*/
|
||||
public Objdump getObjdump() {
|
||||
SOMParser parser = (SOMParser)getBinaryParser();
|
||||
return parser.getObjdump(getPath());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.IAdaptable#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);
|
||||
private CygPath getCygPath() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,25 +13,19 @@ package org.eclipse.cdt.utils.som.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.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.ToolsProvider;
|
||||
import org.eclipse.cdt.utils.som.AR;
|
||||
import org.eclipse.cdt.utils.som.SOM;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* HP-UX SOM binary parser
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnuToolFactory {
|
||||
public class SOMParser extends ToolsProvider implements IBinaryParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], org.eclipse.core.runtime.IPath)
|
||||
|
@ -173,95 +167,4 @@ public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnu
|
|||
private IBinaryFile createBinaryArchive(IPath path) throws IOException {
|
||||
return new BinaryArchive(this, path);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.IGnuToolFactory#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.IGnuToolFactory#getCPPFilt()
|
||||
*/
|
||||
public CPPFilt getCPPFilt() {
|
||||
IPath cppFiltPath = getCPPFiltPath();
|
||||
CPPFilt cppfilt = null;
|
||||
if (cppFiltPath != null && ! cppFiltPath.isEmpty()) {
|
||||
try {
|
||||
cppfilt = new CPPFilt(cppFiltPath.toOSString());
|
||||
} catch (IOException e2) {
|
||||
}
|
||||
}
|
||||
return cppfilt;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.IGnuToolFactory#getObjdump(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public Objdump getObjdump(IPath path) {
|
||||
IPath objdumpPath = getObjdumpPath();
|
||||
String objdumpArgs = getObjdumpArgs();
|
||||
Objdump objdump = null;
|
||||
if (objdumpPath != null && !objdumpPath.isEmpty()) {
|
||||
try {
|
||||
objdump = new Objdump(objdumpPath.toOSString(), objdumpArgs, path.toOSString());
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
return objdump;
|
||||
}
|
||||
|
||||
protected IPath getAddr2linePath() {
|
||||
ICExtensionReference ref = getExtensionReference();
|
||||
String value = ref.getExtensionData("addr2line"); //$NON-NLS-1$
|
||||
if (value == null || value.length() == 0) {
|
||||
value = "addr2line"; //$NON-NLS-1$
|
||||
}
|
||||
return new Path(value);
|
||||
}
|
||||
|
||||
protected IPath getObjdumpPath() {
|
||||
ICExtensionReference ref = getExtensionReference();
|
||||
String value = ref.getExtensionData("objdump"); //$NON-NLS-1$
|
||||
if (value == null || value.length() == 0) {
|
||||
value = "objdump"; //$NON-NLS-1$
|
||||
}
|
||||
return new Path(value);
|
||||
}
|
||||
|
||||
protected 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class AR {
|
|||
private MemberHeader[] memberHeaders;
|
||||
|
||||
/**
|
||||
* TODO Provide description
|
||||
* Content of an archive in AIX XCOFF32 format
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
|
@ -252,7 +252,7 @@ public class AR {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create an new XCOFF32 object for the object file.
|
||||
* Create a new XCOFF32 object for the object file.
|
||||
*
|
||||
* @throws IOException
|
||||
* Not a valid XCOFF32 object file.
|
||||
|
@ -370,7 +370,7 @@ public class AR {
|
|||
try {
|
||||
AR ar = new AR(args[0]);
|
||||
ar.getHeaders();
|
||||
ar.extractFiles(args[0]);
|
||||
ar.extractFiles(args[1]);
|
||||
System.out.println(ar);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.utils.coff.ReadMemoryAccess;
|
||||
|
||||
/**
|
||||
* TODO Provide description
|
||||
* Representation of AIX XCOFF32 binary format
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
* @author vhirsl
|
||||
*/
|
||||
public class ARMember extends XCOFFBinaryObject {
|
||||
AR.MemberHeader header;
|
||||
private AR.MemberHeader header;
|
||||
|
||||
/**
|
||||
* @param parser
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* TODO Provide description
|
||||
* Binary file in AIX XCOFF32 format
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue