GP-1360: Fixed GDB/GADP agent death/hang in development mode.

This commit is contained in:
Dan 2021-10-04 15:57:32 -04:00
parent 9509ec1b98
commit 9596c5be4f
2 changed files with 20 additions and 3 deletions

View File

@ -37,16 +37,19 @@ import agent.gdb.manager.impl.cmd.*;
import agent.gdb.manager.parsing.GdbMiParser;
import agent.gdb.manager.parsing.GdbParsingUtils.GdbParseError;
import agent.gdb.pty.*;
import ghidra.GhidraApplicationLayout;
import ghidra.async.*;
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.framework.GhidraApplicationConfiguration;
import ghidra.lifecycle.Internal;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
import ghidra.util.datastruct.ListenerSet;
import ghidra.util.task.ConsoleTaskMonitor;
import sun.misc.Signal;
import sun.misc.SignalHandler;
@ -206,7 +209,8 @@ public class GdbManagerImpl implements GdbManager {
private void initLog() {
try {
File userSettings = Application.getUserSettingsDirectory();
GhidraApplicationLayout layout = new GhidraApplicationLayout();
File userSettings = layout.getUserSettingsDir();
File logFile = new File(userSettings, "GDB.log");
try {
logFile.createNewFile();
@ -216,7 +220,7 @@ public class GdbManagerImpl implements GdbManager {
}
DBG_LOG = new PrintWriter(new FileOutputStream(logFile));
}
catch (FileNotFoundException e) {
catch (IOException e) {
throw new AssertionError(e);
}
}

View File

@ -47,6 +47,11 @@ public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerM
public final Property<Integer> jdwpPortOption =
Property.fromAccessors(int.class, this::getJdwpPort, this::setJdwpPort);
protected boolean jdwpSuspend = false;
@FactoryOption("Suspend for JDWP")
public final Property<Boolean> jdwpSuspendOption =
Property.fromAccessors(boolean.class, this::isJdwpSuspend, this::setJdwpSuspend);
/**
* Get the name of the thread which processes the agent's stdout
*/
@ -86,6 +91,14 @@ public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerM
this.jdwpPort = jdwpPort;
}
public boolean isJdwpSuspend() {
return jdwpSuspend;
}
public void setJdwpSuspend(boolean jdwpSuspend) {
this.jdwpSuspend = jdwpSuspend;
}
class AgentThread extends Thread {
int port;
Process process;
@ -104,7 +117,7 @@ public abstract class AbstractGadpLocalDebuggerModelFactory implements DebuggerM
cmd.addAll(List.of("-cp", System.getProperty("java.class.path")));
if (jdwpPort >= 0) {
cmd.add("-agentlib:jdwp=server=y,transport=dt_socket,address=" + jdwpPort +
",suspend=n");
",suspend=" + (jdwpSuspend ? "y" : "n"));
}
completeCommandLine(cmd);
builder.command(cmd);