mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 19:57:58 +00:00
refactor(process): share the abortable command-turn wait between GDB and Rizin (#14042)
This commit is contained in:
1 parent
e219c9748e
commit
ac774bcd70
4 files changed
+21
-29
No files matched your search
@@ -28,7 +28,7 @@ import {
|
||||
} from "./GdbProviderIdentity.js";
|
||||
import { persistentDebuggerHostSupported } from "../process/PersistentDebuggerHost.js";
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { AbortedWait, waitForAbortable } from "../process/AbortablePromise.js";
|
||||
import { waitForCommandTurn } from "../process/AbortablePromise.js";
|
||||
import {
|
||||
describeLaunchFailure,
|
||||
launcherFailureOf,
|
||||
@@ -1521,7 +1521,7 @@ export class GdbSessionManager {
|
||||
release = resolve;
|
||||
});
|
||||
try {
|
||||
await waitForGdbCommandTurn(previous, signal);
|
||||
await waitForCommandTurn(previous, signal, "gdb_console");
|
||||
acquired = true;
|
||||
return await operation();
|
||||
} finally {
|
||||
@@ -2243,15 +2243,3 @@ export class GdbSessionManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Await a serialized command turn, preserving the caller's cancellation reason. */
|
||||
const waitForGdbCommandTurn = (
|
||||
previous: Promise<void>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<void> => {
|
||||
if (signal === undefined) return previous;
|
||||
return waitForAbortable(previous, signal).then((outcome) => {
|
||||
if (outcome instanceof AbortedWait)
|
||||
throw cancelledBy("gdb_console", outcome);
|
||||
});
|
||||
};
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { CarriedCancellationReason } from "../domain/analysisErrorCore.js";
|
||||
import {
|
||||
cancelledBy,
|
||||
type CarriedCancellationReason,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
|
||||
/**
|
||||
* An abortable wait that the signal won. It carries the signal's reason as
|
||||
@@ -35,3 +38,16 @@ export const waitForAbortable = async <Value>(
|
||||
if (onAbort !== undefined) signal.removeEventListener("abort", onAbort);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Await the previous holder of a serialized command turn. A caller abort that
|
||||
* wins the wait becomes `operation`'s cancellation with the caller's reason.
|
||||
*/
|
||||
export const waitForCommandTurn = async (
|
||||
previous: Promise<void>,
|
||||
signal: AbortSignal | undefined,
|
||||
operation: string,
|
||||
): Promise<void> => {
|
||||
const outcome = await waitForAbortable(previous, signal);
|
||||
if (outcome instanceof AbortedWait) throw cancelledBy(operation, outcome);
|
||||
};
|
||||
@@ -15,7 +15,6 @@ import type { DebuggerSessionStop } from "../domain/debuggerSessionErrors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { utf8HeadExcerpt } from "../domain/utf8HeadExcerpt.js";
|
||||
import type { FifoQueue } from "../kernel/FifoQueue.js";
|
||||
import { AbortedWait, waitForAbortable } from "../process/AbortablePromise.js";
|
||||
import { debuggerAdmissionRecovery } from "../process/ownedDebuggerSession.js";
|
||||
import type { ProviderProcessSupervisor } from "../process/ProviderProcess.js";
|
||||
import {
|
||||
@@ -298,17 +297,6 @@ export const waitForFrame = (
|
||||
});
|
||||
};
|
||||
|
||||
export const waitForTurn = (
|
||||
previous: Promise<void>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<void> => {
|
||||
if (signal === undefined) return previous;
|
||||
return waitForAbortable(previous, signal).then((outcome) => {
|
||||
if (outcome instanceof AbortedWait)
|
||||
throw cancelledBy("rizin_debug_command", outcome);
|
||||
});
|
||||
};
|
||||
|
||||
/** The caller's reason when it aborted, else the reason an earlier failure carried. */
|
||||
export const rizinCancellationReason = (
|
||||
signal: AbortSignal | undefined,
|
||||
|
||||
@@ -28,9 +28,9 @@ import {
|
||||
RizinProcessExitError,
|
||||
waitForCommandFrames,
|
||||
waitForFrame,
|
||||
waitForTurn,
|
||||
type RizinFrame,
|
||||
} from "./RizinDebugFrames.js";
|
||||
import { waitForCommandTurn } from "../process/AbortablePromise.js";
|
||||
import { persistentDebuggerHostSupported } from "../process/PersistentDebuggerHost.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { open, readlink, realpath, stat } from "node:fs/promises";
|
||||
@@ -724,7 +724,7 @@ export class RizinDebugSessionManager {
|
||||
release = resolve;
|
||||
});
|
||||
try {
|
||||
await waitForTurn(previous, signal);
|
||||
await waitForCommandTurn(previous, signal, "rizin_debug_command");
|
||||
acquired = true;
|
||||
if (signal?.aborted)
|
||||
return err(cancelledBy("rizin_debug_command", signal));
|
||||
|
||||
Reference in new issue
Block a user