Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print launch.json to C/C++ Output Log #5644

Merged
merged 4 commits into from
Jun 17, 2020
Merged
Changes from 2 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
127 changes: 68 additions & 59 deletions Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.DebugConfiguration> {
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
WardenGnaw marked this conversation as resolved.
Show resolved Hide resolved
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) {
const 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) {
const 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));
WardenGnaw marked this conversation as resolved.
Show resolved Hide resolved
logger.showOutputChannel();
}

return config;
}

private getLLDBFrameworkPath(): string | undefined {
Expand Down