Skip to content

Commit d0b9ec7

Browse files
committed
Deprecate lldb-dap.log-path setting in favour of lldb-dap.logFolder
1 parent ca7fd10 commit d0b9ec7

File tree

6 files changed

+82
-29
lines changed

6 files changed

+82
-29
lines changed

lldb/tools/lldb-dap/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@
8181
"description": "The path to the lldb-dap binary, e.g. /usr/local/bin/lldb-dap"
8282
},
8383
"lldb-dap.log-path": {
84+
"scope": "machine-overridable",
85+
"type": "string",
86+
"description": "The log path for lldb-dap (if any)",
87+
"markdownDeprecationMessage": "Use the `#lldb-dap.logFolder#` setting instead"
88+
},
89+
"lldb-dap.logFolder": {
8490
"order": 0,
8591
"scope": "machine-overridable",
8692
"type": "string",
87-
"description": "The log path for lldb-dap (if any)"
93+
"markdownDescription": "The folder to persist lldb-dap logs. If no value is provided, logs will be persisted in the [Extension Logs Folder](command:workbench.action.openExtensionLogsFolder)."
8894
},
8995
"lldb-dap.serverMode": {
9096
"order": 0,

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as child_process from "child_process";
55
import * as fs from "node:fs/promises";
66
import { ConfigureButton, OpenSettingsButton } from "./ui/show-error-message";
77
import { ErrorWithNotification } from "./ui/error-with-notification";
8-
import { LogFilePathProvider } from "./types";
8+
import { LogFilePathProvider, LogType } from "./logging";
99

1010
const exec = util.promisify(child_process.execFile);
1111

@@ -157,22 +157,6 @@ async function getDAPArguments(
157157
.get<string[]>("arguments", []);
158158
}
159159

160-
/**
161-
* Formats the given date as a string in the form "YYYYMMddTHHMMSS".
162-
*
163-
* @param date The date to format as a string.
164-
* @returns The formatted date.
165-
*/
166-
function formatDate(date: Date): string {
167-
const year = date.getFullYear().toString().padStart(4, "0");
168-
const month = (date.getMonth() + 1).toString().padStart(2, "0");
169-
const day = date.getDate().toString().padStart(2, "0");
170-
const hour = date.getHours().toString().padStart(2, "0");
171-
const minute = date.getMinutes().toString().padStart(2, "0");
172-
const seconds = date.getSeconds().toString().padStart(2, "0");
173-
return `${year}${month}${day}T${hour}${minute}${seconds}`;
174-
}
175-
176160
/**
177161
* Creates a new {@link vscode.DebugAdapterExecutable} based on the provided workspace folder and
178162
* debug configuration. Assumes that the given debug configuration is for a local launch of lldb-dap.
@@ -200,9 +184,7 @@ export async function createDebugAdapterExecutable(
200184
} else if (
201185
vscode.workspace.getConfiguration("lldb-dap").get("captureSessionLogs", false)
202186
) {
203-
env["LLDBDAP_LOG"] = logFilePath(
204-
`lldb-dap-session-${formatDate(new Date())}.log`,
205-
);
187+
env["LLDBDAP_LOG"] = logFilePath.get(LogType.DEBUG_SESSION);
206188
}
207189
const configEnvironment =
208190
config.get<{ [key: string]: string }>("environment") || {};
@@ -220,7 +202,7 @@ export async function createDebugAdapterExecutable(
220202
logger.info(`lldb-dap path: ${dapPath}`);
221203
logger.info(`lldb-dap args: ${dbgArgs}`);
222204
logger.info(`cwd: ${dbgOptions.cwd}`);
223-
logger.info(`env: ${JSON.stringify(configEnvironment)}`);
205+
logger.info(`env: ${JSON.stringify(dbgOptions.env)}`);
224206

225207
return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions);
226208
}

lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { LLDBDapServer } from "./lldb-dap-server";
55
import { createDebugAdapterExecutable } from "./debug-adapter-factory";
66
import { ConfigureButton, showErrorMessage } from "./ui/show-error-message";
77
import { ErrorWithNotification } from "./ui/error-with-notification";
8-
import { LogFilePathProvider } from "./types";
8+
import { LogFilePathProvider } from "./logging";
99

1010
const exec = util.promisify(child_process.execFile);
1111

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ModulesDataProvider,
1212
ModuleProperty,
1313
} from "./ui/modules-data-provider";
14-
import { LogFilePathProvider } from "./types";
14+
import { LogFilePathProvider } from "./logging";
1515

1616
/**
1717
* This class represents the extension and manages its life cycle. Other extensions
@@ -64,11 +64,10 @@ export class LLDBDapExtension extends DisposableContext {
6464
*/
6565
export async function activate(context: vscode.ExtensionContext) {
6666
const outputChannel = vscode.window.createOutputChannel("LLDB-DAP", { log: true });
67-
const logFilePath: LogFilePathProvider = (name: string) =>
68-
path.join(context.logUri.fsPath, name);
69-
outputChannel.info("LLDB-Dap extension activating...");
67+
outputChannel.info("LLDB-DAP extension activating...");
68+
const logFilePath = new LogFilePathProvider(context, outputChannel);
7069
context.subscriptions.push(
7170
new LLDBDapExtension(outputChannel, logFilePath, outputChannel),
7271
);
73-
outputChannel.info("LLDB-Dap extension activated");
72+
outputChannel.info("LLDB-DAP extension activated");
7473
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as path from "path";
2+
import * as vscode from "vscode";
3+
4+
/**
5+
* Formats the given date as a string in the form "YYYYMMddTHHMMSS".
6+
*
7+
* @param date The date to format as a string.
8+
* @returns The formatted date.
9+
*/
10+
function formatDate(date: Date): string {
11+
const year = date.getFullYear().toString().padStart(4, "0");
12+
const month = (date.getMonth() + 1).toString().padStart(2, "0");
13+
const day = date.getDate().toString().padStart(2, "0");
14+
const hour = date.getHours().toString().padStart(2, "0");
15+
const minute = date.getMinutes().toString().padStart(2, "0");
16+
const seconds = date.getSeconds().toString().padStart(2, "0");
17+
return `${year}${month}${day}T${hour}${minute}${seconds}`;
18+
}
19+
20+
export enum LogType {
21+
DEBUG_SESSION,
22+
}
23+
24+
export class LogFilePathProvider {
25+
private logFolder: string = "";
26+
27+
constructor(
28+
private context: vscode.ExtensionContext,
29+
private logger: vscode.LogOutputChannel,
30+
) {
31+
this.updateLogFolder();
32+
context.subscriptions.push(
33+
vscode.workspace.onDidChangeConfiguration(e => {
34+
if (
35+
e.affectsConfiguration("lldb-dap.logFolder")
36+
) {
37+
this.updateLogFolder();
38+
}
39+
})
40+
);
41+
}
42+
43+
get(type: LogType): string {
44+
const logFolder = this.logFolder || this.context.logUri.fsPath;
45+
switch(type) {
46+
case LogType.DEBUG_SESSION:
47+
return path.join(logFolder, `lldb-dap-session-${formatDate(new Date())}.log`);
48+
break;
49+
}
50+
}
51+
52+
private updateLogFolder() {
53+
const config = vscode.workspace.getConfiguration("lldb-dap");
54+
let logFolder =
55+
config.get<string>("logFolder") || this.context.logUri.fsPath;
56+
vscode.workspace.fs
57+
.createDirectory(vscode.Uri.file(logFolder))
58+
.then(undefined, (error) => {
59+
this.logger.error(`Failed to create log folder ${logFolder}: ${error}`);
60+
logFolder = this.context.logUri.fsPath;
61+
})
62+
.then(() => {
63+
this.logFolder = logFolder;
64+
this.logger.info(`Persisting lldb-dap logs to ${logFolder}`);
65+
});
66+
}
67+
}

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)