mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
cleanup and remove duplicate methods.
This commit is contained in:
parent
347db0a84e
commit
8c64ff43dd
7 changed files with 67 additions and 137 deletions
|
@ -14,6 +14,8 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.cdt.utils.Addr2line;
|
||||
import org.eclipse.cdt.utils.CPPFilt;
|
||||
import org.eclipse.cdt.utils.elf.AR;
|
||||
import org.eclipse.cdt.utils.elf.Elf;
|
||||
import org.eclipse.cdt.utils.elf.ElfHelper;
|
||||
|
@ -63,15 +65,13 @@ public class ARMember extends BinaryObject {
|
|||
throw new IOException("No file assiocated with Binary");
|
||||
}
|
||||
|
||||
protected void addSymbols(Elf.Symbol[] array, int type) {
|
||||
protected void addSymbols(Elf.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Symbol sym = new Symbol(this);
|
||||
sym.type = type;
|
||||
sym.name = array[i].toString();
|
||||
sym.addr = array[i].st_value;
|
||||
addSymbol(sym);
|
||||
// This can fail if we use addr2line
|
||||
// but we can safely ignore the error.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.elf.parser;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||
|
@ -42,21 +39,19 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
|||
public IBinaryObject[] getObjects() {
|
||||
if (hasChanged()) {
|
||||
children.clear();
|
||||
if (path != null) {
|
||||
AR ar = null;
|
||||
try {
|
||||
ar = new AR(getPath().toOSString());
|
||||
AR.ARHeader[] headers = ar.getHeaders();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
IBinaryObject bin = new ARMember(getPath(), headers[i]);
|
||||
children.add(bin);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
if (ar != null) {
|
||||
ar.dispose();
|
||||
AR ar = null;
|
||||
try {
|
||||
ar = new AR(getPath().toOSString());
|
||||
AR.ARHeader[] headers = ar.getHeaders();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
IBinaryObject bin = new ARMember(getPath(), headers[i]);
|
||||
children.add(bin);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
if (ar != null) {
|
||||
ar.dispose();
|
||||
}
|
||||
children.trimToSize();
|
||||
}
|
||||
|
@ -70,23 +65,6 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
|||
return IBinaryFile.ARCHIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents()
|
||||
*/
|
||||
public InputStream getContents() {
|
||||
try {
|
||||
return new FileInputStream(getPath().toFile());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
|
||||
boolean hasChanged() {
|
||||
long modif = getPath().toFile().lastModified();
|
||||
boolean changed = modif != timestamp;
|
||||
timestamp = modif;
|
||||
return changed;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[])
|
||||
*/
|
||||
|
|
|
@ -11,23 +11,14 @@
|
|||
package org.eclipse.cdt.utils.elf.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.utils.elf.Elf.Attribute;
|
||||
import org.eclipse.cdt.utils.elf.ElfHelper.Sizes;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
|
||||
long timestamp;
|
||||
String soname;
|
||||
String[] needed;
|
||||
Sizes sizes;
|
||||
Attribute attribute;
|
||||
ArrayList symbols;
|
||||
|
||||
public BinaryExecutable(IPath path) throws IOException {
|
||||
super(path);
|
||||
|
|
|
@ -16,6 +16,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.utils.*;
|
||||
import org.eclipse.cdt.utils.Addr2line;
|
||||
import org.eclipse.cdt.utils.CPPFilt;
|
||||
import org.eclipse.cdt.utils.elf.Elf.Attribute;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
@ -27,6 +30,7 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
|||
|
||||
protected IPath path;
|
||||
protected IToolsProvider toolsProvider;
|
||||
protected long timestamp;
|
||||
|
||||
public BinaryFile(IPath p) {
|
||||
path = p;
|
||||
|
@ -36,22 +40,18 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
|||
toolsProvider = p;
|
||||
}
|
||||
|
||||
public IPath getAddr2LinePath() {
|
||||
public Addr2line getAddr2Line() {
|
||||
if (toolsProvider != null)
|
||||
return toolsProvider.getAddr2LinePath();
|
||||
return toolsProvider.getAddr2Line(path);
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPath getCPPFiltPath() {
|
||||
public CPPFilt getCPPFilt() {
|
||||
if (toolsProvider != null)
|
||||
return toolsProvider.getCPPFiltPath();
|
||||
return toolsProvider.getCPPFilt();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected abstract Attribute getAttribute();
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
|
||||
|
@ -82,4 +82,16 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
|||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected abstract Attribute getAttribute();
|
||||
|
||||
protected boolean hasChanged() {
|
||||
long modification = getPath().toFile().lastModified();
|
||||
boolean changed = modification != timestamp;
|
||||
timestamp = modification;
|
||||
return changed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.elf.parser;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
|
@ -32,8 +30,6 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
protected String soname;
|
||||
protected String[] needed;
|
||||
protected int type = IBinaryFile.OBJECT;
|
||||
|
||||
private long timestamp;
|
||||
private Sizes sizes;
|
||||
private Attribute attribute;
|
||||
private ArrayList symbols;
|
||||
|
@ -120,6 +116,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
public void setType(int t) {
|
||||
type = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols()
|
||||
*/
|
||||
|
@ -136,31 +133,11 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
return (ISymbol[]) symbols.toArray(new ISymbol[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents()
|
||||
*/
|
||||
public InputStream getContents() {
|
||||
InputStream stream = null;
|
||||
if (path != null) {
|
||||
try {
|
||||
stream = new FileInputStream(path.toFile());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = super.getContents();
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
if (path != null) {
|
||||
return path.lastSegment().toString();
|
||||
}
|
||||
return "";
|
||||
return getPath().lastSegment().toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -187,18 +164,8 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
return sizes;
|
||||
}
|
||||
|
||||
boolean hasChanged() {
|
||||
long modification = path.toFile().lastModified();
|
||||
boolean changed = modification != timestamp;
|
||||
timestamp = modification;
|
||||
return changed;
|
||||
}
|
||||
|
||||
protected ElfHelper getElfHelper() throws IOException {
|
||||
if (path != null) {
|
||||
return new ElfHelper(path.toOSString());
|
||||
}
|
||||
throw new IOException("No file assiocated with Binary");
|
||||
return new ElfHelper(getPath().toOSString());
|
||||
}
|
||||
|
||||
protected void loadInformation() throws IOException {
|
||||
|
@ -275,7 +242,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
}
|
||||
sym.addr = array[i].st_value;
|
||||
sym.filename = null;
|
||||
sym.startLine = -1;
|
||||
sym.startLine = 0;
|
||||
sym.endLine = sym.startLine;
|
||||
if (addr2line != null) {
|
||||
try {
|
||||
|
@ -293,28 +260,4 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
|||
symbols.add(sym);
|
||||
}
|
||||
|
||||
protected Addr2line getAddr2Line() {
|
||||
IPath addr2LinePath = getAddr2LinePath();
|
||||
Addr2line addr2line = null;
|
||||
if (addr2LinePath != null && !addr2LinePath.isEmpty()) {
|
||||
try {
|
||||
addr2line = new Addr2line(addr2LinePath.toOSString(), getPath().toOSString());
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
return addr2line;
|
||||
}
|
||||
|
||||
protected CPPFilt getCPPFilt() {
|
||||
IPath cppFiltPath = getCPPFiltPath();
|
||||
CPPFilt cppfilt = null;
|
||||
if (cppFiltPath != null && ! cppFiltPath.isEmpty()) {
|
||||
try {
|
||||
cppfilt = new CPPFilt(cppFiltPath.toOSString());
|
||||
} catch (IOException e2) {
|
||||
}
|
||||
}
|
||||
return cppfilt;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ import java.io.IOException;
|
|||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.ICExtensionReference;
|
||||
import org.eclipse.cdt.utils.*;
|
||||
import org.eclipse.cdt.utils.Addr2line;
|
||||
import org.eclipse.cdt.utils.CPPFilt;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -56,4 +59,29 @@ public class GNUElfParser extends ElfParser implements IBinaryParser, IToolsProv
|
|||
}
|
||||
return new Path(value);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.elf.parser;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface IToolsProvider {
|
||||
|
||||
IPath getAddr2LinePath();
|
||||
|
||||
IPath getCPPFiltPath();
|
||||
}
|
Loading…
Add table
Reference in a new issue