GP-1133: logic to id unwritable log and allow the user to fix it

This commit is contained in:
d-millar 2021-07-14 12:59:25 -04:00
parent 928bc5508a
commit 973c9b9495

View File

@ -15,7 +15,7 @@
*/
package agent.gdb.manager.impl;
import static ghidra.async.AsyncUtils.loop;
import static ghidra.async.AsyncUtils.*;
import java.io.*;
import java.util.*;
@ -40,6 +40,7 @@ import ghidra.async.AsyncLock.Hold;
import ghidra.dbg.error.DebuggerModelTerminatingException;
import ghidra.dbg.util.HandlerMap;
import ghidra.dbg.util.PrefixMap;
import ghidra.framework.Application;
import ghidra.lifecycle.Internal;
import ghidra.util.Msg;
import ghidra.util.datastruct.ListenerSet;
@ -73,20 +74,7 @@ public class GdbManagerImpl implements GdbManager {
private static final boolean LOG_IO = true |
Boolean.parseBoolean(System.getProperty("agent.gdb.manager.log"));
private static final PrintWriter DBG_LOG;
static {
if (LOG_IO) {
try {
DBG_LOG = new PrintWriter(new FileOutputStream(new File("GDB.log")));
}
catch (FileNotFoundException e) {
throw new AssertionError(e);
}
}
else {
DBG_LOG = null;
}
}
private static PrintWriter DBG_LOG = null;
private static final String PROMPT_GDB = "(gdb)";
public static final int INTERRUPT_MAX_RETRIES = 3;
public static final int INTERRUPT_RETRY_PERIOD_MILLIS = 100;
@ -111,6 +99,9 @@ public class GdbManagerImpl implements GdbManager {
@Override
public void run() {
if (LOG_IO && DBG_LOG == null) {
initLog();
}
try {
String line;
while (isAlive() && null != (line = reader.readLine())) {
@ -208,6 +199,20 @@ public class GdbManagerImpl implements GdbManager {
defaultHandlers();
}
private void initLog() {
try {
File userSettings = Application.getUserSettingsDirectory();
File logFile = new File(userSettings, "GDB.log");
if (!logFile.canWrite()) {
throw new AssertionError(logFile.getPath() + " appears to be unwritable");
}
DBG_LOG = new PrintWriter(new FileOutputStream(logFile));
}
catch (FileNotFoundException e) {
throw new AssertionError(e);
}
}
CompletableFuture<Void> event(Runnable r, String text) {
//Msg.debug(this, "Queueing event: " + text);
return CompletableFuture.runAsync(r, eventThread).exceptionally(ex -> {