1
0
Fork 0
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:
Alain Magloire 2004-07-19 17:27:22 +00:00
parent 3bc91cc510
commit 16fa4e7c7f
10 changed files with 87 additions and 206 deletions

View file

@ -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. 2004-07-17 Brad Jarvinen.
Fix Pr 70252 Fix Pr 70252

View file

@ -30,6 +30,7 @@ GNUElfParser.name=GNU Elf Parser
PEWindowsParser.name=PE Windows Parser PEWindowsParser.name=PE Windows Parser
CygwinPEParser.name=Cygwin PE Parser CygwinPEParser.name=Cygwin PE Parser
XCOFF32Parser.name=AIX XCOFF32 Parser XCOFF32Parser.name=AIX XCOFF32 Parser
SOMParser.name=HP-UX SOM Parser
CDTGNUCErrorParser.name=CDT GNU C/C++ Error Parser CDTGNUCErrorParser.name=CDT GNU C/C++ Error Parser
CDTGNUAssemblerErrorParser.name=CDT GNU Assembler Error Parser CDTGNUAssemblerErrorParser.name=CDT GNU Assembler Error Parser

View file

@ -107,6 +107,16 @@
</run> </run>
</cextension> </cextension>
</extension> </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 <!-- This is for backward compatibility: an Typo was introduce in on of the realease
and "ELF" instead of "Elf" --> and "ELF" instead of "Elf" -->
<extension <extension

View file

