GP-3800: Get TerminalService working on Windows, too.

This commit is contained in:
Dan 2023-09-05 13:52:35 -04:00
parent 5bed356fd2
commit a548e54075
37 changed files with 834 additions and 217 deletions

View file

@ -79,6 +79,11 @@ public class GdbManagerImpl implements GdbManager {
private static final String GDB_IS_TERMINATING = "GDB is terminating";
public static final int MAX_CMD_LEN = 4094; // Account for longest possible line end
private static final boolean IS_WINDOWS =
OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS;
private static final short PTY_COLS = IS_WINDOWS ? Short.MAX_VALUE : 0;
private static final short PTY_ROWS = IS_WINDOWS ? (short) 1 : 0;
private String maintInfoSectionsCmd = GdbModuleImpl.MAINT_INFO_SECTIONS_CMD_V11;
private Pattern fileLinePattern = GdbModuleImpl.OBJECT_FILE_LINE_PATTERN_V11;
private Pattern sectionLinePattern = GdbModuleImpl.OBJECT_SECTION_LINE_PATTERN_V10;
@ -119,7 +124,7 @@ public class GdbManagerImpl implements GdbManager {
InputStream inputStream = pty.getParent().getInputStream();
// TODO: This should really only be applied to the MI2 console
// But, we don't know what we have until we read it....
if (OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS) {
if (IS_WINDOWS) {
inputStream = new AnsiBufferedInputStream(inputStream);
}
this.reader = new BufferedReader(new InputStreamReader(inputStream));
@ -652,7 +657,8 @@ public class GdbManagerImpl implements GdbManager {
executor = Executors.newSingleThreadExecutor();
if (gdbCmd != null) {
iniThread = new PtyThread(ptyFactory.openpty(), Channel.STDOUT, null);
iniThread =
new PtyThread(ptyFactory.openpty(PTY_COLS, PTY_ROWS), Channel.STDOUT, null);
Msg.info(this, "Starting gdb with: " + fullargs);
gdb =
@ -708,7 +714,7 @@ public class GdbManagerImpl implements GdbManager {
}
}
else {
Pty mi2Pty = ptyFactory.openpty();
Pty mi2Pty = ptyFactory.openpty(Short.MAX_VALUE, (short) 1);
String mi2PtyName = mi2Pty.getChild().nullSession(Echo.OFF);
Msg.info(this, "Agent is waiting for GDB/MI v2 interpreter at " + mi2PtyName);
mi2Thread = new PtyThread(mi2Pty, Channel.STDOUT, Interpreter.MI2);

View file

@ -40,7 +40,6 @@ import generic.ULongSpan.ULongSpanSet;
import ghidra.async.AsyncReference;
import ghidra.dbg.testutil.DummyProc;
import ghidra.pty.PtyFactory;
import ghidra.pty.linux.LinuxPtyFactory;
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
@ -62,8 +61,7 @@ public abstract class AbstractGdbManagerTest extends AbstractGhidraHeadlessInteg
}
protected PtyFactory getPtyFactory() {
// TODO: Choose by host OS
return new LinuxPtyFactory();
return PtyFactory.local();
}
protected abstract CompletableFuture<Void> startManager(GdbManager manager);

View file

@ -21,8 +21,6 @@ import java.util.concurrent.CompletableFuture;
import org.junit.Ignore;
import agent.gdb.manager.GdbManager;
import ghidra.pty.PtyFactory;
import ghidra.pty.windows.ConPtyFactory;
@Ignore("Need compatible version on CI")
public class SpawnedWindowsMi2GdbManagerTest extends AbstractGdbManagerTest {
@ -36,10 +34,4 @@ public class SpawnedWindowsMi2GdbManagerTest extends AbstractGdbManagerTest {
throw new AssertionError(e);
}
}
@Override
protected PtyFactory getPtyFactory() {
// TODO: Choose by host OS
return new ConPtyFactory();
}
}