From 8c64ff43ddabafc54665ce0c4f3b431c076fd186 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Sun, 19 Oct 2003 01:15:19 +0000 Subject: [PATCH] cleanup and remove duplicate methods. --- .../cdt/utils/elf/parser/ARMember.java | 6 +- .../cdt/utils/elf/parser/BinaryArchive.java | 46 ++++--------- .../utils/elf/parser/BinaryExecutable.java | 9 --- .../cdt/utils/elf/parser/BinaryFile.java | 28 +++++--- .../cdt/utils/elf/parser/BinaryObject.java | 65 ++----------------- .../cdt/utils/elf/parser/GNUElfParser.java | 28 ++++++++ .../cdt/utils/elf/parser/IToolsProvider.java | 22 ------- 7 files changed, 67 insertions(+), 137 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/IToolsProvider.java diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java index 98a3ad40e7e..165ff4b167e 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java @@ -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. } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java index 9c766240684..ba4a8b78fa5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java @@ -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[]) */ diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java index ae64ee3d5a4..b1611466617 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java @@ -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); diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java index 9b365aa02e5..08a219547e0 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java @@ -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; + } + } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java index 8548a85d14f..7030dd7ac98 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java @@ -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; - } - } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java index 8cffeda4ab0..474edfd8052 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/GNUElfParser.java @@ -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; + } + } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/IToolsProvider.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/IToolsProvider.java deleted file mode 100644 index 56a855abdac..00000000000 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/IToolsProvider.java +++ /dev/null @@ -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(); -}