Skip to content

Commit 1250095

Browse files
authored
[vscode-lldb] Improve logging in Server Mode (llvm#159672)
A few improvements to logging when lldb-dap is started in **Server Mode** AND when the **`lldb-dap.logFolder`** setting is used (not `lldb-dap.log-path`). ### Improvement #1 **Avoid the prompt of restarting the server when starting each debug session.** That prompt is caused by the combination of the following facts: 1. The log filename changes every time a new debug session is starting (see [here](https://github.com/llvm/llvm-project/blob/9d6062c490548a5e6fea103e010ab3c9bc73a86d/lldb/tools/lldb-dap/src-ts/logging.ts#L47)) 2. The log filename is passed to the server via an environment variable called "LLDBDAP_LOG" (see [here](https://github.com/llvm/llvm-project/blob/9d6062c490548a5e6fea103e010ab3c9bc73a86d/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts#L263-L269)) 3. All environment variables are put into the "spawn info" variable (see [here](https://github.com/llvm/llvm-project/blob/9d6062c490548a5e6fea103e010ab3c9bc73a86d/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts#L170-L172)). 4. The old and new "spawn info" are compared to decide if a prompt should show (see [here](https://github.com/llvm/llvm-project/blob/9d6062c490548a5e6fea103e010ab3c9bc73a86d/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts#L107-L110)). The fix is to remove the "LLDBDAP_LOG" from the "spawn info" variable, so that the same server can be reused if the log path is the only thing that has changed. ### Improvement #2 **Avoid log file conflict when multiple users share a machine and start server in the same second.** The problem: If two users start lldb-dap server in the same second, they will share the same log path. The first user will create the log file. The second user will find that they cannot access the same file, so their server will fail to start. The fix is to add a part of the VS Code session ID to the log filename. ### Improvement #3 **Avoid restarting the server when the order of environment variables changed.** This is done by sorting the environment variables before putting them into the "spawn info".
1 parent fadea8c commit 1250095

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ Restarting the server will interrupt any existing debug sessions and start a new
167167
return [
168168
path,
169169
...args,
170-
...Object.entries(env ?? {}).map(
171-
(entry) => String(entry[0]) + "=" + String(entry[1]),
172-
),
170+
...Object.entries(env ?? {})
171+
// Filter and sort to avoid restarting the server just because the
172+
// order of env changed or the log path changed.
173+
.filter((entry) => String(entry[0]) !== "LLDBDAP_LOG")
174+
.sort()
175+
.map((entry) => String(entry[0]) + "=" + String(entry[1])),
173176
];
174177
}
175178
}

lldb/tools/lldb-dap/src-ts/logging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class LogFilePathProvider {
4444
const logFolder = this.logFolder || this.context.logUri.fsPath;
4545
switch(type) {
4646
case LogType.DEBUG_SESSION:
47-
return path.join(logFolder, `lldb-dap-session-${formatDate(new Date())}.log`);
47+
return path.join(logFolder, `lldb-dap-${formatDate(new Date())}-${vscode.env.sessionId.split("-")[0]}.log`);
4848
break;
4949
}
5050
}

0 commit comments

Comments
 (0)