mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Bug 441385 - Binary editor on big files blocks UI
Change-Id: I4ac0c8eff4e77045657f0fe5921a86a966a22922 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/31238 Tested-by: Hudson CI
This commit is contained in:
parent
b89c530f09
commit
15402f6488
4 changed files with 65 additions and 14 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,7 +46,7 @@ public class Objdump {
|
||||||
public Objdump(String command, String[] params, String file) throws IOException {
|
public Objdump(String command, String[] params, String file) throws IOException {
|
||||||
init(command, params, file);
|
init(command, params, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Objdump(String file) throws IOException {
|
public Objdump(String file) throws IOException {
|
||||||
this("objdump", new String[0], file); //$NON-NLS-1$
|
this("objdump", new String[0], file); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -60,18 +61,54 @@ public class Objdump {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getOutput() throws IOException {
|
@Override
|
||||||
Process objdump = ProcessFactory.getFactory().exec(args);
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuilder b = new StringBuilder();
|
||||||
BufferedReader stdout = new BufferedReader(new InputStreamReader(objdump.getInputStream()));
|
b.append(args[0]);
|
||||||
char[] buf = new char[512];
|
for (int i = 1; i < args.length; i++) {
|
||||||
int len;
|
b.append(" "); //$NON-NLS-1$
|
||||||
while ((len = stdout.read(buf, 0, buf.length)) != -1) {
|
b.append(args[i]);
|
||||||
buffer.append(buf, 0, len);
|
|
||||||
}
|
}
|
||||||
stdout.close();
|
return b.toString();
|
||||||
objdump.destroy();
|
}
|
||||||
return buffer.toString().getBytes();
|
/**
|
||||||
|
* Limit output to number of bytes
|
||||||
|
*/
|
||||||
|
public byte[] getOutput(int limitBytes) throws IOException {
|
||||||
|
Process objdump = ProcessFactory.getFactory().exec(args);
|
||||||
|
try {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
BufferedReader stdout = new BufferedReader(new InputStreamReader(
|
||||||
|
objdump.getInputStream()));
|
||||||
|
char[] buf = new char[4096];
|
||||||
|
int len;
|
||||||
|
while ((len = stdout.read(buf, 0, buf.length)) != -1) {
|
||||||
|
if (limitBytes > 0 && buffer.length() + len >= limitBytes) {
|
||||||
|
buffer.append(buf, 0, Math.min(len, limitBytes - buffer.length()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer.append(buf, 0, len);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
stdout.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore that
|
||||||
|
}
|
||||||
|
return buffer.toString().getBytes();
|
||||||
|
} finally {
|
||||||
|
objdump.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getOutput() throws IOException {
|
||||||
|
return getOutput(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
Process objdump = ProcessFactory.getFactory().exec(args);
|
||||||
|
objdump.getOutputStream().close();
|
||||||
|
objdump.getErrorStream().close();
|
||||||
|
return objdump.getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
|
|
@ -61,6 +61,7 @@ public final class CEditorMessages extends NLS {
|
||||||
public static String OverrideIndicatorManager_overrides;
|
public static String OverrideIndicatorManager_overrides;
|
||||||
public static String OverrideIndicatorManager_shadows;
|
public static String OverrideIndicatorManager_shadows;
|
||||||
public static String OverrideIndicatorManager_via;
|
public static String OverrideIndicatorManager_via;
|
||||||
|
public static String DefaultBinaryFileEditor_TruncateMessage;
|
||||||
public static String DefaultCEditorTextHover_html_name;
|
public static String DefaultCEditorTextHover_html_name;
|
||||||
public static String DefaultCEditorTextHover_html_prototype;
|
public static String DefaultCEditorTextHover_html_prototype;
|
||||||
public static String DefaultCEditorTextHover_html_description;
|
public static String DefaultCEditorTextHover_html_description;
|
||||||
|
|
|
@ -49,6 +49,7 @@ OverrideIndicatorManager_overrides=Overrides
|
||||||
OverrideIndicatorManager_shadows=Shadows
|
OverrideIndicatorManager_shadows=Shadows
|
||||||
OverrideIndicatorManager_via=via
|
OverrideIndicatorManager_via=via
|
||||||
|
|
||||||
|
DefaultBinaryFileEditor_TruncateMessage=Truncated, result is too large, use command line objdump
|
||||||
DefaultCEditorTextHover_html_name=<b>Name:</b>
|
DefaultCEditorTextHover_html_name=<b>Name:</b>
|
||||||
DefaultCEditorTextHover_html_prototype=<br><b>Prototype:</b>
|
DefaultCEditorTextHover_html_prototype=<br><b>Prototype:</b>
|
||||||
DefaultCEditorTextHover_html_description=<br><b>Description:</b><br>
|
DefaultCEditorTextHover_html_description=<br><b>Description:</b><br>
|
||||||
|
|
|
@ -119,10 +119,22 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
Objdump objdump= factory.getObjdump(object.getPath());
|
Objdump objdump = factory.getObjdump(object.getPath());
|
||||||
if (objdump != null) {
|
if (objdump != null) {
|
||||||
try {
|
try {
|
||||||
fStorage= new FileStorage(new ByteArrayInputStream(objdump.getOutput()), object.getPath());
|
// limit editor to X MB, if more - users should use objdump in command
|
||||||
|
// this is UI blocking call, on 56M binary it takes more than 15 min
|
||||||
|
// and generates at least 2.5G of assembly
|
||||||
|
int limitBytes = 6 * 1024 * 1024; // this can run reasonably within seconds
|
||||||
|
byte[] output = objdump.getOutput(limitBytes);
|
||||||
|
if (output.length >= limitBytes) {
|
||||||
|
// add a message for user
|
||||||
|
String text = CEditorMessages.DefaultBinaryFileEditor_TruncateMessage;
|
||||||
|
String message = "\n\n--- " + text + " ---\n" + objdump.toString(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
System.arraycopy(message.getBytes(), 0, output,
|
||||||
|
limitBytes - message.length(), message.length());
|
||||||
|
}
|
||||||
|
fStorage = new FileStorage(new ByteArrayInputStream(output), object.getPath());
|
||||||
} catch (IOException exc) {
|
} catch (IOException exc) {
|
||||||
CUIPlugin.log(exc);
|
CUIPlugin.log(exc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue