https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/151828
>From b58e5d4fe42a499dc7b9d903f56d62fc993f67a2 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Sat, 2 Aug 2025 09:30:25 -0700 Subject: [PATCH 1/2] [vscode-lldb] Fix race condition when changing lldb-dap arguments --- lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts index 79573ec7342b1..c4e99a3178e8c 100644 --- a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts +++ b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts @@ -39,8 +39,10 @@ export class LLDBDapServer implements vscode.Disposable { const process = child_process.spawn(dapPath, dapArgs, options); process.on("error", (error) => { reject(error); - this.serverProcess = undefined; - this.serverInfo = undefined; + if (this.serverProcess === process) { + this.serverProcess = undefined; + this.serverInfo = undefined; + } }); process.on("exit", (code, signal) => { let errorMessage = "Server process exited early"; @@ -50,8 +52,10 @@ export class LLDBDapServer implements vscode.Disposable { errorMessage += ` due to signal ${signal}`; } reject(new Error(errorMessage)); - this.serverProcess = undefined; - this.serverInfo = undefined; + if (this.serverProcess === process) { + this.serverProcess = undefined; + this.serverInfo = undefined; + } }); process.stdout.setEncoding("utf8").on("data", (data) => { const connection = /connection:\/\/\[([^\]]+)\]:(\d+)/.exec( >From 852216b6fba70668b7f7453e64c1e237b3b63d89 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Tue, 5 Aug 2025 11:46:01 -0700 Subject: [PATCH 2/2] Add a util function `cleanUp` --- lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts index c4e99a3178e8c..34908bb7b33aa 100644 --- a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts +++ b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts @@ -39,10 +39,7 @@ export class LLDBDapServer implements vscode.Disposable { const process = child_process.spawn(dapPath, dapArgs, options); process.on("error", (error) => { reject(error); - if (this.serverProcess === process) { - this.serverProcess = undefined; - this.serverInfo = undefined; - } + this.cleanUp(process); }); process.on("exit", (code, signal) => { let errorMessage = "Server process exited early"; @@ -52,10 +49,7 @@ export class LLDBDapServer implements vscode.Disposable { errorMessage += ` due to signal ${signal}`; } reject(new Error(errorMessage)); - if (this.serverProcess === process) { - this.serverProcess = undefined; - this.serverInfo = undefined; - } + this.cleanUp(process); }); process.stdout.setEncoding("utf8").on("data", (data) => { const connection = /connection:\/\/\[([^\]]+)\]:(\d+)/.exec( @@ -130,7 +124,16 @@ Restarting the server will interrupt any existing debug sessions and start a new return; } this.serverProcess.kill(); - this.serverProcess = undefined; - this.serverInfo = undefined; + this.cleanUp(this.serverProcess); + } + + cleanUp(process: child_process.ChildProcessWithoutNullStreams) { + // If the following don't equal, then the fields have already been updated + // (either a new process has started, or the fields were already cleaned + // up), and so the cleanup should be skipped. + if (this.serverProcess === process) { + this.serverProcess = undefined; + this.serverInfo = undefined; + } } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits