Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(gdb): accept GDB's built-in p, s, d and t aliases (#5124)

bercebe4498d39404
diff --git a/src/gdb/GdbSessionManager.ts b/src/gdb/GdbSessionManager.ts
index 340926d20..0671ea895 100644
--- a/src/gdb/GdbSessionManager.ts
+++ b/src/gdb/GdbSessionManager.ts
@@ -2260,12 +2260,30 @@ export const miStringField = (
: undefined;
};
+// GDB resolves its built-in aliases before abbreviations, so `p` is print, never
+// python. Of the prefixes of the commands classified below, only these four
+// name another command (checked against GDB 18.1).
+const GDB_BUILTIN_ALIASES: ReadonlyMap<string, string> = new Map([
+ ["d", "delete"],
+ ["p", "print"],
+ ["s", "step"],
+ ["t", "thread"],
+]);
+
+/** The first console word, lowercased, with GDB's built-in aliases resolved. */
+const gdbCommandWord = (command: string): string | undefined => {
+ const word = /^\s*([^\s;]+)/u.exec(command)?.[1]?.toLowerCase();
+ return word === undefined
+ ? undefined
+ : (GDB_BUILTIN_ALIASES.get(word) ?? word);
+};
+
/** @internal Classify commands that can invalidate the configured output sink. */
export const gdbOneShotCommandMayInvalidateDetachProof = (
command: string,
): boolean => {
if (commandMayChangeInferiorOutput(command)) return true;
- const firstToken = /^\s*([^\s;]+)/u.exec(command)?.[1]?.toLowerCase();
+ const firstToken = gdbCommandWord(command);
if (
firstToken !== undefined &&
(["source", "define", "alias"].some((name) =>
@@ -2285,7 +2303,7 @@ export const commandMayChangeInferiorOutput = (command: string): boolean => {
const setting = /^\s*(?:set|with)\s+(\S+)/iu.exec(command)?.[1];
const maySetInferiorTty =
setting !== undefined && "inferior-tty".startsWith(setting.toLowerCase());
- const firstToken = /^\s*([^\s;]+)/u.exec(command)?.[1]?.toLowerCase();
+ const firstToken = gdbCommandWord(command);
const mayBeTtyCommand =
firstToken !== undefined && "tty".startsWith(firstToken);
const mayDefineAlias =
diff --git a/tests/boundary/providers/GdbSessionManagerCoverage.test.ts b/tests/boundary/providers/GdbSessionManagerCoverage.test.ts
index 636dfd830..cdc648024 100644
--- a/tests/boundary/providers/GdbSessionManagerCoverage.test.ts
+++ b/tests/boundary/providers/GdbSessionManagerCoverage.test.ts
@@ -14,6 +14,7 @@ import {
import {
commandMayChangeInferiorOutput,
gdbErrorMessage,
+ gdbOneShotCommandMayInvalidateDetachProof,
gdbThreadGroupCount,
GdbSessionManager,
miStringField,
@@ -141,10 +142,31 @@ it.each([
["python print(1)", true],
["define start\nrun", true],
["run > /tmp/output", true],
+ ["t 1", false],
+ ["tt /dev/pts/2", true],
] as const)("classifies inferior output mutations: %s", (command, expected) => {
expect(commandMayChangeInferiorOutput(command)).toBe(expected);
});
+// GDB's built-in aliases are full commands, not abbreviations of python,
+// source or define (#5098); ambiguous and true abbreviations stay refused.
+it.each([
+ ["p 1", false],
+ ["print 1", false],
+ ["s", false],
+ ["step", false],
+ ["d 1", false],
+ ["delete 1", false],
+ ["t 1", false],
+ ["py print(1)", true],
+ ["pyt print(1)", true],
+ ["so commands.gdb", true],
+ ["de", true],
+ ["p 1; python print(2)", true],
+] as const)("classifies one-shot GDB commands: %s", (command, expected) => {
+ expect(gdbOneShotCommandMayInvalidateDetachProof(command)).toBe(expected);
+});
+
it.each([
[new Error("provider failure"), "provider failure"],
["non-error provider failure", "non-error provider failure"],