@ -20,7 +20,9 @@ import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.ISymbol; import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.utils.Addr2line;
import org.eclipse.cdt.utils.CPPFilt; import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.Symbol; import org.eclipse.cdt.utils.Symbol;
import org.eclipse.cdt.utils.som.AR; import org.eclipse.cdt.utils.som.AR;
import org.eclipse.cdt.utils.som.SOM; import org.eclipse.cdt.utils.som.SOM;
@ -45,8 +47,7 @@ public class ARMember extends SOMBinaryObject {
/* (non-Javadoc) /* (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) * @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) { protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
CPPFilt cppfilt = getCPPFilt();
for (int i = 0; i < peSyms.length; i++) { 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); String name = peSyms[i].getName(table);
@ -54,14 +55,18 @@ public class ARMember extends SOMBinaryObject {
!Character.isJavaIdentifierStart(name.charAt(0))) { !Character.isJavaIdentifierStart(name.charAt(0))) {
continue; 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) { if (cppfilt != null) {
try { try {
name = cppfilt.getFunction(name); sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) { } catch (IOException e1) {
cppfilt = null; cppfilt = null;
} }
} }
Symbol sym = new Symbol(this, name, peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE, peSyms[i].symbol_value, 1);
list.add(sym); list.add(sym);
} }

View file

@ -10,9 +10,7 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.utils.som.parser; package org.eclipse.cdt.utils.som.parser;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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.Addr2line;
import org.eclipse.cdt.utils.BinaryObjectAdapter; import org.eclipse.cdt.utils.BinaryObjectAdapter;
import org.eclipse.cdt.utils.CPPFilt; import org.eclipse.cdt.utils.CPPFilt;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.Objdump; 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.SOM;
import org.eclipse.cdt.utils.som.parser.SOMParser;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -35,7 +34,6 @@ import org.eclipse.core.runtime.Path;
* @author vhirsl * @author vhirsl
*/ */
public class SOMBinaryObject extends BinaryObjectAdapter { public class SOMBinaryObject extends BinaryObjectAdapter {
Addr2line addr2line;
BinaryObjectInfo info; BinaryObjectInfo info;
ISymbol[] symbols; ISymbol[] symbols;
@ -82,26 +80,6 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
return IBinaryFile.OBJECT; 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 { protected SOM getSOM() throws IOException {
return new SOM(getPath().toOSString()); return new SOM(getPath().toOSString());
} }
@ -141,19 +119,30 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
protected void loadSymbols(SOM som) throws IOException { protected void loadSymbols(SOM som) throws IOException {
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
Addr2line addr2line = getAddr2line();
CPPFilt cppfilt = getCPPFilt();
CygPath cygpath = getCygPath();
SOM.Symbol[] peSyms = som.getSymbols(); SOM.Symbol[] peSyms = som.getSymbols();
byte[] table = som.getStringTable(); 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); symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
Arrays.sort(symbols); Arrays.sort(symbols);
list.clear(); list.clear();
} }
protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, List list) { protected void addSymbols(SOM.Symbol[] peSyms, byte[] table, Addr2line addr2line, CPPFilt cppfilt, CygPath cygpath, List list) {
CPPFilt cppfilt = getCPPFilt();
Addr2line addr2line = getAddr2line(false);
for (int i = 0; i < peSyms.length; i++) { 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); String name = peSyms[i].getName(table);
@ -161,105 +150,72 @@ public class SOMBinaryObject extends BinaryObjectAdapter {
!Character.isJavaIdentifierStart(name.charAt(0))) { !Character.isJavaIdentifierStart(name.charAt(0))) {
continue; continue;
} }
int type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE; Symbol sym = new Symbol(this);
int addr = peSyms[i].symbol_value; sym.type = peSyms[i].isFunction() ? ISymbol.FUNCTION : ISymbol.VARIABLE;
int size = 4; sym.addr = peSyms[i].symbol_value;
sym.name = name;
if (cppfilt != null) { if (cppfilt != null) {
try { try {
name = cppfilt.getFunction(name); sym.name = cppfilt.getFunction(sym.name);
} catch (IOException e1) { } catch (IOException e1) {
cppfilt = null; cppfilt = null;
} }
} }
sym.filename = null;
sym.startLine = 0;
sym.endLine = 0;
if (addr2line != null) { if (addr2line != null) {
try { try {
String filename = addr2line.getFileName(addr); String filename = addr2line.getFileName(sym.addr);
// Addr2line returns the funny "??" when it can not find the file. // Addr2line returns the funny "??" when it can not find the file.
if (filename != null && filename.equals("??")) { //$NON-NLS-1$ if (filename != null && filename.equals("??")) { //$NON-NLS-1$
filename = null; filename = null;
} }
IPath file = filename != null ? new Path(filename) : Path.EMPTY; if (filename != null) {
int startLine = addr2line.getLineNumber(addr); if (cygpath != null) {
int endLine = addr2line.getLineNumber(addr + size - 1); sym.filename = new Path(cygpath.getFileName(filename));
list.add(new SomSymbol(this, name, type, addr, size, file, startLine, endLine)); } else {
sym.filename = new Path(filename);
}
}
sym.startLine = addr2line.getLineNumber(sym.addr);
} catch (IOException e) { } catch (IOException e) {
addr2line = null; 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) { /* (non-Javadoc)
if (!autodisposing) { * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getAddr2line()
SOMParser parser = (SOMParser) getBinaryParser(); */
public Addr2line getAddr2line() {
SOMParser parser = (SOMParser)getBinaryParser();
return parser.getAddr2line(getPath()); 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() { /* (non-Javadoc)
long diff = System.currentTimeMillis() - timestamp; * @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPPFilt()
while (diff < 10000) { */
try { public CPPFilt getCPPFilt() {
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;
}
protected CPPFilt getCPPFilt() {
SOMParser parser = (SOMParser)getBinaryParser(); SOMParser parser = (SOMParser)getBinaryParser();
return parser.getCPPFilt(); return parser.getCPPFilt();
} }
protected Objdump getObjdump() { /* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getObjdump()
*/
public Objdump getObjdump() {
SOMParser parser = (SOMParser)getBinaryParser(); SOMParser parser = (SOMParser)getBinaryParser();
return parser.getObjdump(getPath()); return parser.getObjdump(getPath());
} }
/* (non-Javadoc) private CygPath getCygPath() {
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) return null;
*/
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

@ -13,25 +13,19 @@ package org.eclipse.cdt.utils.som.parser;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.utils.ToolsProvider;
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.som.AR; import org.eclipse.cdt.utils.som.AR;
import org.eclipse.cdt.utils.som.SOM; import org.eclipse.cdt.utils.som.SOM;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/** /**
* HP-UX SOM binary parser * HP-UX SOM binary parser
* *
* @author vhirsl * @author vhirsl
*/ */
public class SOMParser extends AbstractCExtension implements IBinaryParser, IGnuToolFactory { public class SOMParser extends ToolsProvider implements IBinaryParser {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(byte[], org.eclipse.core.runtime.IPath) * @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 { private IBinaryFile createBinaryArchive(IPath path) throws IOException {
return new BinaryArchive(this, path); 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);
}
} }

View file

@ -34,7 +34,7 @@ public class AR {
private MemberHeader[] memberHeaders; private MemberHeader[] memberHeaders;
/** /**
* TODO Provide description * Content of an archive in AIX XCOFF32 format
* *
* @author vhirsl * @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 * @throws IOException
* Not a valid XCOFF32 object file. * Not a valid XCOFF32 object file.
@ -370,7 +370,7 @@ public class AR {
try { try {
AR ar = new AR(args[0]); AR ar = new AR(args[0]);
ar.getHeaders(); ar.getHeaders();
ar.extractFiles(args[0]); ar.extractFiles(args[1]);
System.out.println(ar); System.out.println(ar);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -21,7 +21,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.utils.coff.ReadMemoryAccess; import org.eclipse.cdt.utils.coff.ReadMemoryAccess;
/** /**
* TODO Provide description * Representation of AIX XCOFF32 binary format
* *
* @author vhirsl * @author vhirsl
*/ */

View file

@ -32,7 +32,7 @@ import org.eclipse.core.runtime.IPath;
* @author vhirsl * @author vhirsl
*/ */
public class ARMember extends XCOFFBinaryObject { public class ARMember extends XCOFFBinaryObject {
AR.MemberHeader header; private AR.MemberHeader header;
/** /**
* @param parser * @param parser

View file

@ -29,7 +29,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
/** /**
* TODO Provide description * Binary file in AIX XCOFF32 format
* *
* @author vhirsl * @author vhirsl
*/ */