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.IOException;
|
||||||
import java.io.InputStream;
|
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.AR;
|
||||||
import org.eclipse.cdt.utils.elf.Elf;
|
import org.eclipse.cdt.utils.elf.Elf;
|
||||||
import org.eclipse.cdt.utils.elf.ElfHelper;
|
import org.eclipse.cdt.utils.elf.ElfHelper;
|
||||||
|
@ -63,15 +65,13 @@ public class ARMember extends BinaryObject {
|
||||||
throw new IOException("No file assiocated with Binary");
|
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++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
Symbol sym = new Symbol(this);
|
Symbol sym = new Symbol(this);
|
||||||
sym.type = type;
|
sym.type = type;
|
||||||
sym.name = array[i].toString();
|
sym.name = array[i].toString();
|
||||||
sym.addr = array[i].st_value;
|
sym.addr = array[i].st_value;
|
||||||
addSymbol(sym);
|
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;
|
package org.eclipse.cdt.utils.elf.parser;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||||
|
@ -42,7 +39,6 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
||||||
public IBinaryObject[] getObjects() {
|
public IBinaryObject[] getObjects() {
|
||||||
if (hasChanged()) {
|
if (hasChanged()) {
|
||||||
children.clear();
|
children.clear();
|
||||||
if (path != null) {
|
|
||||||
AR ar = null;
|
AR ar = null;
|
||||||
try {
|
try {
|
||||||
ar = new AR(getPath().toOSString());
|
ar = new AR(getPath().toOSString());
|
||||||
|
@ -57,7 +53,6 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
||||||
if (ar != null) {
|
if (ar != null) {
|
||||||
ar.dispose();
|
ar.dispose();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
children.trimToSize();
|
children.trimToSize();
|
||||||
}
|
}
|
||||||
return (IBinaryObject[]) children.toArray(new IBinaryObject[0]);
|
return (IBinaryObject[]) children.toArray(new IBinaryObject[0]);
|
||||||
|
@ -70,23 +65,6 @@ public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
||||||
return IBinaryFile.ARCHIVE;
|
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[])
|
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[])
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,23 +11,14 @@
|
||||||
package org.eclipse.cdt.utils.elf.parser;
|
package org.eclipse.cdt.utils.elf.parser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
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;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
|
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 {
|
public BinaryExecutable(IPath path) throws IOException {
|
||||||
super(path);
|
super(path);
|
||||||
|
|
|
@ -16,6 +16,9 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
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.cdt.utils.elf.Elf.Attribute;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
@ -27,6 +30,7 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
||||||
|
|
||||||
protected IPath path;
|
protected IPath path;
|
||||||
protected IToolsProvider toolsProvider;
|
protected IToolsProvider toolsProvider;
|
||||||
|
protected long timestamp;
|
||||||
|
|
||||||
public BinaryFile(IPath p) {
|
public BinaryFile(IPath p) {
|
||||||
path = p;
|
path = p;
|
||||||
|
@ -36,22 +40,18 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
||||||
toolsProvider = p;
|
toolsProvider = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPath getAddr2LinePath() {
|
public Addr2line getAddr2Line() {
|
||||||
if (toolsProvider != null)
|
if (toolsProvider != null)
|
||||||
return toolsProvider.getAddr2LinePath();
|
return toolsProvider.getAddr2Line(path);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPath getCPPFiltPath() {
|
public CPPFilt getCPPFilt() {
|
||||||
if (toolsProvider != null)
|
if (toolsProvider != null)
|
||||||
return toolsProvider.getCPPFiltPath();
|
return toolsProvider.getCPPFilt();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract Attribute getAttribute();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
|
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
|
||||||
|
@ -82,4 +82,16 @@ public abstract class BinaryFile extends PlatformObject implements IBinaryFile {
|
||||||
return stream;
|
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;
|
package org.eclipse.cdt.utils.elf.parser;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
|
@ -32,8 +30,6 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
protected String soname;
|
protected String soname;
|
||||||
protected String[] needed;
|
protected String[] needed;
|
||||||
protected int type = IBinaryFile.OBJECT;
|
protected int type = IBinaryFile.OBJECT;
|
||||||
|
|
||||||
private long timestamp;
|
|
||||||
private Sizes sizes;
|
private Sizes sizes;
|
||||||
private Attribute attribute;
|
private Attribute attribute;
|
||||||
private ArrayList symbols;
|
private ArrayList symbols;
|
||||||
|
@ -120,6 +116,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
public void setType(int t) {
|
public void setType(int t) {
|
||||||
type = t;
|
type = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getSymbols()
|
* @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]);
|
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()
|
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (path != null) {
|
return getPath().lastSegment().toString();
|
||||||
return path.lastSegment().toString();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -187,18 +164,8 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
return sizes;
|
return sizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasChanged() {
|
|
||||||
long modification = path.toFile().lastModified();
|
|
||||||
boolean changed = modification != timestamp;
|
|
||||||
timestamp = modification;
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ElfHelper getElfHelper() throws IOException {
|
protected ElfHelper getElfHelper() throws IOException {
|
||||||
if (path != null) {
|
return new ElfHelper(getPath().toOSString());
|
||||||
return new ElfHelper(path.toOSString());
|
|
||||||
}
|
|
||||||
throw new IOException("No file assiocated with Binary");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadInformation() throws IOException {
|
protected void loadInformation() throws IOException {
|
||||||
|
@ -275,7 +242,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
}
|
}
|
||||||
sym.addr = array[i].st_value;
|
sym.addr = array[i].st_value;
|
||||||
sym.filename = null;
|
sym.filename = null;
|
||||||
sym.startLine = -1;
|
sym.startLine = 0;
|
||||||
sym.endLine = sym.startLine;
|
sym.endLine = sym.startLine;
|
||||||
if (addr2line != null) {
|
if (addr2line != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -293,28 +260,4 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
symbols.add(sym);
|
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.IBinaryParser;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
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.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
@ -56,4 +59,29 @@ public class GNUElfParser extends ElfParser implements IBinaryParser, IToolsProv
|
||||||
}
|
}
|
||||||
return new Path(value);
|
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