From 39486e0b5c37f5db88b08220cf603a26f3a7661d Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Mon, 15 Jun 2020 13:47:49 -0700 Subject: [PATCH 1/2] Print launch.json to C/C++ Output Log This PR adds a check in resolveDebugConfiguration so that if a user adds logging.engineLogging = true in the launch.json, we will output the resovled json in the C/C++ Output. --- .../src/Debugger/configurationProvider.ts | 127 ++++++++++-------- 1 file changed, 68 insertions(+), 59 deletions(-) diff --git a/Extension/src/Debugger/configurationProvider.ts b/Extension/src/Debugger/configurationProvider.ts index 35ad0ce053..1de23e010f 100644 --- a/Extension/src/Debugger/configurationProvider.ts +++ b/Extension/src/Debugger/configurationProvider.ts @@ -188,85 +188,94 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider { * Try to add all missing attributes to the debug configuration being launched. */ resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult { - if (config) { - if (config.type === 'cppvsdbg') { - // Fail if cppvsdbg type is running on non-Windows - if (os.platform() !== 'win32') { - logger.getOutputChannelLogger().showWarningMessage(localize("debugger.not.available", "Debugger of type: '{0}' is only available on Windows. Use type: '{1}' on the current OS platform.", "cppvsdbg", "cppdbg")); - return undefined; - } + // if config or type is not specified, return null to trigger VS Code to open a configuration file https://github.com/Microsoft/vscode/issues/54213 + if (!config || !config.type) { + return null; + } - // Disable debug heap by default, enable if 'enableDebugHeap' is set. - if (!config.enableDebugHeap) { - const disableDebugHeapEnvSetting: Environment = {"name" : "_NO_DEBUG_HEAP", "value" : "1"}; + if (config.type === 'cppvsdbg') { + // Fail if cppvsdbg type is running on non-Windows + if (os.platform() !== 'win32') { + logger.getOutputChannelLogger().showWarningMessage(localize("debugger.not.available", "Debugger of type: '{0}' is only available on Windows. Use type: '{1}' on the current OS platform.", "cppvsdbg", "cppdbg")); + return undefined; + } - if (config.environment && util.isArray(config.environment)) { - config.environment.push(disableDebugHeapEnvSetting); - } else { - config.environment = [disableDebugHeapEnvSetting]; - } + // Disable debug heap by default, enable if 'enableDebugHeap' is set. + if (!config.enableDebugHeap) { + const disableDebugHeapEnvSetting: Environment = {"name" : "_NO_DEBUG_HEAP", "value" : "1"}; + + if (config.environment && util.isArray(config.environment)) { + config.environment.push(disableDebugHeapEnvSetting); + } else { + config.environment = [disableDebugHeapEnvSetting]; } } + } - // Add environment variables from .env file - this.resolveEnvFile(config, folder); + // Add environment variables from .env file + this.resolveEnvFile(config, folder); - this.resolveSourceFileMapVariables(config); + this.resolveSourceFileMapVariables(config); - // Modify WSL config for OpenDebugAD7 - if (os.platform() === 'win32' && - config.pipeTransport && - config.pipeTransport.pipeProgram) { - let replacedPipeProgram: string | undefined; - const pipeProgramStr: string = config.pipeTransport.pipeProgram.toLowerCase().trim(); + // Modify WSL config for OpenDebugAD7 + if (os.platform() === 'win32' && + config.pipeTransport && + config.pipeTransport.pipeProgram) { + let replacedPipeProgram: string | undefined; + const pipeProgramStr: string = config.pipeTransport.pipeProgram.toLowerCase().trim(); - // OpenDebugAD7 is a 32-bit process. Make sure the WSL pipe transport is using the correct program. - replacedPipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(pipeProgramStr, debugUtils.ArchType.ia32); + // OpenDebugAD7 is a 32-bit process. Make sure the WSL pipe transport is using the correct program. + replacedPipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(pipeProgramStr, debugUtils.ArchType.ia32); - // If pipeProgram does not get replaced and there is a pipeCwd, concatenate with pipeProgramStr and attempt to replace. - if (!replacedPipeProgram && !path.isAbsolute(pipeProgramStr) && config.pipeTransport.pipeCwd) { - const pipeCwdStr: string = config.pipeTransport.pipeCwd.toLowerCase().trim(); - const newPipeProgramStr: string = path.join(pipeCwdStr, pipeProgramStr); + // If pipeProgram does not get replaced and there is a pipeCwd, concatenate with pipeProgramStr and attempt to replace. + if (!replacedPipeProgram && !path.isAbsolute(pipeProgramStr) && config.pipeTransport.pipeCwd) { + const pipeCwdStr: string = config.pipeTransport.pipeCwd.toLowerCase().trim(); + const newPipeProgramStr: string = path.join(pipeCwdStr, pipeProgramStr); - replacedPipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(newPipeProgramStr, debugUtils.ArchType.ia32); - } + replacedPipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(newPipeProgramStr, debugUtils.ArchType.ia32); + } - if (replacedPipeProgram) { - config.pipeTransport.pipeProgram = replacedPipeProgram; - } + if (replacedPipeProgram) { + config.pipeTransport.pipeProgram = replacedPipeProgram; } + } - const macOSMIMode: string = config.osx?.MIMode ?? config.MIMode; - const macOSMIDebuggerPath: string = config.osx?.miDebuggerPath ?? config.miDebuggerPath; + const macOSMIMode: string = config.osx?.MIMode ?? config.MIMode; + const macOSMIDebuggerPath: string = config.osx?.miDebuggerPath ?? config.miDebuggerPath; - const lldb_mi_10_x_path: string = path.join(util.extensionPath, "debugAdapters", "lldb-mi", "bin", "lldb-mi"); + const lldb_mi_10_x_path: string = path.join(util.extensionPath, "debugAdapters", "lldb-mi", "bin", "lldb-mi"); - // Validate LLDB-MI - if (os.platform() === 'darwin' && // Check for macOS - fs.existsSync(lldb_mi_10_x_path) && // lldb-mi 10.x exists - (!macOSMIMode || macOSMIMode === 'lldb') && - !macOSMIDebuggerPath // User did not provide custom lldb-mi - ) { - const frameworkPath: string | undefined = this.getLLDBFrameworkPath(); + // Validate LLDB-MI + if (os.platform() === 'darwin' && // Check for macOS + fs.existsSync(lldb_mi_10_x_path) && // lldb-mi 10.x exists + (!macOSMIMode || macOSMIMode === 'lldb') && + !macOSMIDebuggerPath // User did not provide custom lldb-mi + ) { + const frameworkPath: string | undefined = this.getLLDBFrameworkPath(); - if (!frameworkPath) { - const moreInfoButton: string = localize("lldb.framework.install.xcode", "More Info"); - const LLDBFrameworkMissingMessage: string = localize("lldb.framework.not.found", "Unable to locate 'LLDB.framework' for lldb-mi. Please install XCode or XCode Command Line Tools."); + if (!frameworkPath) { + const moreInfoButton: string = localize("lldb.framework.install.xcode", "More Info"); + const LLDBFrameworkMissingMessage: string = localize("lldb.framework.not.found", "Unable to locate 'LLDB.framework' for lldb-mi. Please install XCode or XCode Command Line Tools."); - vscode.window.showErrorMessage(LLDBFrameworkMissingMessage, moreInfoButton) - .then(value => { - if (value === moreInfoButton) { - let helpURL: string = "https://aka.ms/vscode-cpptools/LLDBFrameworkNotFound"; - vscode.env.openExternal(vscode.Uri.parse(helpURL)); - } - }); + vscode.window.showErrorMessage(LLDBFrameworkMissingMessage, moreInfoButton) + .then(value => { + if (value === moreInfoButton) { + let helpURL: string = "https://aka.ms/vscode-cpptools/LLDBFrameworkNotFound"; + vscode.env.openExternal(vscode.Uri.parse(helpURL)); + } + }); - return undefined; - } + return undefined; } } - // if config or type is not specified, return null to trigger VS Code to open a configuration file https://github.com/Microsoft/vscode/issues/54213 - return config && config.type ? config : null; + + if (config.logging?.engineLogging) { + const outputChannel: logger.Logger = logger.getOutputChannelLogger(); + outputChannel.appendLine(JSON.stringify(config, undefined, 2)); + logger.showOutputChannel(); + } + + return config; } private getLLDBFrameworkPath(): string | undefined { From af611a3873bac1e29b7f25995146f62ea1307e97 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Mon, 15 Jun 2020 17:21:43 -0700 Subject: [PATCH 2/2] Use GitHub bug notation and add title for log --- Extension/src/Debugger/configurationProvider.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Extension/src/Debugger/configurationProvider.ts b/Extension/src/Debugger/configurationProvider.ts index 1de23e010f..f9a4cf467a 100644 --- a/Extension/src/Debugger/configurationProvider.ts +++ b/Extension/src/Debugger/configurationProvider.ts @@ -188,7 +188,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider { * Try to add all missing attributes to the debug configuration being launched. */ resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult { - // if config or type is not specified, return null to trigger VS Code to open a configuration file https://github.com/Microsoft/vscode/issues/54213 + // [Microsoft/vscode#54213] If config or type is not specified, return null to trigger VS Code to open a configuration file. if (!config || !config.type) { return null; } @@ -271,6 +271,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider { if (config.logging?.engineLogging) { const outputChannel: logger.Logger = logger.getOutputChannelLogger(); + outputChannel.appendLine(localize("debugger.launchConfig", "Launch configuration:")); outputChannel.appendLine(JSON.stringify(config, undefined, 2)); logger.showOutputChannel(); }