Improve Hopper session reliability
This commit is contained in:
1 parent
ee6d539a40
commit
d9c9025ffb
11 files changed
+124
-80
No files matched your search
@@ -39,21 +39,18 @@ export class BinarySession implements HopperToolPort {
|
||||
return ok(parsed.value);
|
||||
await this.#drainCalls();
|
||||
const previous = this.#active;
|
||||
this.#active = undefined;
|
||||
await previous?.client.close();
|
||||
const client = this.createClient(parsed.value);
|
||||
const started = await client.callTool("health", {}, options);
|
||||
if (!started.ok) {
|
||||
await client.close();
|
||||
if (previous !== undefined) await this.#restore(previous.target);
|
||||
return started;
|
||||
}
|
||||
if (isAborted(options.signal)) {
|
||||
await client.close();
|
||||
if (previous !== undefined) await this.#restore(previous.target);
|
||||
return err(new HopperCancelledError());
|
||||
}
|
||||
this.#active = { target: parsed.value, client };
|
||||
await previous?.client.close();
|
||||
return ok(parsed.value);
|
||||
});
|
||||
}
|
||||
@@ -114,13 +111,6 @@ export class BinarySession implements HopperToolPort {
|
||||
await Promise.allSettled([...this.#calls]);
|
||||
}
|
||||
|
||||
async #restore(target: BinaryTarget): Promise<void> {
|
||||
const client = this.createClient(target);
|
||||
const started = await client.callTool("health", {});
|
||||
if (started.ok) this.#active = { target, client };
|
||||
else await client.close();
|
||||
}
|
||||
|
||||
async #waitForTransition(
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<undefined, HopperCancelledError>> {
|
||||
|
||||
@@ -6,6 +6,8 @@ import { join } from "node:path";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { probeHomebrew } from "./homebrew.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const DEFAULT_HOPPER =
|
||||
"/Applications/Hopper Disassembler.app/Contents/MacOS/hopper";
|
||||
@@ -119,11 +121,7 @@ export const systemDoctorHost = (): DoctorHost => ({
|
||||
}
|
||||
},
|
||||
async brewHopperPath() {
|
||||
for (const command of [
|
||||
"brew",
|
||||
"/opt/homebrew/bin/brew",
|
||||
"/usr/local/bin/brew",
|
||||
]) {
|
||||
return probeHomebrew(async (command) => {
|
||||
try {
|
||||
const prefix = (
|
||||
await execFileAsync(command, [
|
||||
@@ -134,10 +132,9 @@ export const systemDoctorHost = (): DoctorHost => ({
|
||||
).stdout.trim();
|
||||
return `${prefix}/Hopper Disassembler.app/Contents/MacOS/hopper`;
|
||||
} catch {
|
||||
// Try the next standard Homebrew executable location.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
},
|
||||
async manualHopperPaths() {
|
||||
const roots = ["/Applications", join(homedir(), "Applications")];
|
||||
|
||||
@@ -131,7 +131,7 @@ export class EnhancedTools {
|
||||
const relation = input.direction === "forward" ? "callees" : "callers";
|
||||
const tool =
|
||||
input.direction === "forward" ? "procedure_callees" : "procedure_callers";
|
||||
const visited = new Set<string>();
|
||||
const discovered = new Set([input.address]);
|
||||
const queue: Array<{ address: string; depth: number }> = [
|
||||
{ address: input.address, depth: 0 },
|
||||
];
|
||||
@@ -140,14 +140,9 @@ export class EnhancedTools {
|
||||
|
||||
while (queueIndex < queue.length) {
|
||||
const current = queue[queueIndex++];
|
||||
if (
|
||||
current === undefined ||
|
||||
visited.has(current.address) ||
|
||||
current.depth >= input.depth
|
||||
) {
|
||||
if (current === undefined || current.depth >= input.depth) {
|
||||
continue;
|
||||
}
|
||||
visited.add(current.address);
|
||||
const level = String(current.depth);
|
||||
graph[level] ??= [];
|
||||
|
||||
@@ -177,8 +172,10 @@ export class EnhancedTools {
|
||||
});
|
||||
if (current.depth + 1 < input.depth) {
|
||||
for (const address of related.value) {
|
||||
if (!visited.has(address))
|
||||
if (!discovered.has(address)) {
|
||||
discovered.add(address);
|
||||
queue.push({ address, depth: current.depth + 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { z } from "zod";
|
||||
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import { runDoctor, systemDoctorHost } from "./Doctor.js";
|
||||
import { probeHomebrew } from "./homebrew.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
@@ -271,13 +272,10 @@ const commandSucceeds = async (
|
||||
}
|
||||
};
|
||||
const brewSucceeds = async (args: readonly string[]): Promise<boolean> => {
|
||||
for (const command of [
|
||||
"brew",
|
||||
"/opt/homebrew/bin/brew",
|
||||
"/usr/local/bin/brew",
|
||||
])
|
||||
if (await commandSucceeds(command, args)) return true;
|
||||
return false;
|
||||
const result = await probeHomebrew(async (command) =>
|
||||
(await commandSucceeds(command, args)) ? true : undefined,
|
||||
);
|
||||
return result === true;
|
||||
};
|
||||
const major = (version: string): number =>
|
||||
Number.parseInt(version.split(".")[0] ?? "0", 10);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/** Standard executable names and locations used to discover Homebrew. */
|
||||
export const HOMEBREW_COMMANDS = [
|
||||
"brew",
|
||||
"/opt/homebrew/bin/brew",
|
||||
"/usr/local/bin/brew",
|
||||
] as const;
|
||||
|
||||
/** Return the first successful result from the standard Homebrew executables. */
|
||||
export const probeHomebrew = async <T>(
|
||||
probe: (command: string) => Promise<T | undefined>,
|
||||
): Promise<T | undefined> => {
|
||||
for (const command of HOMEBREW_COMMANDS) {
|
||||
const result = await probe(command);
|
||||
if (result !== undefined) return result;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
Reference in new issue
Block a user