Debugger Process exception handling

This commit is contained in:
dragonmacher
2021-07-14 17:04:08 -04:00
parent 245b57d69b
commit 59cd0938ff
3 changed files with 35 additions and 10 deletions

View File

@@ -22,13 +22,24 @@ import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.commons.lang3.exception.ExceptionUtils;
import agent.gdb.gadp.impl.GdbGadpServerImpl;
import ghidra.dbg.agent.AgentWindow;
import ghidra.util.Msg;
public interface GdbGadpServer extends AutoCloseable {
public static void main(String[] args) throws Exception {
new Runner().run(args);
try {
new Runner().run(args);
}
catch (Throwable t) {
System.err.println(ExceptionUtils.getMessage(t));
t.printStackTrace(System.err);
System.exit(1);
}
// new Runner().run(args);
}
public static GdbGadpServer newInstance(SocketAddress addr) throws IOException {

View File

@@ -15,18 +15,18 @@
*/
package ghidra.dbg.gadp.server;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.ProcessBuilder.Redirect;
import java.io.*;
import java.nio.channels.AsynchronousByteChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import generic.concurrent.io.IOResult;
import generic.concurrent.io.ProcessConsumer;
import ghidra.dbg.DebuggerModelFactory;
import ghidra.dbg.gadp.client.GadpClient;
import ghidra.dbg.gadp.client.GadpTcpDebuggerModelFactory;
import ghidra.dbg.util.ConfigurableFactory.FactoryOption;
import ghidra.util.Msg;
public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerModelFactory {
@@ -108,9 +108,13 @@ public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerM
}
completeCommandLine(cmd);
builder.command(cmd);
builder.redirectError(Redirect.INHERIT);
//builder.redirectError(Redirect.INHERIT);
process = builder.start();
InputStream errorStream = process.getErrorStream();
Future<IOResult> errorFuture = ProcessConsumer.consume(errorStream);
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
@@ -124,9 +128,19 @@ public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerM
ready.complete(null);
}
}
if (!ready.isDone()) {
ready.completeExceptionally(
new RuntimeException("Agent terminated unexpectedly"));
IOResult errorResult = errorFuture.get();
String errorMessage = errorResult.getOutputAsString();
if (errorMessage != null) {
ready.completeExceptionally(
new RuntimeException("Agent terminated with error: " + errorMessage));
}
else {
ready.completeExceptionally(
new RuntimeException("Agent terminated unexpectedly"));
}
}
}
catch (Throwable e) {

View File

@@ -32,7 +32,7 @@ public class IOResult implements Runnable {
public static final String THREAD_POOL_NAME = "I/O Thread Pool";
private List<String> outputLines = new ArrayList<String>();
private List<String> outputLines = new ArrayList<>();
private BufferedReader commandOutput;
private final Throwable inception;
private Consumer<String> consumer = Dummy.consumer();
@@ -53,7 +53,7 @@ public class IOResult implements Runnable {
public String getOutputAsString() {
StringBuilder buffy = new StringBuilder();
for (String line : outputLines) {
buffy.append(line);
buffy.append(line).append("\n");
}
return buffy.toString();
}