Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fwd: Re: [cdt-dev] EditorUtility.getStorage(IBinary)



>
> >The problem is where do we get "objdump -CxS"?, who will spawn() it?
> >How to override it ?  etc ...
> >I'm very interested to your scheme for this, nothing satisfactory was
> >found so far.
>
> My inclination was to put it into the IBinaryParser. Put a reference to the
> BinaryParser into IBinaryFile on construction. Binary is already socking
> away the IBinaryFile, so Binary would implement these methods by delegating
> the request to IBinaryParser through the IBinaryFile.
>
> Now it all pushes back to the extension point. The extension that knows how
> to parse the binary and create the IBinaryFile also knows how to generate
> the viewable text file representation of that IBinaryFile.
>
> Here at Tensilica, we'd add a binaryparser for XtensaElf that derives from
> ElfParser, override the objdump execing method in the default
> implementation and go from there.
>

Ho! I see.  Yes.

If there's anything worse than being a director, it's being a director and attempting to get real work done. I must have died on the way in to work today and gone to hell or something. :) Regardless, here's what the changes ended up looking like for 1.2.1. I don't know if this has been an area of big churn on 2.0. If not, maybe it's helpful.

With these changes to CDT, we successfully subclassed ElfParser and overrode the new getViewableContents method to do our special magic for what shows up when you double click a binary in Xtensa Xplorer. That makes me think it works. I like not having to go in and hack EditorUtility (like we did last time.)

Some review of the creation of IBuffers by Binary is appreciated. Totally opaque to me, I just took a stab at it, might be leaking like a seive.

Thanks!
-Chris
diff -r -u xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java
--- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java	Fri Jan 16 20:25:05 2004
+++ xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java	Fri Jan 16 20:26:37 2004
@@ -15,6 +15,7 @@
 import org.eclipse.cdt.core.IBinaryParser.ISymbol;
 import org.eclipse.cdt.core.model.CModelException;
 import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IBuffer;
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
@@ -271,4 +272,19 @@
 		//}
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.core.model.IOpenable#getBuffer()
+	 */
+	public IBuffer getBuffer() throws CModelException
+	{
+		IBuffer ret = getBufferManager().getBuffer( this );
+		if( ret == null )
+		{
+			ret = getBufferManager().createBuffer(this);
+			ret.setContents( binaryFile.getParser().getViewableContents(binaryFile) );
+		}
+		
+		return ret;
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java
--- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java	Fri Jan 16 20:25:06 2004
+++ xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java	Fri Jan 16 20:26:38 2004
@@ -8,6 +8,7 @@
 import java.io.IOException;
 
 import org.eclipse.cdt.core.IBinaryParser;
+import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.core.runtime.IPath;
 
 /**
@@ -35,4 +36,12 @@
 		return false;
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.core.IBinaryParser#getViewableContents(org.eclipse.cdt.core.IBinaryParser.IBinaryFile)
+	 */
+	public char[] getViewableContents(IBinaryFile file)
+	{
+		return new char[0];
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java
--- xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java	Fri Jan 16 20:25:10 2004
+++ xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java	Fri Jan 16 20:26:41 2004
@@ -28,6 +28,7 @@
 		IPath getPath();
 		int getType();
 		InputStream getContents();
+		IBinaryParser getParser();
 	}
 
 	/**
@@ -94,4 +95,13 @@
 	boolean isBinary(byte[] array, IPath path);
 	
 	String getFormat();
+	
+	/** 
+	 * requests that the parser give a human readable form of the file. 
+	 * 
+	 * @param file this file must have been created by the binary parser.
+	 * 
+	 * @return the character array representation of the file.
+	 */
+	char []getViewableContents(IBinaryFile file);
 }
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java	Fri Jan 16 20:25:10 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/ARMember.java	Fri Jan 16 20:26:41 2004
@@ -15,6 +15,7 @@
 import java.io.InputStream;
 import java.util.List;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.ISymbol;
 import org.eclipse.cdt.utils.Addr2line;
 import org.eclipse.cdt.utils.CPPFilt;
