mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 16:26:11 +02:00
Move Symbol class outside.
This commit is contained in:
parent
3f774dc60b
commit
47c90fdd03
2 changed files with 58 additions and 87 deletions
|
@ -91,4 +91,16 @@ public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
|
||||||
timestamp = modif;
|
timestamp = modif;
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @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 {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,66 +40,15 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
Attribute attribute;
|
Attribute attribute;
|
||||||
ArrayList symbols;
|
ArrayList symbols;
|
||||||
|
|
||||||
public class ElfSymbol implements ISymbol {
|
|
||||||
|
|
||||||
String filename;
|
|
||||||
int lineno;
|
|
||||||
String name;
|
|
||||||
int type;
|
|
||||||
|
|
||||||
public ElfSymbol (Elf.Symbol symbol, int t) throws IOException {
|
|
||||||
filename = symbol.getFilename();
|
|
||||||
name = symbol.toString();
|
|
||||||
lineno = symbol.getFuncLineNumber();
|
|
||||||
type = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getFilename()
|
|
||||||
*/
|
|
||||||
public String getFilename() {
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getLineNumber()
|
|
||||||
*/
|
|
||||||
public int getLineNumber() {
|
|
||||||
return lineno;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getName()
|
|
||||||
*/
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getType()
|
|
||||||
*/
|
|
||||||
public int getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElfBinaryFile(IFile f) throws IOException {
|
public ElfBinaryFile(IFile f) throws IOException {
|
||||||
this(f, null, null);
|
this(f, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElfBinaryFile(IFile f, String n) throws IOException {
|
public ElfBinaryFile(IFile f, String n) throws IOException {
|
||||||
this(f, n, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElfBinaryFile(IFile f, String n, Elf elf) throws IOException {
|
|
||||||
file = f;
|
file = f;
|
||||||
objectName = n;
|
objectName = n;
|
||||||
if (elf != null) {
|
loadInformation();
|
||||||
loadAttributes(new ElfHelper(elf));
|
hasChanged();
|
||||||
} else {
|
|
||||||
loadAttributes();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,8 +241,14 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
|
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
if (objectName != null) {
|
||||||
return objectName;
|
return objectName;
|
||||||
}
|
}
|
||||||
|
if (file != null) {
|
||||||
|
return file.getName();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName();
|
return getName();
|
||||||
|
@ -328,15 +283,18 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
|
|
||||||
protected ElfHelper getElfHelper() throws IOException {
|
protected ElfHelper getElfHelper() throws IOException {
|
||||||
// Archive ?
|
// Archive ?
|
||||||
if (file != null && file.exists() && objectName != null) {
|
if (file != null && objectName != null) {
|
||||||
|
IPath location = file.getLocation();
|
||||||
|
if (location != null) {
|
||||||
ElfHelper helper = null;
|
ElfHelper helper = null;
|
||||||
AR ar = null;
|
AR ar = null;
|
||||||
try {
|
try {
|
||||||
ar = new AR(file.getLocation().toOSString());
|
ar = new AR(file.getLocation().toOSString());
|
||||||
AR.ARHeader[] headers = ar.getHeaders();
|
AR.ARHeader[] headers = ar.getHeaders();
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
if (objectName.equals(headers[i].getObjectName())) {
|
AR.ARHeader hdr = headers[i];
|
||||||
helper = new ElfHelper(headers[i].getElf());
|
if (objectName.equals(hdr.getObjectName())) {
|
||||||
|
helper = new ElfHelper(hdr.getElf());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +303,10 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
ar.dispose();
|
ar.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (helper != null) {
|
||||||
return helper;
|
return helper;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (file != null && file.exists()) {
|
} else if (file != null && file.exists()) {
|
||||||
IPath path = file.getLocation();
|
IPath path = file.getLocation();
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
@ -357,21 +318,21 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadInformation() throws IOException {
|
protected void loadInformation() throws IOException {
|
||||||
loadAttributes();
|
ElfHelper helper = getElfHelper();
|
||||||
|
loadInformation(helper);
|
||||||
|
helper.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadInformation(ElfHelper helper) throws IOException {
|
||||||
|
loadAttributes(helper);
|
||||||
if (symbols != null) {
|
if (symbols != null) {
|
||||||
symbols.clear();
|
symbols.clear();
|
||||||
loadSymbols();
|
loadSymbols(helper);
|
||||||
symbols.trimToSize();
|
symbols.trimToSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadAttributes() throws IOException {
|
private void loadAttributes(ElfHelper helper) throws IOException {
|
||||||
ElfHelper helper = getElfHelper();
|
|
||||||
loadAttributes(helper);
|
|
||||||
helper.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadAttributes(ElfHelper helper) throws IOException {
|
|
||||||
Elf.Dynamic[] sharedlibs = helper.getNeeded();
|
Elf.Dynamic[] sharedlibs = helper.getNeeded();
|
||||||
needed = new String[sharedlibs.length];
|
needed = new String[sharedlibs.length];
|
||||||
for (int i = 0; i < sharedlibs.length; i++) {
|
for (int i = 0; i < sharedlibs.length; i++) {
|
||||||
|
@ -382,13 +343,7 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
attribute = helper.getElf().getAttributes();
|
attribute = helper.getElf().getAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadSymbols() throws IOException {
|
private void loadSymbols(ElfHelper helper) throws IOException {
|
||||||
ElfHelper helper = getElfHelper();
|
|
||||||
loadSymbols(helper);
|
|
||||||
helper.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadSymbols(ElfHelper helper) throws IOException {
|
|
||||||
Elf.Dynamic[] sharedlibs = helper.getNeeded();
|
Elf.Dynamic[] sharedlibs = helper.getNeeded();
|
||||||
needed = new String[sharedlibs.length];
|
needed = new String[sharedlibs.length];
|
||||||
for (int i = 0; i < sharedlibs.length; i++) {
|
for (int i = 0; i < sharedlibs.length; i++) {
|
||||||
|
@ -405,10 +360,14 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
|
||||||
symbols.trimToSize();
|
symbols.trimToSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addSymbols(Elf.Symbol[] array, int type) {
|
private void addSymbols(Elf.Symbol[] array, int type) {
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
try {
|
try {
|
||||||
ISymbol sym = new ElfSymbol(array[i], type);
|
Symbol sym = new Symbol();
|
||||||
|
sym.filename = array[i].getFilename();
|
||||||
|
sym.name = array[i].toString();
|
||||||
|
sym.lineno = array[i].getFuncLineNumber();
|
||||||
|
sym.type = type;
|
||||||
symbols.add(sym);
|
symbols.add(sym);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue