Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1365: Several fixes for GDB 'use existing session'

Dan78f986a22f0d
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbConsoleOperations.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbConsoleOperations.java
new file mode 100644
index 0000000000..bd20bde21a
--- /dev/null
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbConsoleOperations.java
@@ -0,0 +1,70 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package agent.gdb.manager;
+
+import java.util.concurrent.CompletableFuture;
+
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
+
+public interface GdbConsoleOperations {
+ /**
+ * Execute an arbitrary CLI command, printing output to the CLI console
+ *
+ * <p>
+ * The command is executed in the context of this object. If more specific context is necessary,
+ * it will take from whatever happens to be selected, e.g., the current thread.
+ *
+ * @param command the command to execute
+ * @param cwr specifies expected state change behavior
+ * @return a future that completes when GDB has executed the command
+ */
+ CompletableFuture<Void> console(String command, CompletesWithRunning cwr);
+
+ /**
+ * Equivalent to {@link #console(String, CompletesWithRunning)} with no behavior restriction
+ *
+ * @param command the command to execute
+ * @return a future that completes when GDB has executed the command
+ */
+ default CompletableFuture<Void> console(String command) {
+ return console(command, CompletesWithRunning.CAN);
+ }
+
+ /**
+ * Execute an arbitrary CLI command, capturing its console output
+ *
+ * <p>
+ * The output will not be printed to the CLI console. The command is executed in the context of
+ * this object. If more specific context is necessary, it will take from whatever happens to be
+ * selected, e.g., the current thread.
+ *
+ * @param command the command to execute
+ * @param cwr specifies expected state change behavior
+ * @return a future that completes with the captured output when GDB has executed the command
+ */
+ CompletableFuture<String> consoleCapture(String command, CompletesWithRunning cwr);
+
+ /**
+ * Equivalent to {@link #consoleCapture(String, CompletesWithRunning)} with no behavior
+ * restriction
+ *
+ * @param command the command to execute
+ * @return a future that completes with the captured output when GDB has executed the command
+ */
+ default CompletableFuture<String> consoleCapture(String command) {
+ return consoleCapture(command, CompletesWithRunning.CAN);
+ }
+}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrameOperations.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbContextualOperations.java
similarity index 72%
rename from Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrameOperations.java
rename to Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbContextualOperations.java
index 54f2b37c41..a749a4570a 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrameOperations.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbContextualOperations.java
@@ -20,7 +20,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
-public interface GdbStackFrameOperations {
+public interface GdbContextualOperations extends GdbConsoleOperations {
/**
* Evaluate an expression
*
@@ -47,23 +47,4 @@ public interface GdbStackFrameOperations {
* @return a future that completes when the registers have been written
*/
CompletableFuture<Void> writeRegisters(Map<GdbRegister, BigInteger> regVals);
-
- /**
- * Execute an arbitrary CLI command, printing output to the CLI console
- *
- * @param command the command to execute
- * @return a future that completes when GDB has executed the command
- */
- CompletableFuture<Void> console(String command);
-
- /**
- * Execute an arbitrary CLI command, capturing its console output
- *
- * The output will not be printed to the CLI console.
- *
- * @param command the command to execute
- * @return a future that completes with the captured output when GDB has executed the command
- */
- CompletableFuture<String> consoleCapture(String command);
-
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbInferior.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbInferior.java
index 670650889c..e61f1763d8 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbInferior.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbInferior.java
@@ -32,7 +32,7 @@ import agent.gdb.manager.impl.GdbMemoryMapping;
* method issuing a command will first change focus to this inferior. The returned future completes
* when GDB has finished executing the command.
*/
-public interface GdbInferior extends GdbMemoryOperations {
+public interface GdbInferior extends GdbConsoleOperations, GdbMemoryOperations {
/**
* Get the GDB-assigned inferior number
@@ -219,30 +219,6 @@ public interface GdbInferior extends GdbMemoryOperations {
*/
CompletableFuture<Set<GdbThread>> attach(long pid);
- /**
- * Execute an arbitrary CLI command, printing output to the CLI console
- *
- * <p>
- * Note: to ensure a certain thread has focus for a console command, see
- * {@link GdbThread#console(String)}.
- *
- * @param command the command to execute
- * @return a future that completes when GDB has executed the command
- */
- CompletableFuture<Void> console(String command);
-
- /**
- * Execute an arbitrary CLI command, capturing its console output
- *
- * <p>
- * The output will not be printed to the CLI console. To ensure a certain thread has focus for a
- * console command, see {@link GdbThread#consoleCapture(String)}.
- *
- * @param command the command to execute
- * @return a future that completes with the captured output when GDB has executed the command
- */
- CompletableFuture<String> consoleCapture(String command);
-
/**
* Continue execution
*
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbManager.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbManager.java
index 57973b2cfc..033579b4f2 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbManager.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbManager.java
@@ -36,7 +36,7 @@ import agent.gdb.pty.linux.LinuxPtyFactory;
* {@link CompletableFuture} all send commands to GDB, and the future completes when the command has
* been executed.
*/
-public interface GdbManager extends AutoCloseable, GdbBreakpointInsertions {
+public interface GdbManager extends AutoCloseable, GdbConsoleOperations, GdbBreakpointInsertions {
public static final String DEFAULT_GDB_CMD = "/usr/bin/gdb";
/**
@@ -396,7 +396,9 @@ public interface GdbManager extends AutoCloseable, GdbBreakpointInsertions {
* This is used to squelch normal processing of a stopped event until the next prompt
*
* @return a future which completes when the "command" has finished execution
+ * @deprecated I don't see this being used anywhere. Probably defunct.
*/
+ @Deprecated
CompletableFuture<Void> claimStopped();
/**
@@ -432,34 +434,6 @@ public interface GdbManager extends AutoCloseable, GdbBreakpointInsertions {
*/
CompletableFuture<Void> removeInferior(GdbInferior inferior);
- /**
- * Execute an arbitrary CLI command, printing output to the CLI console
- *
- * <p>
- * Note: to ensure a certain thread or inferior has focus for a console command, see
- * {@link GdbThread#console(String)} and {@link GdbInferior#console(String)}.
- *
- * @param command the command to execute
- * @return a future that completes when GDB has executed the command
- */
- CompletableFuture<Void> console(String command);
-
- /**
- * Execute an arbitrary CLI command, capturing its console output
- *
- * <p>
- * The output will not be printed to the CLI console. To ensure a certain thread or inferior has
- * focus for a console command, see {@link GdbThread#consoleCapture(String)} and
- * {@link GdbInferior#consoleCapture(String)}. The caller should take care that other commands
- * or events are not actively producing console output. If they are, those lines may be captured
- * though they are unrelated to the given command. Generally, this can be achieved by assuring
- * that GDB is in the {@link GdbState#STOPPED} state using {@link #waitForState(GdbState)}.
- *
- * @param command the command to execute
- * @return a future that completes with the captured output when GDB has executed the command
- */
- CompletableFuture<String> consoleCapture(String command);
-
/**
* Interrupt the GDB session
*
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrame.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrame.java
index 017ae8172b..e8108cdff7 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrame.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbStackFrame.java
@@ -18,7 +18,7 @@ package agent.gdb.manager;
import java.math.BigInteger;
import java.util.concurrent.CompletableFuture;
-public interface GdbStackFrame extends GdbStackFrameOperations {
+public interface GdbStackFrame extends GdbContextualOperations {
// TODO: from, args?
/**
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbThread.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbThread.java
index 7dd3cbe328..47f7817d5c 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbThread.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/GdbThread.java
@@ -32,7 +32,7 @@ import agent.gdb.manager.impl.GdbThreadInfo;
* finished executing the command.
*/
public interface GdbThread
- extends GdbBreakpointInsertions, GdbMemoryOperations, GdbStackFrameOperations {
+ extends GdbBreakpointInsertions, GdbMemoryOperations, GdbContextualOperations {
/**
* Get the inferior to which this thread belongs
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbInferiorImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbInferiorImpl.java
index 50ab8a335f..221418e055 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbInferiorImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbInferiorImpl.java
@@ -27,8 +27,10 @@ import java.util.regex.Pattern;
import com.google.common.collect.RangeSet;
import agent.gdb.manager.*;
+import agent.gdb.manager.GdbCause.Causes;
import agent.gdb.manager.GdbManager.StepCmd;
import agent.gdb.manager.impl.cmd.*;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import ghidra.async.AsyncLazyValue;
import ghidra.lifecycle.Internal;
import ghidra.util.Msg;
@@ -84,9 +86,15 @@ public class GdbInferiorImpl implements GdbInferior {
}
public void update(GdbInferiorThreadGroup g) {
+ Long oldPid = pid;
this.pid = g.getPid();
this.exitCode = g.getExitCode();
this.executable = g.getExecutable();
+
+ // Because we're only called to resync, we should synth started, if needed
+ if (oldPid == null && pid != null) {
+ manager.fireInferiorStarted(this, Causes.UNCLAIMED, "resyncInferiorStarted");
+ }
}
@Override
@@ -225,8 +233,9 @@ public class GdbInferiorImpl implements GdbInferior {
public CompletableFuture<Map<String, GdbModule>> listModules() {
// "nosections" is an unlikely section name. Goal is to exclude section lines.
// TODO: See how this behaves on other GDB versions.
- return consoleCapture("maintenance info sections ALLOBJ nosections")
- .thenApply(this::parseModuleNames);
+ return consoleCapture("maintenance info sections ALLOBJ nosections",
+ CompletesWithRunning.CANNOT)
+ .thenApply(this::parseModuleNames);
}
protected CompletableFuture<Void> loadSections() {
@@ -234,7 +243,7 @@ public class GdbInferiorImpl implements GdbInferior {
}
protected CompletableFuture<Void> doLoadSections() {
- return consoleCapture("maintenance info sections ALLOBJ")
+ return consoleCapture("maintenance info sections ALLOBJ", CompletesWithRunning.CANNOT)
.thenAccept(this::parseAndUpdateAllModuleSections);
}
@@ -319,7 +328,8 @@ public class GdbInferiorImpl implements GdbInferior {
@Override
public CompletableFuture<Map<BigInteger, GdbMemoryMapping>> listMappings() {
- return consoleCapture("info proc mappings").thenApply(this::parseMappings);
+ return consoleCapture("info proc mappings", CompletesWithRunning.CANNOT)
+ .thenApply(this::parseMappings);
}
protected Map<BigInteger, GdbMemoryMapping> parseMappings(String out) {
@@ -377,15 +387,15 @@ public class GdbInferiorImpl implements GdbInferior {
}
@Override
- public CompletableFuture<Void> console(String command) {
+ public CompletableFuture<Void> console(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(manager, null, null, command,
- GdbConsoleExecCommand.Output.CONSOLE)).thenApply(e -> null);
+ GdbConsoleExecCommand.Output.CONSOLE, cwr)).thenApply(e -> null);
}
@Override
- public CompletableFuture<String> consoleCapture(String command) {
+ public CompletableFuture<String> consoleCapture(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(manager, null, null, command,
- GdbConsoleExecCommand.Output.CAPTURE));
+ GdbConsoleExecCommand.Output.CAPTURE, cwr));
}
@Override
@@ -457,7 +467,7 @@ public class GdbInferiorImpl implements GdbInferior {
@Internal
public CompletableFuture<Void> syncEndianness() {
- return consoleCapture("show endian").thenAccept(out -> {
+ return consoleCapture("show endian", CompletesWithRunning.CANNOT).thenAccept(out -> {
if (out.toLowerCase().contains("little endian")) {
endianness = ByteOrder.LITTLE_ENDIAN;
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbManagerImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbManagerImpl.java
index 802cd707f2..51dc8299e4 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbManagerImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbManagerImpl.java
@@ -22,10 +22,12 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
+import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.python.core.PyDictionary;
+import org.python.icu.text.MessageFormat;
import org.python.util.InteractiveConsole;
import agent.gdb.manager.*;
@@ -34,6 +36,7 @@ import agent.gdb.manager.breakpoint.GdbBreakpointInfo;
import agent.gdb.manager.breakpoint.GdbBreakpointType;
import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.cmd.*;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.parsing.GdbMiParser;
import agent.gdb.manager.parsing.GdbParsingUtils.GdbParseError;
import agent.gdb.pty.*;
@@ -43,13 +46,10 @@ 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;
@@ -73,6 +73,15 @@ import sun.misc.SignalHandler;
public class GdbManagerImpl implements GdbManager {
private static final String GDB_IS_TERMINATING = "GDB is terminating";
+ private static final String PTY_DIALOG_MESSAGE_PATTERN =
+ "<html><p>Please enter:</p>" +
+ "<pre>new-ui mi2 <b>{0}</b></pre>" + "" +
+ "<p>into an existing gdb session.</p><br/>" +
+ "<p>Alternatively, to launch a new session, cancel this dialog. " +
+ "Then, retry with <b>use existing session</b> disabled.</p></html>";
+
+ private static final String CANCEL = "Cancel";
+
@Internal
public enum Interpreter {
CLI, MI2;
@@ -142,6 +151,31 @@ public class GdbManagerImpl implements GdbManager {
}
}
+ class PtyInfoDialogThread extends Thread {
+ private final JOptionPane pane;
+ private final JDialog dialog;
+ final CompletableFuture<Integer> result = new CompletableFuture<>();
+
+ public PtyInfoDialogThread(String ptyName) {
+ String message = MessageFormat.format(PTY_DIALOG_MESSAGE_PATTERN, ptyName);
+ pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, 0, null,
+ new Object[] { CANCEL });
+ dialog = pane.createDialog("Waiting for GDB/MI session");
+ }
+
+ @Override
+ public void run() {
+ dialog.setVisible(true);
+ Object sel = pane.getValue();
+ if (CANCEL.equals(sel)) {
+ result.complete(JOptionPane.CANCEL_OPTION);
+ }
+ else {
+ result.complete(JOptionPane.CLOSED_OPTION);
+ }
+ }
+ }
+
private final PtyFactory ptyFactory;
private final AsyncReference<GdbState, GdbCause> state =
@@ -505,13 +539,18 @@ public class GdbManagerImpl implements GdbManager {
return unmodifiableBreakpoints;
}
- private GdbBreakpointInfo addKnownBreakpoint(GdbBreakpointInfo bkpt, boolean expectExisting) {
+ @Internal
+ public Map<Long, GdbBreakpointInfo> getKnownBreakpointsInternal() {
+ return breakpoints;
+ }
+
+ public GdbBreakpointInfo addKnownBreakpoint(GdbBreakpointInfo bkpt, boolean expectExisting) {
GdbBreakpointInfo old = breakpoints.put(bkpt.getNumber(), bkpt);
if (expectExisting && old == null) {
- Msg.warn(this, "Breakpoint " + bkpt.getNumber() + " is not known");
+ Msg.warn(this, "Was missing breakpoint " + bkpt.getNumber());
}
else if (!expectExisting && old != null) {
- Msg.warn(this, "Breakpoint " + bkpt.getNumber() + " is already known");
+ Msg.warn(this, "Already had breakpoint " + bkpt.getNumber());
}
return old;
}
@@ -524,10 +563,10 @@ public class GdbManagerImpl implements GdbManager {
return info;
}
- private GdbBreakpointInfo removeKnownBreakpoint(long number) {
+ public GdbBreakpointInfo removeKnownBreakpoint(long number) {
GdbBreakpointInfo del = breakpoints.remove(number);
if (del == null) {
- Msg.warn(this, "Breakpoint " + number + " is not known");
+ Msg.warn(this, "Deleted missing breakpoint " + number);
}
return del;
}
@@ -640,14 +679,28 @@ public class GdbManagerImpl implements GdbManager {
mi2Thread.start();
- int choice = JOptionPane.showConfirmDialog(null,
- "Please enter \"new-ui mi2 " + mi2PtyName + "\" in an existing gdb session. " +
- "Alternatively, disable 'use existing session' to launch a new session.",
- "Waiting for GDB/MI session", JOptionPane.OK_CANCEL_OPTION);
- if (choice == JOptionPane.CANCEL_OPTION) {
+ PtyInfoDialogThread dialog = new PtyInfoDialogThread(mi2PtyName);
+ dialog.start();
+ dialog.result.thenAccept(choice -> {
+ if (choice == JOptionPane.CANCEL_OPTION) {
+ mi2Thread.hasWriter.cancel(false);
+ // This will cause
+ }
+ });
+
+ // Yes, wait on the user indefinitely.
+ try {
+ mi2Thread.hasWriter.get();
+ }
+ catch (InterruptedException | ExecutionException e) {
+ Msg.info(this, "The user cancelled, or something else: " + e);
terminate();
}
+ dialog.dialog.setVisible(false);
}
+
+ // Do this whether or not joining existing. It's possible .gdbinit did stuff.
+ resync();
}
@Override
@@ -664,6 +717,25 @@ public class GdbManagerImpl implements GdbManager {
return AsyncUtils.NIL;
}
+ protected void resync() {
+ AsyncFence fence = new AsyncFence();
+ fence.include(listInferiors().thenCompose(infs -> {
+ AsyncFence inner = new AsyncFence();
+ for (GdbInferior inf : infs.values()) {
+ // NOTE: Mappings need not be constantly synced
+ // NOTE: Modules need not be constantly synced
+ inner.include(inf.listThreads());
+ }
+ return inner.ready();
+ }));
+ fence.include(listBreakpoints());
+ // NOTE: Available processes need not be constantly synced
+ fence.ready().exceptionally(ex -> {
+ Msg.error(this, "Could not resync the GDB session: " + ex);
+ return null;
+ });
+ }
+
private void waitGdbExit() {
try {
int exitcode = gdb.waitExited();
@@ -1043,7 +1115,11 @@ public class GdbManagerImpl implements GdbManager {
int iid = evt.getInferiorId();
GdbInferiorImpl inf = getInferior(iid);
inf.setPid(evt.getPid());
- event(() -> listenersEvent.fire.inferiorStarted(inf, evt.getCause()), "inferiorStarted");
+ fireInferiorStarted(inf, evt.getCause(), "inferiorStarted");
+ }
+
+ public void fireInferiorStarted(GdbInferiorImpl inf, GdbCause cause, String text) {
+ event(() -> listenersEvent.fire.inferiorStarted(inf, cause), text);
}
/**
@@ -1567,7 +1643,7 @@ public class GdbManagerImpl implements GdbManager {
sendInterruptNow(cliThread, (((char) 3) + "interrupt" + newLine).getBytes());
}
else if (mi2Thread != null) {
- sendInterruptNow(mi2Thread, new byte[] { 3 });
+ sendInterruptNow(mi2Thread, (((char) 3) + "-exec-interrupt" + newLine).getBytes());
}
}
@@ -1600,6 +1676,7 @@ public class GdbManagerImpl implements GdbManager {
}
@Override
+ @Deprecated
public CompletableFuture<Void> claimStopped() {
return execute(new GdbClaimStopped(this));
}
@@ -1641,15 +1718,15 @@ public class GdbManagerImpl implements GdbManager {
}
@Override
- public CompletableFuture<Void> console(String command) {
+ public CompletableFuture<Void> console(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(this, null, null, command,
- GdbConsoleExecCommand.Output.CONSOLE)).thenApply(e -> null);
+ GdbConsoleExecCommand.Output.CONSOLE, cwr)).thenApply(e -> null);
}
@Override
- public CompletableFuture<String> consoleCapture(String command) {
+ public CompletableFuture<String> consoleCapture(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(this, null, null, command,
- GdbConsoleExecCommand.Output.CAPTURE));
+ GdbConsoleExecCommand.Output.CAPTURE, cwr));
}
@Override
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbModuleImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbModuleImpl.java
index 4d644f3293..1a46e062f1 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbModuleImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbModuleImpl.java
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
import agent.gdb.manager.GdbModule;
import agent.gdb.manager.GdbModuleSection;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import ghidra.async.AsyncLazyValue;
import ghidra.async.AsyncUtils;
import ghidra.util.MathUtilities;
@@ -138,7 +139,7 @@ public class GdbModuleImpl implements GdbModule {
// TODO: Apparently, this is using internal GDB-debugging commands....
// TODO: Also make methods for "full" symbols (DWARF?)
String cmd = "maintenance print msymbols -objfile " + name;
- return inferior.consoleCapture(cmd).thenApply(out -> {
+ return inferior.consoleCapture(cmd, CompletesWithRunning.CANNOT).thenApply(out -> {
Map<String, GdbMinimalSymbol> result = new LinkedHashMap<>();
for (String line : out.split("\n")) {
Matcher mat = MSYMBOL_LINE_PATTERN.matcher(line);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbStackFrameImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbStackFrameImpl.java
index 0905b4fdf1..604e61246b 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbStackFrameImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbStackFrameImpl.java
@@ -23,6 +23,7 @@ import java.util.concurrent.CompletableFuture;
import agent.gdb.manager.GdbRegister;
import agent.gdb.manager.GdbStackFrame;
import agent.gdb.manager.impl.cmd.*;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.parsing.GdbMiParser.GdbMiFieldList;
import agent.gdb.manager.parsing.GdbParsingUtils;
@@ -129,14 +130,14 @@ public class GdbStackFrameImpl implements GdbStackFrame {
}
@Override
- public CompletableFuture<Void> console(String command) {
+ public CompletableFuture<Void> console(String command, CompletesWithRunning cwr) {
return manager.execute(new GdbConsoleExecCommand(manager, thread.getId(), level, command,
- GdbConsoleExecCommand.Output.CONSOLE)).thenApply(e -> null);
+ GdbConsoleExecCommand.Output.CONSOLE, cwr)).thenApply(e -> null);
}
@Override
- public CompletableFuture<String> consoleCapture(String command) {
+ public CompletableFuture<String> consoleCapture(String command, CompletesWithRunning cwr) {
return manager.execute(new GdbConsoleExecCommand(manager, thread.getId(), level, command,
- GdbConsoleExecCommand.Output.CAPTURE));
+ GdbConsoleExecCommand.Output.CAPTURE, cwr));
}
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbThreadImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbThreadImpl.java
index 56767b9f3f..c194b8999f 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbThreadImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/GdbThreadImpl.java
@@ -30,6 +30,7 @@ import agent.gdb.manager.GdbManager.StepCmd;
import agent.gdb.manager.breakpoint.GdbBreakpointInfo;
import agent.gdb.manager.breakpoint.GdbBreakpointType;
import agent.gdb.manager.impl.cmd.*;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.parsing.GdbCValueParser;
import agent.gdb.manager.parsing.GdbParsingUtils.GdbParseError;
import agent.gdb.manager.reason.GdbReason;
@@ -232,15 +233,15 @@ public class GdbThreadImpl implements GdbThread {
}
@Override
- public CompletableFuture<Void> console(String command) {
+ public CompletableFuture<Void> console(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(manager, id, null, command,
- GdbConsoleExecCommand.Output.CONSOLE)).thenApply(e -> null);
+ GdbConsoleExecCommand.Output.CONSOLE, cwr)).thenApply(e -> null);
}
@Override
- public CompletableFuture<String> consoleCapture(String command) {
+ public CompletableFuture<String> consoleCapture(String command, CompletesWithRunning cwr) {
return execute(new GdbConsoleExecCommand(manager, id, null, command,
- GdbConsoleExecCommand.Output.CAPTURE));
+ GdbConsoleExecCommand.Output.CAPTURE, cwr));
}
@Override
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/AbstractGdbCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/AbstractGdbCommand.java
index f427f59612..f301294fba 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/AbstractGdbCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/AbstractGdbCommand.java
@@ -16,8 +16,7 @@
package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbState;
-import agent.gdb.manager.evt.GdbCommandErrorEvent;
-import agent.gdb.manager.evt.GdbConsoleOutputEvent;
+import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.impl.GdbManagerImpl.Interpreter;
import agent.gdb.manager.parsing.GdbParsingUtils.GdbParseError;
@@ -58,6 +57,7 @@ public abstract class AbstractGdbCommand<T> implements GdbCommand<T> {
/**
* {@inheritDoc}
*
+ * <p>
* Selects mi2 by default. Check {@link GdbManagerImpl#hasCli()} before selecting the
* command-line (console) interface.
*/
@@ -97,6 +97,25 @@ public abstract class AbstractGdbCommand<T> implements GdbCommand<T> {
return evt;
}
+ @Override
+ public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
+ /**
+ * Unfortunately, GDB prints {@code ^running} even if the command causing that result is
+ * issued from the CLI. This is a problem when "using an existing session," because the user
+ * will likely type "start" into the existing CLI. Thus, we have to be careful not to let
+ * spurious {@code ^running} command-completion events actually complete any command, except
+ * ones where we expect that result. This seems a bug in GDB to me.
+ */
+ if (evt instanceof GdbCommandRunningEvent) {
+ return false;
+ }
+ if (evt instanceof AbstractGdbCompletedCommandEvent) {
+ pending.claim(evt);
+ return true;
+ }
+ return false;
+ }
+
@Override
public Integer impliesCurrentThreadId() {
return null;
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAddInferiorCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAddInferiorCommand.java
index 4f384350ac..48321868b4 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAddInferiorCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAddInferiorCommand.java
@@ -17,9 +17,9 @@ package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbInferior;
import agent.gdb.manager.GdbManager;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbManager#addInferior()}
@@ -34,15 +34,6 @@ public class GdbAddInferiorCommand extends AbstractGdbCommand<GdbInferior> {
return "-add-inferior";
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public GdbInferior complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAttachCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAttachCommand.java
index 0194439c66..956f10e642 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAttachCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbAttachCommand.java
@@ -20,7 +20,8 @@ import java.util.Set;
import agent.gdb.manager.GdbInferior;
import agent.gdb.manager.GdbThread;
-import agent.gdb.manager.evt.*;
+import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.evt.GdbThreadCreatedEvent;
import agent.gdb.manager.impl.*;
/**
@@ -42,8 +43,7 @@ public class GdbAttachCommand extends AbstractGdbCommand<Set<GdbThread>> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbThreadCreatedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbClaimStopped.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbClaimStopped.java
index e9aa2a0d6b..f8bd806981 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbClaimStopped.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbClaimStopped.java
@@ -22,7 +22,10 @@ import agent.gdb.manager.impl.*;
/**
* Implementation of {@link GdbManager#claimStopped()}
+ *
+ * @deprecated I don't see this being used anywhere. Probably defunct.
*/
+@Deprecated
public class GdbClaimStopped extends AbstractGdbCommand<Void> {
public GdbClaimStopped(GdbManagerImpl manager) {
super(manager);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbConsoleExecCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbConsoleExecCommand.java
index 55a18846d1..e411c2f4ba 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbConsoleExecCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbConsoleExecCommand.java
@@ -19,8 +19,7 @@ import org.apache.commons.text.StringEscapeUtils;
import agent.gdb.manager.GdbManager;
import agent.gdb.manager.GdbManager.Channel;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
-import agent.gdb.manager.evt.GdbConsoleOutputEvent;
+import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.impl.GdbManagerImpl.Interpreter;
@@ -28,18 +27,64 @@ import agent.gdb.manager.impl.GdbManagerImpl.Interpreter;
* Implementation of {@link GdbManager#console(String)} and similar
*/
public class GdbConsoleExecCommand extends AbstractGdbCommandWithThreadAndFrameId<String> {
+ public enum CompletesWithRunning {
+ /**
+ * Ignore {@code ^running} events, because they cannot complete this command
+ */
+ CANNOT(AbstractGdbCompletedCommandEvent.class) {
+ @Override
+ boolean handleRunning(GdbCommandRunningEvent evt, GdbPendingCommand<?> pending) {
+ return false;
+ }
+ },
+ /**
+ * Allow any completion, including a {@code ^running} event, to complete this command
+ *
+ * <p>
+ * Use this when the nature of the command is unknown, e.g., when it was input by the user.
+ */
+ CAN(AbstractGdbCompletedCommandEvent.class) {
+ @Override
+ boolean handleRunning(GdbCommandRunningEvent evt, GdbPendingCommand<?> pending) {
+ pending.claim(evt);
+ return true;
+ }
+ },
+ /**
+ * Require completion by a {@code ^running} event
+ */
+ MUST(GdbCommandRunningEvent.class) {
+ @Override
+ boolean handleRunning(GdbCommandRunningEvent evt, GdbPendingCommand<?> pending) {
+ pending.claim(evt);
+ return true;
+ }
+ };
+
+ private final Class<? extends AbstractGdbCompletedCommandEvent> completionClass;
+
+ private CompletesWithRunning(
+ Class<? extends AbstractGdbCompletedCommandEvent> completionClass) {
+ this.completionClass = completionClass;
+ }
+
+ abstract boolean handleRunning(GdbCommandRunningEvent evt, GdbPendingCommand<?> pending);
+ }
+
public enum Output {
CONSOLE, CAPTURE;
}
- private String command;
- private Output to;
+ private final String command;
+ private final Output to;
+ private final CompletesWithRunning cwr;
public GdbConsoleExecCommand(GdbManagerImpl manager, Integer threadId, Integer frameId,
- String command, Output to) {
+ String command, Output to, CompletesWithRunning cwr) {
super(manager, threadId, frameId);
this.command = command;
this.to = to;
+ this.cwr = cwr;
}
/**
@@ -80,7 +125,10 @@ public class GdbConsoleExecCommand extends AbstractGdbCommandWithThreadAndFrameI
return false;
}
// MI2
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
+ if (evt instanceof GdbCommandRunningEvent) {
+ return cwr.handleRunning((GdbCommandRunningEvent) evt, pending);
+ }
+ else if (evt instanceof AbstractGdbCompletedCommandEvent) {
pending.claim(evt);
return true;
}
@@ -109,7 +157,7 @@ public class GdbConsoleExecCommand extends AbstractGdbCommandWithThreadAndFrameI
return null;
}
// MI2
- pending.checkCompletion(AbstractGdbCompletedCommandEvent.class);
+ pending.checkCompletion(cwr.completionClass);
if (to == Output.CONSOLE) {
return null;
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDeleteBreakpointsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDeleteBreakpointsCommand.java
index 041be2fdba..8841926515 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDeleteBreakpointsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDeleteBreakpointsCommand.java
@@ -18,7 +18,7 @@ package agent.gdb.manager.impl.cmd;
import org.apache.commons.lang3.StringUtils;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
+import agent.gdb.manager.evt.GdbBreakpointDeletedEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
@@ -41,10 +41,12 @@ public class GdbDeleteBreakpointsCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
+ if (evt instanceof GdbBreakpointDeletedEvent) {
+ pending.claim(evt);
+ }
return false;
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDetachCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDetachCommand.java
index 77cc059491..9425d6de17 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDetachCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDetachCommand.java
@@ -40,8 +40,7 @@ public class GdbDetachCommand extends AbstractGdbCommandWithThreadId<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbThreadExitedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDisableBreakpointsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDisableBreakpointsCommand.java
index ff5b9dae82..8b5b0df363 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDisableBreakpointsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbDisableBreakpointsCommand.java
@@ -18,8 +18,7 @@ package agent.gdb.manager.impl.cmd;
import org.apache.commons.lang3.StringUtils;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
-import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.*;
/**
@@ -41,10 +40,12 @@ public class GdbDisableBreakpointsCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
+ if (evt instanceof GdbBreakpointModifiedEvent) {
+ pending.claim(evt);
+ }
return false;
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEnableBreakpointsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEnableBreakpointsCommand.java
index 5edcc9a03d..fff2408803 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEnableBreakpointsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEnableBreakpointsCommand.java
@@ -18,8 +18,7 @@ package agent.gdb.manager.impl.cmd;
import org.apache.commons.lang3.StringUtils;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
-import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.*;
/**
@@ -41,10 +40,12 @@ public class GdbEnableBreakpointsCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
+ if (evt instanceof GdbBreakpointModifiedEvent) {
+ pending.claim(evt);
+ }
return false;
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEvaluateCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEvaluateCommand.java
index 5a8dcf8428..98f91e0ffc 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEvaluateCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbEvaluateCommand.java
@@ -18,9 +18,9 @@ package agent.gdb.manager.impl.cmd;
import org.apache.commons.text.StringEscapeUtils;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbInferior#evaluate(String)}
@@ -40,15 +40,6 @@ public class GdbEvaluateCommand extends AbstractGdbCommandWithThreadAndFrameId<S
StringEscapeUtils.escapeJava(expression) + '"';
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public String complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbFileExecAndSymbolsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbFileExecAndSymbolsCommand.java
index f57c2e49fe..a251030aef 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbFileExecAndSymbolsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbFileExecAndSymbolsCommand.java
@@ -16,9 +16,9 @@
package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbInferior#fileExecAndSymbols(String)}
@@ -37,15 +37,6 @@ public class GdbFileExecAndSymbolsCommand extends AbstractGdbCommand<Void> {
return "-file-exec-and-symbols " + file;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Void complete(GdbPendingCommand<?> pending) {
pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetThreadInfoCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetThreadInfoCommand.java
index ca3152cd9a..c1f055d442 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetThreadInfoCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetThreadInfoCommand.java
@@ -17,7 +17,6 @@ package agent.gdb.manager.impl.cmd;
import java.util.List;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.parsing.GdbMiParser.GdbMiFieldList;
@@ -41,15 +40,6 @@ public class GdbGetThreadInfoCommand extends AbstractGdbCommandWithThreadId<GdbT
return null;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public GdbThreadInfo complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetVarCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetVarCommand.java
index 50c3a9c809..514dbee907 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetVarCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbGetVarCommand.java
@@ -16,9 +16,9 @@
package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbInferior#getVar(String)}
@@ -36,15 +36,6 @@ public class GdbGetVarCommand extends AbstractGdbCommand<String> {
return "-gdb-show " + varName;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public String complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInferiorSelectCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInferiorSelectCommand.java
index b0176578d1..27ffdb932a 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInferiorSelectCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInferiorSelectCommand.java
@@ -15,7 +15,8 @@
*/
package agent.gdb.manager.impl.cmd;
-import agent.gdb.manager.evt.*;
+import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.evt.GdbThreadSelectedEvent;
import agent.gdb.manager.impl.*;
public class GdbInferiorSelectCommand extends AbstractGdbCommand<Void> {
@@ -45,8 +46,7 @@ public class GdbInferiorSelectCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
if (evt instanceof GdbThreadSelectedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInfoOsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInfoOsCommand.java
index a307cf5e3c..482be4cf05 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInfoOsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInfoOsCommand.java
@@ -17,9 +17,9 @@ package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbManager;
import agent.gdb.manager.GdbTable;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbManager#infoOs(String)}
@@ -37,15 +37,6 @@ public class GdbInfoOsCommand extends AbstractGdbCommand<GdbTable> {
return "-info-os " + type;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public GdbTable complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInsertBreakpointCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInsertBreakpointCommand.java
index 6f88e521ef..5d8d35d60b 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInsertBreakpointCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInsertBreakpointCommand.java
@@ -72,8 +72,7 @@ public class GdbInsertBreakpointCommand extends AbstractGdbCommandWithThreadId<G
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbBreakpointCreatedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInterruptCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInterruptCommand.java
index e30959181b..4591b32060 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInterruptCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbInterruptCommand.java
@@ -17,7 +17,6 @@ package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbManager;
import agent.gdb.manager.GdbState;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbStoppedEvent;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.impl.GdbManagerImpl.Interpreter;
@@ -58,8 +57,7 @@ public class GdbInterruptCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbStoppedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbKillCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbKillCommand.java
index 3e0eb51a34..1e0461bac7 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbKillCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbKillCommand.java
@@ -35,8 +35,7 @@ public class GdbKillCommand extends AbstractGdbCommandWithThreadId<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbThreadExitedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListAvailableProcessesCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListAvailableProcessesCommand.java
index 7dc4371684..446555fdd4 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListAvailableProcessesCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListAvailableProcessesCommand.java
@@ -18,9 +18,9 @@ package agent.gdb.manager.impl.cmd;
import java.util.List;
import agent.gdb.manager.GdbProcessThreadGroup;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
public class GdbListAvailableProcessesCommand
extends AbstractGdbCommand<List<GdbProcessThreadGroup>> {
@@ -33,15 +33,6 @@ public class GdbListAvailableProcessesCommand
return "-list-thread-groups --available";
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public List<GdbProcessThreadGroup> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListBreakpointsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListBreakpointsCommand.java
index d08a7696cb..3249ab5580 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListBreakpointsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListBreakpointsCommand.java
@@ -17,13 +17,15 @@ package agent.gdb.manager.impl.cmd;
import java.util.*;
+import agent.gdb.manager.GdbCause.Causes;
import agent.gdb.manager.GdbInferior;
import agent.gdb.manager.breakpoint.GdbBreakpointInfo;
import agent.gdb.manager.breakpoint.GdbBreakpointLocation;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
import agent.gdb.manager.parsing.GdbMiParser.GdbMiFieldList;
+import ghidra.util.Msg;
/**
* Implementation of {@link GdbInferior#listBreakpoints()}
@@ -40,15 +42,6 @@ public class GdbListBreakpointsCommand
return "-break-list" + threadPart;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Map<Long, GdbBreakpointInfo> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
@@ -56,13 +49,34 @@ public class GdbListBreakpointsCommand
// Also, there are some bonus fields that don't appear in cells....
GdbMiFieldList tbl = done.assumeBreakpointTable();
GdbMiFieldList body = tbl.getFieldList("body");
- Map<Long, GdbBreakpointInfo> list = new LinkedHashMap<>();
+ Set<Long> nums = new HashSet<>();
+ Map<Long, GdbBreakpointInfo> allBreakpoints = manager.getKnownBreakpointsInternal();
List<GdbBreakpointLocation> allLocs = GdbBreakpointInfo.parseLocations(body);
for (Object bkpt : body.get("bkpt")) {
GdbBreakpointInfo info =
GdbBreakpointInfo.parseBkpt((GdbMiFieldList) bkpt, allLocs, null);
- list.put(info.getNumber(), info);
+ nums.add(info.getNumber());
+ GdbBreakpointInfo exists = allBreakpoints.get(info.getNumber());
+ if (exists != null) {
+ if (!exists.equals(info)) {
+ // Need to update as if =breakpoint-modified
+ Msg.warn(this, "Resync: Missed breakpoint modification: " + info);
+ manager.doBreakpointModified(info, Causes.UNCLAIMED);
+ }
+ continue;
+ }
+ // Need to add as if =breakpoint-created
+ Msg.warn(this, "Resync: Was missing breakpoint: " + info);
+ manager.doBreakpointCreated(info, Causes.UNCLAIMED);
+ }
+ for (long num : new ArrayList<>(manager.getKnownBreakpoints().keySet())) {
+ if (nums.contains(num)) {
+ continue; // Do nothing, we're in sync
+ }
+ // Need to remove as if =breakpoint-deleted
+ Msg.warn(this, "Resync: Had extra breakpoint: " + num);
+ manager.doBreakpointDeleted(num, Causes.UNCLAIMED);
}
- return list;
+ return manager.getKnownBreakpoints();
}
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListInferiorsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListInferiorsCommand.java
index abd7fcd1cd..7865b8a079 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListInferiorsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListInferiorsCommand.java
@@ -19,7 +19,6 @@ import java.util.*;
import agent.gdb.manager.*;
import agent.gdb.manager.GdbCause.Causes;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
import ghidra.util.Msg;
@@ -37,15 +36,6 @@ public class GdbListInferiorsCommand extends AbstractGdbCommand<Map<Integer, Gdb
return "-list-thread-groups";
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Map<Integer, GdbInferior> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListRegisterNamesCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListRegisterNamesCommand.java
index a4bc81d746..7097d1eae2 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListRegisterNamesCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListRegisterNamesCommand.java
@@ -18,9 +18,9 @@ package agent.gdb.manager.impl.cmd;
import java.util.List;
import agent.gdb.manager.GdbThread;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbThread#listRegisters()}
@@ -36,15 +36,6 @@ public class GdbListRegisterNamesCommand extends AbstractGdbCommandWithThreadId<
return "-data-list-register-names" + threadPart;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public List<String> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListThreadsCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListThreadsCommand.java
index 8630c1f672..5446176a34 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListThreadsCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbListThreadsCommand.java
@@ -18,7 +18,6 @@ package agent.gdb.manager.impl.cmd;
import java.util.*;
import agent.gdb.manager.GdbThread;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
import ghidra.util.Msg;
@@ -36,15 +35,6 @@ public class GdbListThreadsCommand extends AbstractGdbCommand<Map<Integer, GdbTh
return "-list-thread-groups i" + inferior.getId();
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Map<Integer, GdbThread> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadMemoryCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadMemoryCommand.java
index b0e1eb377f..36014a94fe 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadMemoryCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadMemoryCommand.java
@@ -21,11 +21,11 @@ import java.util.List;
import com.google.common.collect.*;
import agent.gdb.manager.GdbThread;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
-import agent.gdb.manager.parsing.GdbParsingUtils;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
import agent.gdb.manager.parsing.GdbMiParser.GdbMiFieldList;
+import agent.gdb.manager.parsing.GdbParsingUtils;
import ghidra.util.Msg;
import ghidra.util.NumericUtilities;
@@ -51,15 +51,6 @@ public class GdbReadMemoryCommand extends AbstractGdbCommandWithThreadId<RangeSe
return "-data-read-memory-bytes" + threadPart + " 0x" + Long.toHexString(addr) + " " + len;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public RangeSet<Long> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadRegistersCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadRegistersCommand.java
index acd5940f85..a323fcf157 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadRegistersCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbReadRegistersCommand.java
@@ -22,9 +22,8 @@ import java.util.*;
import java.util.stream.Collectors;
import agent.gdb.manager.GdbRegister;
-import agent.gdb.manager.GdbStackFrameOperations;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
-import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.GdbContextualOperations;
+import agent.gdb.manager.evt.*;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.parsing.GdbCValueParser;
import agent.gdb.manager.parsing.GdbCValueParser.*;
@@ -34,7 +33,7 @@ import ghidra.pcode.utils.Utils;
import ghidra.util.Msg;
/**
- * Implementation of {@link GdbStackFrameOperations#readRegisters(Set)}
+ * Implementation of {@link GdbContextualOperations#readRegisters(Set)}
*/
public class GdbReadRegistersCommand
extends AbstractGdbCommandWithThreadAndFrameId<Map<GdbRegister, BigInteger>> {
@@ -69,15 +68,6 @@ public class GdbReadRegistersCommand
return b.toString();
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
protected BigInteger packElements(GdbArrayValue av, int byteCount, int bytesPer,
ByteOrder endianness) {
assert bytesPer * av.size() == byteCount;
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbRemoveInferiorCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbRemoveInferiorCommand.java
index d29ccc02ec..5804940175 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbRemoveInferiorCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbRemoveInferiorCommand.java
@@ -15,7 +15,8 @@
*/
package agent.gdb.manager.impl.cmd;
-import agent.gdb.manager.evt.*;
+import agent.gdb.manager.evt.GdbCommandDoneEvent;
+import agent.gdb.manager.evt.GdbThreadGroupRemovedEvent;
import agent.gdb.manager.impl.*;
public class GdbRemoveInferiorCommand extends AbstractGdbCommand<Void> {
@@ -34,8 +35,7 @@ public class GdbRemoveInferiorCommand extends AbstractGdbCommand<Void> {
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
if (evt instanceof GdbThreadGroupRemovedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetActiveThreadCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetActiveThreadCommand.java
index 257c65b3c1..754eb38941 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetActiveThreadCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetActiveThreadCommand.java
@@ -51,8 +51,7 @@ public class GdbSetActiveThreadCommand extends AbstractGdbCommandWithThreadAndFr
@Override
public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
+ if (super.handle(evt, pending)) {
return true;
}
else if (evt instanceof GdbThreadSelectedEvent) {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetInferiorTtyCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetInferiorTtyCommand.java
index 835348d49b..e8986cf082 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetInferiorTtyCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetInferiorTtyCommand.java
@@ -16,9 +16,9 @@
package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbInferior#setTty(String)}
@@ -36,15 +36,6 @@ public class GdbSetInferiorTtyCommand extends AbstractGdbCommand<Void> {
return "-inferior-tty-set " + tty;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Void complete(GdbPendingCommand<?> pending) {
pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetVarCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetVarCommand.java
index 5c30766fbf..c2f38606e0 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetVarCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbSetVarCommand.java
@@ -16,9 +16,9 @@
package agent.gdb.manager.impl.cmd;
import agent.gdb.manager.GdbInferior;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbInferior#setVar(String, String)}
@@ -38,15 +38,6 @@ public class GdbSetVarCommand extends AbstractGdbCommandWithThreadId<Void> {
return "-gdb-set" + threadPart + " " + varName + " " + val;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Void complete(GdbPendingCommand<?> pending) {
pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbStackListFramesCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbStackListFramesCommand.java
index bab1a58bc2..a025b59535 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbStackListFramesCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbStackListFramesCommand.java
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import agent.gdb.manager.GdbStackFrame;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
import agent.gdb.manager.parsing.GdbMiParser.GdbMiFieldList;
@@ -37,15 +36,6 @@ public class GdbStackListFramesCommand extends AbstractGdbCommandWithThreadId<Li
return "-stack-list-frames" + threadPart;
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public List<GdbStackFrame> complete(GdbPendingCommand<?> pending) {
GdbCommandDoneEvent done = pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteMemoryCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteMemoryCommand.java
index 33644cb65d..4800d3bc8b 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteMemoryCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteMemoryCommand.java
@@ -18,9 +18,9 @@ package agent.gdb.manager.impl.cmd;
import java.nio.ByteBuffer;
import agent.gdb.manager.GdbThread;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
-import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.GdbManagerImpl;
+import agent.gdb.manager.impl.GdbPendingCommand;
/**
* Implementation of {@link GdbThread#writeMemory(long, ByteBuffer, int)}
@@ -58,15 +58,6 @@ public class GdbWriteMemoryCommand extends AbstractGdbCommandWithThreadId<Void>
return b.toString();
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Void complete(GdbPendingCommand<?> pending) {
pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteRegistersCommand.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteRegistersCommand.java
index 58cfeffe7b..3617e20ed7 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteRegistersCommand.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/manager/impl/cmd/GdbWriteRegistersCommand.java
@@ -22,14 +22,13 @@ import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import agent.gdb.manager.GdbRegister;
-import agent.gdb.manager.GdbStackFrameOperations;
-import agent.gdb.manager.evt.AbstractGdbCompletedCommandEvent;
+import agent.gdb.manager.GdbContextualOperations;
import agent.gdb.manager.evt.GdbCommandDoneEvent;
import agent.gdb.manager.impl.*;
import ghidra.dbg.util.ConversionUtils;
/**
- * Implementation of {@link GdbStackFrameOperations#writeRegisters(Map)}
+ * Implementation of {@link GdbContextualOperations#writeRegisters(Map)}
*/
public class GdbWriteRegistersCommand extends AbstractGdbCommandWithThreadAndFrameId<Void> {
protected static final BigInteger UINT128_MAX =
@@ -123,15 +122,6 @@ public class GdbWriteRegistersCommand extends AbstractGdbCommandWithThreadAndFra
return b.toString();
}
- @Override
- public boolean handle(GdbEvent<?> evt, GdbPendingCommand<?> pending) {
- if (evt instanceof AbstractGdbCompletedCommandEvent) {
- pending.claim(evt);
- return true;
- }
- return false;
- }
-
@Override
public Void complete(GdbPendingCommand<?> pending) {
pending.checkCompletion(GdbCommandDoneEvent.class);
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelImpl.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelImpl.java
index 631bf2d4c2..60e7aa85eb 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelImpl.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelImpl.java
@@ -139,14 +139,16 @@ public class GdbModelImpl extends AbstractDebuggerObjectModel {
}
public CompletableFuture<Void> startGDB(String gdbCmd, String[] args) {
- try {
- gdb.start(gdbCmd, args);
+ return CompletableFuture.runAsync(() -> {
+ try {
+ gdb.start(gdbCmd, args);
+ }
+ catch (IOException e) {
+ throw new DebuggerModelTerminatingException("Error while starting GDB", e);
+ }
+ }).thenCompose(__ -> {
return gdb.runRC();
- }
- catch (IOException e) {
- return CompletableFuture.failedFuture(
- new DebuggerModelTerminatingException("Error while starting GDB", e));
- }
+ });
}
public void consoleLoop() throws IOException {
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetEnvironment.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetEnvironment.java
index a46590d8d4..dc9f0fd6ed 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetEnvironment.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetEnvironment.java
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import ghidra.async.AsyncFence;
import ghidra.dbg.agent.DefaultTargetObject;
import ghidra.dbg.target.TargetEnvironment;
@@ -83,7 +84,7 @@ public class GdbModelTargetEnvironment
* --thread parameter.
*/
return CompletableFuture.supplyAsync(() -> null).thenCompose(__ -> {
- return impl.gdb.consoleCapture("show architecture");
+ return impl.gdb.consoleCapture("show architecture", CompletesWithRunning.CANNOT);
}).thenAccept(out -> {
String[] tokens = out.split("\\s+");
String arch = tokens[tokens.length - 1].trim();
@@ -116,7 +117,7 @@ public class GdbModelTargetEnvironment
* TODO: Ditto the "current inferior" issue as refreshArchitecture
*/
return CompletableFuture.supplyAsync(() -> null).thenCompose(__ -> {
- return impl.gdb.consoleCapture("show os");
+ return impl.gdb.consoleCapture("show os", CompletesWithRunning.CANNOT);
}).thenAccept(out -> {
String[] tokens = out.split("\n")[0].split("\\s+");
String os = tokens[tokens.length - 1].trim();
@@ -145,7 +146,7 @@ public class GdbModelTargetEnvironment
protected CompletableFuture<Void> refreshEndian() {
// TODO: This duplicates GdbInferiorImpl.syncEndianness....
return CompletableFuture.supplyAsync(() -> null).thenCompose(__ -> {
- return impl.gdb.consoleCapture("show endian");
+ return impl.gdb.consoleCapture("show endian", CompletesWithRunning.CANNOT);
}).thenAccept(out -> {
if (out.toLowerCase().contains("little endian")) {
endian = "little";
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetInferior.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetInferior.java
index bc850f5a18..fa6a1a990a 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetInferior.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetInferior.java
@@ -21,6 +21,7 @@ import java.util.concurrent.CompletableFuture;
import agent.gdb.manager.*;
import agent.gdb.manager.GdbManager.StepCmd;
import agent.gdb.manager.impl.cmd.GdbStateChangeRecord;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.reason.*;
import ghidra.async.AsyncFence;
import ghidra.dbg.agent.DefaultTargetObject;
@@ -104,7 +105,8 @@ public class GdbModelTargetInferior
this.threads = new GdbModelTargetThreadContainer(this);
this.breakpoints = new GdbModelTargetBreakpointLocationContainer(this);
- this.realState = TargetExecutionState.INACTIVE;
+ this.realState =
+ inferior.getPid() == null ? TargetExecutionState.INACTIVE : TargetExecutionState.ALIVE;
changeAttributes(List.of(), //
List.of( //
@@ -215,7 +217,7 @@ public class GdbModelTargetInferior
throw new UnsupportedOperationException(kind.name());
case ADVANCE: // Why no exec-advance in GDB/MI?
// TODO: This doesn't work, since advance requires a parameter
- return model.gateFuture(inferior.console("advance"));
+ return model.gateFuture(inferior.console("advance", CompletesWithRunning.MUST));
default:
return model.gateFuture(inferior.step(convertToGdb(kind)));
}
@@ -260,8 +262,9 @@ public class GdbModelTargetInferior
Map.entry(DISPLAY_ATTRIBUTE_NAME, updateDisplay())),
"Refresh on started");*/
AsyncFence fence = new AsyncFence();
- //fence.include(modules.refreshInternal());
- //fence.include(registers.refreshInternal());
+ fence.include(memory.refreshInternal()); // In case of resync
+ fence.include(modules.refreshInternal());
+ fence.include(threads.refreshInternal()); // In case of resync
fence.include(environment.refreshInternal());
fence.include(impl.gdb.listInferiors()); // HACK to update inferior.getExecutable()
return fence.ready().thenAccept(__ -> {
@@ -279,6 +282,9 @@ public class GdbModelTargetInferior
"Refresh on initial break");
}
else {
+ if (!realState.isAlive()) {
+ realState = TargetExecutionState.ALIVE;
+ }
changeAttributes(List.of(), Map.ofEntries(
Map.entry(STATE_ATTRIBUTE_NAME, state = realState),
Map.entry(PID_ATTRIBUTE_NAME, p),
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetModuleContainer.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetModuleContainer.java
index faad546fb0..8ddf366ea0 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetModuleContainer.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetModuleContainer.java
@@ -127,7 +127,7 @@ public class GdbModelTargetModuleContainer
return (GdbModelTargetModule) impl.getModelObject(name);
}
- public CompletableFuture<?> refreshInternal() {
+ protected CompletableFuture<?> refreshInternal() {
return doRefresh().exceptionally(ex -> {
impl.reportError(this, "Problem refreshing inferior's modules", ex);
return null;
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetProcessMemory.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetProcessMemory.java
index ba720bc886..5ed6e700f2 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetProcessMemory.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetProcessMemory.java
@@ -100,8 +100,12 @@ public class GdbModelTargetProcessMemory
}
@Override
- public CompletableFuture<Void> requestElements(boolean refresh) {
+ protected CompletableFuture<Void> requestElements(boolean refresh) {
// Can't use refresh getKnownMappings is only populated by listMappings
+ return doRefresh();
+ }
+
+ protected CompletableFuture<Void> doRefresh() {
if (inferior.getPid() == null) {
setElements(List.of(), "Refreshed (while no process)");
return AsyncUtils.NIL;
@@ -184,7 +188,7 @@ public class GdbModelTargetProcessMemory
// TODO: Seems this is only called when sco.getState() == STOPPED.
// Maybe should name it such
public CompletableFuture<Void> stateChanged(GdbStateChangeRecord sco) {
- return requestElements(false).thenCompose(__ -> {
+ return doRefresh().thenCompose(__ -> {
AsyncFence fence = new AsyncFence();
for (GdbModelTargetMemoryRegion modelRegion : regionsByStart.values()) {
fence.include(modelRegion.stateChanged(sco));
@@ -192,4 +196,11 @@ public class GdbModelTargetProcessMemory
return fence.ready();
});
}
+
+ protected CompletableFuture<?> refreshInternal() {
+ return doRefresh().exceptionally(ex -> {
+ impl.reportError(this, "Problem refreshing inferior's memory regions", ex);
+ return null;
+ });
+ }
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetSession.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetSession.java
index f86ffdeddd..808c17d291 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetSession.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetSession.java
@@ -21,6 +21,7 @@ import java.util.concurrent.CompletableFuture;
import agent.gdb.manager.*;
import agent.gdb.manager.impl.*;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.impl.cmd.GdbStateChangeRecord;
import agent.gdb.manager.reason.GdbReason;
import ghidra.async.AsyncUtils;
@@ -112,7 +113,7 @@ public class GdbModelTargetSession extends DefaultTargetModelRoot
protected void getVersion() {
impl.gdb.waitForPrompt().thenCompose(__ -> {
- return impl.gdb.consoleCapture("show version");
+ return impl.gdb.consoleCapture("show version", CompletesWithRunning.CANNOT);
}).thenAccept(out -> {
debugger = out;
changeAttributes(List.of(),
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThread.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThread.java
index 7c4e15c5af..57d9623f3d 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThread.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThread.java
@@ -24,6 +24,7 @@ import agent.gdb.manager.GdbManager.StepCmd;
import agent.gdb.manager.impl.GdbFrameInfo;
import agent.gdb.manager.impl.GdbThreadInfo;
import agent.gdb.manager.impl.cmd.GdbStateChangeRecord;
+import agent.gdb.manager.impl.cmd.GdbConsoleExecCommand.CompletesWithRunning;
import agent.gdb.manager.reason.GdbBreakpointHitReason;
import ghidra.async.AsyncUtils;
import ghidra.dbg.agent.DefaultTargetObject;
@@ -214,7 +215,7 @@ public class GdbModelTargetThread
throw new UnsupportedOperationException(kind.name());
case ADVANCE: // Why no exec-advance in GDB/MI?
// TODO: This doesn't work, since advance requires a parameter
- return model.gateFuture(thread.console("advance"));
+ return model.gateFuture(thread.console("advance", CompletesWithRunning.CANNOT));
default:
return model.gateFuture(thread.step(convertToGdb(kind)));
}
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThreadContainer.java b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThreadContainer.java
index e8e494b5fc..a3eabf42ba 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThreadContainer.java
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/model/impl/GdbModelTargetThreadContainer.java
@@ -95,6 +95,10 @@ public class GdbModelTargetThreadContainer
updateUsingThreads(inferior.getKnownThreads());
return AsyncUtils.NIL;
}
+ return doRefresh();
+ }
+
+ protected CompletableFuture<Void> doRefresh() {
return inferior.listThreads().thenAccept(byTID -> {
updateUsingThreads(byTID);
});
@@ -172,4 +176,10 @@ public class GdbModelTargetThreadContainer
return AsyncUtils.NIL;
}
+ protected CompletableFuture<?> refreshInternal() {
+ return doRefresh().exceptionally(ex -> {
+ impl.reportError(this, "Problem refreshing inferior's threads", ex);
+ return null;
+ });
+ }
}