1
0
Fork 0
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:
Anton Leherbauer 2008-05-23 13:09:37 +00:00
parent b5afa53f38
commit 30536df362
2 changed files with 63 additions and 12 deletions

View file

@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -39,6 +39,7 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
private ISymbol[] symbols;
private final AR.ARHeader header;
private IAddressFactory addressFactory;
private volatile Elf.Attribute fElfAttributes;
public ElfBinaryObject(IBinaryParser parser, IPath p, AR.ARHeader h){
super(parser, p, IBinaryFile.OBJECT);
@ -50,6 +51,13 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
header = null;
}
/**
* @param elfAttributes the elfAttributes to set
*/
void setElfAttributes(Elf.Attribute elfAttributes) {
fElfAttributes= elfAttributes;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getName()
*/
@ -155,10 +163,11 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
info.hasDebug = attribute.hasDebug();
info.cpu = attribute.getCPU();
addressFactory = attribute.getAddressFactory();
fElfAttributes= null;
}
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.getLocalFunctions(), ISymbol.FUNCTION, list);
@ -166,12 +175,12 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, list);
list.trimToSize();
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
symbols = list.toArray(NO_SYMBOLS);
Arrays.sort(symbols);
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++) {
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)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class adapter) {
if (adapter.equals(Elf.class)) {
@ -205,12 +215,50 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
@Override
public IAddressFactory getAddressFactory() {
if (addressFactory == null) {
try {
loadInfo();
} catch (IOException e) {
return new Addr32Factory();
if (fElfAttributes != null) {
addressFactory= fElfAttributes.getAddressFactory();
}
if (addressFactory == null) {
try {
loadInfo();
} catch (IOException e) {
return new Addr32Factory();
}
}
}
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();
}
}

View file

@ -76,6 +76,9 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
binary = createBinaryCore(path);
break;
}
if (binary instanceof ElfBinaryObject) {
((ElfBinaryObject)binary).setElfAttributes(attribute);
}
}
} catch (IOException e) {
if (hints == null) {