mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Performance tuning for binary objects
This commit is contained in:
parent
b5afa53f38
commit
30536df362
2 changed files with 63 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
* Copyright (c) 2000, 2008 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -39,6 +39,7 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
private ISymbol[] symbols;
|
private ISymbol[] symbols;
|
||||||
private final AR.ARHeader header;
|
private final AR.ARHeader header;
|
||||||
private IAddressFactory addressFactory;
|
private IAddressFactory addressFactory;
|
||||||
|
private volatile Elf.Attribute fElfAttributes;
|
||||||
|
|
||||||
public ElfBinaryObject(IBinaryParser parser, IPath p, AR.ARHeader h){
|
public ElfBinaryObject(IBinaryParser parser, IPath p, AR.ARHeader h){
|
||||||
super(parser, p, IBinaryFile.OBJECT);
|
super(parser, p, IBinaryFile.OBJECT);
|
||||||
|
@ -50,6 +51,13 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
header = null;
|
header = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elfAttributes the elfAttributes to set
|
||||||
|
*/
|
||||||
|
void setElfAttributes(Elf.Attribute elfAttributes) {
|
||||||
|
fElfAttributes= elfAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName()
|
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName()
|
||||||
*/
|
*/
|
||||||
|
@ -155,10 +163,11 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
info.hasDebug = attribute.hasDebug();
|
info.hasDebug = attribute.hasDebug();
|
||||||
info.cpu = attribute.getCPU();
|
info.cpu = attribute.getCPU();
|
||||||
addressFactory = attribute.getAddressFactory();
|
addressFactory = attribute.getAddressFactory();
|
||||||
|
fElfAttributes= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadSymbols(ElfHelper helper) throws IOException {
|
protected void loadSymbols(ElfHelper helper) throws IOException {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<Symbol> list = new ArrayList<Symbol>();
|
||||||
|
|
||||||
// addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, list);
|
// addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, list);
|
||||||
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, list);
|
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, list);
|
||||||
|
@ -166,12 +175,12 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, list);
|
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, list);
|
||||||
list.trimToSize();
|
list.trimToSize();
|
||||||
|
|
||||||
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
|
symbols = list.toArray(NO_SYMBOLS);
|
||||||
Arrays.sort(symbols);
|
Arrays.sort(symbols);
|
||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addSymbols(Elf.Symbol[] array, int type, List list) {
|
protected void addSymbols(Elf.Symbol[] array, int type, List<Symbol> list) {
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
list.add(new Symbol(this, array[i].toString(), type, array[i].st_value, array[i].st_size));
|
list.add(new Symbol(this, array[i].toString(), type, array[i].st_value, array[i].st_size));
|
||||||
}
|
}
|
||||||
|
@ -181,6 +190,7 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Object getAdapter(Class adapter) {
|
public Object getAdapter(Class adapter) {
|
||||||
if (adapter.equals(Elf.class)) {
|
if (adapter.equals(Elf.class)) {
|
||||||
|
@ -205,12 +215,50 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
@Override
|
@Override
|
||||||
public IAddressFactory getAddressFactory() {
|
public IAddressFactory getAddressFactory() {
|
||||||
if (addressFactory == null) {
|
if (addressFactory == null) {
|
||||||
try {
|
if (fElfAttributes != null) {
|
||||||
loadInfo();
|
addressFactory= fElfAttributes.getAddressFactory();
|
||||||
} catch (IOException e) {
|
}
|
||||||
return new Addr32Factory();
|
if (addressFactory == null) {
|
||||||
|
try {
|
||||||
|
loadInfo();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return new Addr32Factory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addressFactory;
|
return addressFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#isLittleEndian()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isLittleEndian() {
|
||||||
|
if (fElfAttributes != null) {
|
||||||
|
return fElfAttributes.isLittleEndian();
|
||||||
|
}
|
||||||
|
return super.isLittleEndian();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#hasDebug()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean hasDebug() {
|
||||||
|
if (fElfAttributes != null) {
|
||||||
|
return fElfAttributes.hasDebug();
|
||||||
|
}
|
||||||
|
return super.hasDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getCPU()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getCPU() {
|
||||||
|
if (fElfAttributes != null) {
|
||||||
|
return fElfAttributes.getCPU();
|
||||||
|
}
|
||||||
|
return super.getCPU();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,9 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
|
||||||
binary = createBinaryCore(path);
|
binary = createBinaryCore(path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (binary instanceof ElfBinaryObject) {
|
||||||
|
((ElfBinaryObject)binary).setElfAttributes(attribute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (hints == null) {
|
if (hints == null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue