Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lldb/tools/lldb-dap/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lldb/tools/lldb-dap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"categories": [
"Debuggers"
],
"dependencies": {
"chokidar": "^4.0.3"
},
"devDependencies": {
"@types/node": "^18.19.41",
"@types/tabulator-tables": "^6.2.10",
Expand Down
60 changes: 47 additions & 13 deletions lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { FSWatcher, watch as chokidarWatch } from 'chokidar';
import * as child_process from "node:child_process";
import * as path from "path";
import { isDeepStrictEqual } from "util";
import * as vscode from "vscode";

Expand All @@ -12,6 +14,10 @@ export class LLDBDapServer implements vscode.Disposable {
private serverProcess?: child_process.ChildProcessWithoutNullStreams;
private serverInfo?: Promise<{ host: string; port: number }>;
private serverSpawnInfo?: string[];
// Detects changes to the lldb-dap executable file since the server's startup.
private serverFileWatcher?: FSWatcher;
// Indicates whether the lldb-dap executable file has changed since the server's startup.
private serverFileChanged?: boolean;

constructor() {
vscode.commands.registerCommand(
Expand Down Expand Up @@ -83,6 +89,11 @@ export class LLDBDapServer implements vscode.Disposable {
});
this.serverProcess = process;
this.serverSpawnInfo = this.getSpawnInfo(dapPath, dapArgs, options?.env);
this.serverFileChanged = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@royitaqi royitaqi Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: vscode.workspace.createFileSystemWatcher now works on my machine. Are you suggesting to use chokidar instead?

Also, even with chokidar, I will have to have this.serverFileChanged, so that we know that the lldb-dap binary has changed at the start of the next debug session. Make sense?

Updated the patch to use chokidar.

this.serverFileWatcher = chokidarWatch(dapPath);
this.serverFileWatcher
.on('change', () => this.serverFileChanged = true)
.on('unlink', () => this.serverFileChanged = true);
});
return this.serverInfo;
}
Expand All @@ -100,39 +111,58 @@ export class LLDBDapServer implements vscode.Disposable {
args: string[],
env: NodeJS.ProcessEnv | { [key: string]: string } | undefined,
): Promise<boolean> {
if (!this.serverProcess || !this.serverInfo || !this.serverSpawnInfo) {
if (
!this.serverProcess ||
!this.serverInfo ||
!this.serverSpawnInfo ||
!this.serverFileWatcher ||
this.serverFileChanged === undefined
) {
return true;
}

const newSpawnInfo = this.getSpawnInfo(dapPath, args, env);
if (isDeepStrictEqual(this.serverSpawnInfo, newSpawnInfo)) {
return true;
}
const changeTLDR = [];
const changeDetails = [];

const userInput = await vscode.window.showInformationMessage(
"The arguments to lldb-dap have changed. Would you like to restart the server?",
{
modal: true,
detail: `An existing lldb-dap server (${this.serverProcess.pid}) is running with different arguments.
if (this.serverFileChanged) {
changeTLDR.push("an old binary");
}

const newSpawnInfo = this.getSpawnInfo(dapPath, args, env);
if (!isDeepStrictEqual(this.serverSpawnInfo, newSpawnInfo)) {
changeTLDR.push("different arguments");
changeDetails.push(`
The previous lldb-dap server was started with:

${this.serverSpawnInfo.join(" ")}

The new lldb-dap server will be started with:

${newSpawnInfo.join(" ")}
`
);
}

// If the server hasn't changed, continue startup without killing it.
if (changeTLDR.length === 0) {
return true;
}

// The server has changed. Prompt the user to restart it.
const userInput = await vscode.window.showInformationMessage(
"The lldb-dap server has changed. Would you like to restart the server?",
{
modal: true,
detail: `An existing lldb-dap server (${this.serverProcess.pid}) is running with ${changeTLDR.map(s => `*${s}*`).join(" and ")}.
${changeDetails.join("\n")}
Restarting the server will interrupt any existing debug sessions and start a new server.`,
},
"Restart",
"Use Existing",
);
switch (userInput) {
case "Restart":
this.serverProcess.kill();
this.serverProcess = undefined;
this.serverInfo = undefined;
this.dispose();
return true;
case "Use Existing":
return true;
Expand All @@ -156,6 +186,10 @@ Restarting the server will interrupt any existing debug sessions and start a new
if (this.serverProcess === process) {
this.serverProcess = undefined;
this.serverInfo = undefined;
this.serverSpawnInfo = undefined;
this.serverFileWatcher?.close();
this.serverFileWatcher = undefined;
this.serverFileChanged = undefined;
}
}

Expand Down
Loading