@@ -30,8 +31,8 @@
 public class ARMember extends BinaryObject {
 	PEArchive.ARHeader header;
 
-	public ARMember(IPath p, PEArchive.ARHeader h, ICygwinToolsProvider provider) throws IOException {
-		super(p, h.getPE(), provider);
+	public ARMember(IPath p, PEArchive.ARHeader h, ICygwinToolsProvider provider, IBinaryParser parser) throws IOException {
+		super(p, h.getPE(), provider, parser);
 		header = h;
 	}
 
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java	Fri Jan 16 20:25:10 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryArchive.java	Fri Jan 16 20:26:41 2004
@@ -8,6 +8,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
@@ -21,8 +22,8 @@
 
 	ArrayList children;
 	
-	public BinaryArchive(IPath p) throws IOException {
-		super(p);
+	public BinaryArchive(IPath p, IBinaryParser parser) throws IOException {
+		super(p, parser);
 		new PEArchive(p.toOSString()).dispose(); // check file type
 		children = new ArrayList(5);
 	}
@@ -38,7 +39,7 @@
 				ar = new PEArchive(getPath().toOSString());
 				PEArchive.ARHeader[] headers = ar.getHeaders();
 				for (int i = 0; i < headers.length; i++) {
-					IBinaryObject bin = new ARMember(path, headers[i], toolsProvider);
+					IBinaryObject bin = new ARMember(path, headers[i], toolsProvider, parser);
 					children.add(bin);
 				}
 			} catch (IOException e) {
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryExecutable.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryExecutable.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryExecutable.java	Fri Jan 16 20:25:10 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryExecutable.java	Fri Jan 16 20:26:41 2004
@@ -12,6 +12,7 @@
 
 import java.io.IOException;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.core.runtime.IPath;
@@ -20,8 +21,8 @@
  */
 public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
 
-	public BinaryExecutable(IPath path) throws IOException {
-		super(path);
+	public BinaryExecutable(IPath path, IBinaryParser parser) throws IOException {
+		super(path, parser);
 	}
 
 	/**
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryFile.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryFile.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryFile.java	Fri Jan 16 20:25:10 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryFile.java	Fri Jan 16 20:26:41 2004
@@ -15,6 +15,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.utils.Addr2line;
 import org.eclipse.cdt.utils.CPPFilt;
@@ -32,9 +33,11 @@
 	protected IPath path;
 	protected ICygwinToolsProvider toolsProvider;
 	protected long timestamp;
+	protected IBinaryParser parser;
 
-	public BinaryFile(IPath p) {
+	public BinaryFile(IPath p, IBinaryParser parser) {
 		path = p;
+		this.parser = parser;
 	}
 
 	public void setToolsProvider(ICygwinToolsProvider p) {
@@ -100,4 +103,12 @@
 		return changed;
 	}
 
+	/**
+	 * @return
+	 */
+	public IBinaryParser getParser()
+	{
+		return parser;
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java	Fri Jan 16 20:26:42 2004
@@ -15,6 +15,7 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
 import org.eclipse.cdt.core.IBinaryParser.ISymbol;
@@ -37,12 +38,12 @@
 	int type = IBinaryFile.OBJECT;
 	private ISymbol[] NO_SYMBOLS = new ISymbol[0];
 	
-	public BinaryObject(IPath p) throws IOException {
-		super(p);
+	public BinaryObject(IPath p, IBinaryParser parser) throws IOException {
+		super(p, parser);
 	}
 
-	public BinaryObject(IPath p, PE pe, ICygwinToolsProvider provider) throws IOException {
-		super(p);
+	public BinaryObject(IPath p, PE pe, ICygwinToolsProvider provider, IBinaryParser parser) throws IOException {
+		super(p, parser);
 		setToolsProvider(provider);
 		loadInformation(pe);
 		pe.dispose();
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryShared.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryShared.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryShared.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryShared.java	Fri Jan 16 20:26:42 2004
@@ -12,6 +12,7 @@
 
 import java.io.IOException;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
 import org.eclipse.core.runtime.IPath;
@@ -21,8 +22,8 @@
 public class BinaryShared extends BinaryExecutable implements IBinaryShared {
 	String soname;
 
-	public BinaryShared(IPath path) throws IOException {
-		super(path);
+	public BinaryShared(IPath path, IBinaryParser parser) throws IOException {
+		super(path, parser);
 	}
 
 	/**
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/PEParser.java	Fri Jan 16 20:26:42 2004
@@ -11,13 +11,16 @@
 
 package org.eclipse.cdt.utils.coff.parser;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 
 import org.eclipse.cdt.core.AbstractCExtension;
 import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.utils.coff.PE;
 import org.eclipse.cdt.utils.coff.PEArchive;
 import org.eclipse.cdt.utils.coff.PE.Attribute;
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
 import org.eclipse.core.runtime.IPath;
 
 /**
@@ -38,19 +41,19 @@
 			if (attribute != null) {
 				switch (attribute.getType()) {
 					case Attribute.PE_TYPE_EXE :
-						binary = new BinaryExecutable(path);
+						binary = new BinaryExecutable(path, this);
 					break;
  
 					case Attribute.PE_TYPE_SHLIB :
-						binary = new BinaryShared(path);
+						binary = new BinaryShared(path, this);
 					break;
  
 					case Attribute.PE_TYPE_OBJ :
-						binary = new BinaryObject(path);
+						binary = new BinaryObject(path, this);
 					break;
  
 					case Attribute.PE_TYPE_CORE :
-						BinaryObject obj = new BinaryObject(path);
+						BinaryObject obj = new BinaryObject(path, this);
 						obj.setType(IBinaryFile.CORE);
 						binary = obj;
 					break;
@@ -58,7 +61,7 @@
 			}
 		} catch (IOException e) {
 			// Is it an Archive?
-			binary = new BinaryArchive(path);
+			binary = new BinaryArchive(path, this);
 		}
 
 		return binary;
@@ -78,4 +81,35 @@
 		return PE.isExeHeader(array) || PEArchive.isARHeader(array);
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.core.IBinaryParser#getViewableContents()
+	 */
+	public char[] getViewableContents(IBinaryFile bfile)
+	{
+		Process objdump = null;
+		IPath path;
+		StringBuffer buffer = new StringBuffer();
+		path = bfile.getPath();
+		
+		try {
+			String[] args = new String[] {"objdump", "-CxS", path.toOSString()};
+			objdump = ProcessFactory.getFactory().exec(args);
+			BufferedReader stdout =
+				new BufferedReader(new InputStreamReader(objdump.getInputStream()));
+			char[] buf = new char[128];
+			while (stdout.read(buf, 0, buf.length) != -1) {
+				buffer.append(buf);
+			}
+		} catch (SecurityException e) {
+		} catch (IndexOutOfBoundsException e) {
+		} catch (NullPointerException e) {
+		} catch (IOException e) {
+		} finally {
+			if (objdump != null) {
+				objdump.destroy();
+			}
+		}
+		return buffer.toString().toCharArray();		
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ARMember.java	Fri Jan 16 20:26:42 2004
@@ -15,6 +15,7 @@
 import java.io.InputStream;
 import java.util.List;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.utils.Addr2line;
 import org.eclipse.cdt.utils.CPPFilt;
 import org.eclipse.cdt.utils.IToolsProvider;
@@ -28,8 +29,8 @@
 public class ARMember extends BinaryObject {
 	AR.ARHeader header;
 
-	public ARMember(IPath p, AR.ARHeader h, IToolsProvider provider) throws IOException {
-		super(p, new ElfHelper(h.getElf()), provider);
+	public ARMember(IPath p, AR.ARHeader h, IToolsProvider provider, IBinaryParser parser) throws IOException {
+		super(p, new ElfHelper(h.getElf()), provider, parser);
 		header = h;
 	}
 
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java	Fri Jan 16 20:26:42 2004
@@ -13,6 +13,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
@@ -27,8 +28,8 @@
 	ArrayList children;
 	long timestamp;
 
-	public BinaryArchive(IPath p) throws IOException {
-		super(p);
+	public BinaryArchive(IPath p, IBinaryParser parser) throws IOException {
+		super(p, parser);
 		new AR(p.toOSString()).dispose(); // check file type
 		children = new ArrayList(5);
 	}
@@ -44,7 +45,7 @@
 				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], toolsProvider);
+					IBinaryObject bin = new ARMember(getPath(), headers[i], toolsProvider, parser);
 					children.add(bin);
 				}
 			} catch (IOException e) {
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryExecutable.java	Fri Jan 16 20:26:42 2004
@@ -12,6 +12,7 @@
 
 import java.io.IOException;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.core.runtime.IPath;
@@ -20,8 +21,8 @@
  */
 public class BinaryExecutable extends BinaryObject implements IBinaryExecutable {
 
-	public BinaryExecutable(IPath path) throws IOException {
-		super(path);
+	public BinaryExecutable(IPath path, IBinaryParser parser) throws IOException {
+		super(path, parser);
 	}
 
 	/**
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryFile.java	Fri Jan 16 20:26:42 2004
@@ -15,6 +15,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.utils.*;
 import org.eclipse.cdt.utils.Addr2line;
@@ -31,9 +32,11 @@
 	protected IPath path;
 	protected IToolsProvider toolsProvider;
 	protected long timestamp;
+	protected IBinaryParser parser;
 
-	public BinaryFile(IPath p) {
+	public BinaryFile(IPath p, IBinaryParser parser) {
 		path = p;
+		this.parser = parser;
 	}
 
 	public void setToolsProvider(IToolsProvider p) {
@@ -94,4 +97,12 @@
 		return changed;
 	}
  
+	/**
+	 * @return
+	 */
+	public IBinaryParser getParser()
+	{
+		return parser;
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java	Fri Jan 16 20:26:42 2004
@@ -15,6 +15,7 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
 import org.eclipse.cdt.core.IBinaryParser.ISymbol;
@@ -39,12 +40,12 @@
 	private ISymbol[] symbols;
 	private ISymbol[] NO_SYMBOLS = new ISymbol[0];
 
-	public BinaryObject(IPath path) throws IOException {
-		super(path);
+	public BinaryObject(IPath path, IBinaryParser parser) throws IOException {
+		super(path, parser);
 	}
 
-	public BinaryObject(IPath path, ElfHelper helper, IToolsProvider provider) throws IOException {
-		super(path);
+	public BinaryObject(IPath path, ElfHelper helper, IToolsProvider provider, IBinaryParser parser) throws IOException {
+		super(path, parser);
 		setToolsProvider(provider);
 		loadInformation(helper);
 		helper.dispose();
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryShared.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryShared.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryShared.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryShared.java	Fri Jan 16 20:26:42 2004
@@ -12,6 +12,7 @@
 
 import java.io.IOException;
 
+import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
 import org.eclipse.core.runtime.IPath;
@@ -20,8 +21,8 @@
  */
 public class BinaryShared extends BinaryExecutable implements IBinaryShared {
 
-	public BinaryShared(IPath path) throws IOException {
-		super(path);
+	public BinaryShared(IPath path, IBinaryParser parser) throws IOException {
+		super(path, parser);
 	}
 
 	/**
diff -r -u xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java
--- xide/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java	Fri Jan 16 20:26:42 2004
@@ -10,13 +10,17 @@
 ***********************************************************************/
 package org.eclipse.cdt.utils.elf.parser;
  
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 
 import org.eclipse.cdt.core.AbstractCExtension;
 import org.eclipse.cdt.core.IBinaryParser;
 import org.eclipse.cdt.utils.elf.AR;
 import org.eclipse.cdt.utils.elf.Elf;
 import org.eclipse.cdt.utils.elf.Elf.Attribute;
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IPath;
 
 /**
@@ -37,26 +41,26 @@
 			if (attribute != null) {
 				switch (attribute.getType()) {
 					case Attribute.ELF_TYPE_EXE :
-						binary = new BinaryExecutable(path);
+						binary = new BinaryExecutable(path, this);
 						break;
 
 					case Attribute.ELF_TYPE_SHLIB :
-						binary = new BinaryShared(path);
+						binary = new BinaryShared(path, this);
 						break;
 
 					case Attribute.ELF_TYPE_OBJ :
-						binary = new BinaryObject(path);
+						binary = new BinaryObject(path, this);
 						break;
 
 					case Attribute.ELF_TYPE_CORE :
-						BinaryObject obj = new BinaryObject(path);
+						BinaryObject obj = new BinaryObject(path, this);
 						obj.setType(IBinaryFile.CORE);
 						binary = obj;
 						break;
 				}
 			}
 		} catch (IOException e) {
-			binary = new BinaryArchive(path);
+			binary = new BinaryArchive(path, this);
 		}
 		return binary;
 	}
@@ -75,4 +79,35 @@
 		return Elf.isElfHeader(array) || AR.isARHeader(array);
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.core.IBinaryParser#getViewableContents()
+	 */
+	public char[] getViewableContents(IBinaryFile bfile)
+	{
+		Process objdump = null;
+		IPath path;
+		StringBuffer buffer = new StringBuffer();
+		path = bfile.getPath();
+		
+		try {
+			String[] args = new String[] {"objdump", "-CxS", path.toOSString()};
+			objdump = ProcessFactory.getFactory().exec(args);
+			BufferedReader stdout =
+				new BufferedReader(new InputStreamReader(objdump.getInputStream()));
+			char[] buf = new char[128];
+			while (stdout.read(buf, 0, buf.length) != -1) {
+				buffer.append(buf);
+			}
+		} catch (SecurityException e) {
+		} catch (IndexOutOfBoundsException e) {
+		} catch (NullPointerException e) {
+		} catch (IOException e) {
+		} finally {
+			if (objdump != null) {
+				objdump.destroy();
+			}
+		}
+		return buffer.toString().toCharArray();		
+	}
+
 }
diff -r -u xide/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java xide_compare/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
--- xide/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java	Fri Jan 16 20:25:28 2004
+++ xide_compare/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java	Fri Jan 16 20:26:57 2004
@@ -297,33 +297,11 @@
 	
 	public static IStorage getStorage(IBinary bin) {
 		IStorage store = null;
-		Process objdump = null;
-		IPath path;
-		IResource file = null;
-		file = bin.getResource();
-		if (file == null)
-			return store;
-		path = file.getLocation();
 		try {
-			String[] args = new String[] {"objdump", "-CxS", path.toOSString()};
-			objdump = ProcessFactory.getFactory().exec(args);
-			StringBuffer buffer = new StringBuffer();
-			BufferedReader stdout =
-				new BufferedReader(new InputStreamReader(objdump.getInputStream()));
-			char[] buf = new char[128];
-			while (stdout.read(buf, 0, buf.length) != -1) {
-				buffer.append(buf);
-			}
-			store = new FileStorage(new ByteArrayInputStream(buffer.toString().getBytes()), path);
-		} catch (SecurityException e) {
-		} catch (IndexOutOfBoundsException e) {
-		} catch (NullPointerException e) {
-		} catch (IOException e) {
-		} finally {
-			if (objdump != null) {
-				objdump.destroy();
-			}
-		}
+			store = new FileStorage(new ByteArrayInputStream(bin.getBuffer().getContents().getBytes()), 
+				bin.getPath());
+		} catch (CModelException e) {
+		} 
 		return store;
 	}
 }

Back to the top