From fd17308d82f1234c7595bb35514907d7012343d9 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Wed, 30 Sep 2015 17:06:09 -0700 Subject: [PATCH] add PDB format option to /debug flag --- .../Portable/CommandLine/CommandLineParser.cs | 38 +++++++++---------- .../Test/CommandLine/CommandLineTests.cs | 20 ++++++++++ .../Portable/CommandLine/CommandLineParser.vb | 31 ++++++--------- .../Test/CommandLine/CommandLineTests.vb | 19 +++++++++- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CommandLine/CommandLineParser.cs b/src/Compilers/CSharp/Portable/CommandLine/CommandLineParser.cs index e2e816b6792..34b31c2258a 100644 --- a/src/Compilers/CSharp/Portable/CommandLine/CommandLineParser.cs +++ b/src/Compilers/CSharp/Portable/CommandLine/CommandLineParser.cs @@ -59,6 +59,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable args, string bas bool concurrentBuild = true; bool deterministic = false; // TODO(5431): Enable deterministic mode by default bool emitPdb = false; + DebugInformationFormat debugInformationFormat = DebugInformationFormat.Pdb; bool debugPlus = false; string pdbPath = null; bool noStdLib = false; @@ -516,11 +517,22 @@ public new CSharpCommandLineArguments Parse(IEnumerable args, string bas if (value.IsEmpty()) { AddDiagnostic(diagnostics, ErrorCode.ERR_SwitchNeedsString, MessageID.IDS_Text.Localize(), name); + continue; } - else if (!string.Equals(value, "full", StringComparison.OrdinalIgnoreCase) && - !string.Equals(value, "pdbonly", StringComparison.OrdinalIgnoreCase)) - { - AddDiagnostic(diagnostics, ErrorCode.ERR_BadDebugType, value); + switch (value.ToLower()) { + case "full": + case "pdbonly": + debugInformationFormat = DebugInformationFormat.Pdb; + break; + case "portable": + debugInformationFormat = DebugInformationFormat.PortablePdb; + break; + case "embedded": + debugInformationFormat = DebugInformationFormat.Embedded; + break; + default: + AddDiagnostic(diagnostics, ErrorCode.ERR_BadDebugType, value); + break; } } continue; @@ -1053,21 +1065,6 @@ public new CSharpCommandLineArguments Parse(IEnumerable args, string bas var parsedFeatures = CompilerOptionParseUtilities.ParseFeatures(features); - var debugInfoFormat = DebugInformationFormat.Pdb; - string pdbFormatStr; - if (emitPdb && parsedFeatures.TryGetValue("pdb", out pdbFormatStr)) - { - if (pdbFormatStr == "portable") - { - debugInfoFormat = DebugInformationFormat.PortablePdb; - } - else if (pdbFormatStr == "embedded") - { - debugInfoFormat = DebugInformationFormat.Embedded; - emitPdb = false; - } - } - string compilationName; GetCompilationAndModuleNames(diagnostics, outputKind, sourceFiles, sourceFilesSpecified, moduleAssemblyName, ref outputFileName, ref moduleName, out compilationName); @@ -1116,7 +1113,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable args, string bas var emitOptions = new EmitOptions ( metadataOnly: false, - debugInformationFormat: debugInfoFormat, + debugInformationFormat: debugInformationFormat, pdbFilePath: null, // to be determined later outputNameOverride: null, // to be determined later baseAddress: baseAddress, @@ -1139,6 +1136,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable args, string bas OutputFileName = outputFileName, PdbPath = pdbPath, EmitPdb = emitPdb, + // TODO: pipe debugInformationFormat through this OutputDirectory = outputDirectory, DocumentationPath = documentationPath, ErrorLogPath = errorLogPath, diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index 958804989c9..0621998e795 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -1177,42 +1177,62 @@ public void Debug() var parsedArgs = DefaultParse(new[] { "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug-", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug+", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(true, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug+", "/debug-", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug:full", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug:FULL", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug:pdbonly", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); + + parsedArgs = DefaultParse(new[] { "/debug:portable", "a.cs" }, _baseDirectory); + parsedArgs.Errors.Verify(); + Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.PortablePdb); + + parsedArgs = DefaultParse(new[] { "/debug:embedded", "a.cs" }, _baseDirectory); + parsedArgs.Errors.Verify(); + Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Embedded); parsedArgs = DefaultParse(new[] { "/debug:PDBONLY", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug:full", "/debug:pdbonly", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); Assert.Equal(false, parsedArgs.CompilationOptions.DebugPlusMode); + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb); parsedArgs = DefaultParse(new[] { "/debug:pdbonly", "/debug:full", "a.cs" }, _baseDirectory); parsedArgs.Errors.Verify(); diff --git a/src/Compilers/VisualBasic/Portable/CommandLine/CommandLineParser.vb b/src/Compilers/VisualBasic/Portable/CommandLine/CommandLineParser.vb index a970030ab98..051ffbebc87 100644 --- a/src/Compilers/VisualBasic/Portable/CommandLine/CommandLineParser.vb +++ b/src/Compilers/VisualBasic/Portable/CommandLine/CommandLineParser.vb @@ -90,6 +90,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim concurrentBuild As Boolean = True Dim deterministic As Boolean = False Dim emitPdb As Boolean + Dim debugInformationFormat As DebugInformationFormat = DebugInformationFormat.Pdb Dim noStdLib As Boolean = False Dim utf8output As Boolean = False Dim outputFileName As String = Nothing @@ -581,16 +582,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Continue For Case "debug" - ' parse only for backwards compat value = RemoveQuotesAndSlashes(value) If value IsNot Nothing Then - If String.IsNullOrEmpty(value) Then - AddDiagnostic(diagnostics, ERRID.ERR_ArgumentRequired, "debug", ":pdbonly|full") - ElseIf Not String.Equals(value, "full", StringComparison.OrdinalIgnoreCase) AndAlso - Not String.Equals(value, "pdbonly", StringComparison.OrdinalIgnoreCase) Then - AddDiagnostic(diagnostics, ERRID.ERR_InvalidSwitchValue, "debug", value) - End If + Select Case value.ToLower() + Case "full", "pdbonly" + debugInformationFormat = DebugInformationFormat.Pdb + Case "portable" + debugInformationFormat = DebugInformationFormat.PortablePdb + Case "embedded" + debugInformationFormat = DebugInformationFormat.Embedded + Case Else + AddDiagnostic(diagnostics, ERRID.ERR_InvalidSwitchValue, "debug", value) + End Select End If emitPdb = True @@ -1160,17 +1164,6 @@ lVbRuntimePlus: Dim parsedFeatures = CompilerOptionParseUtilities.ParseFeatures(features) - Dim debugInfoFormat = DebugInformationFormat.Pdb - Dim pdbFormatStr As String = Nothing - If emitPdb AndAlso parsedFeatures.TryGetValue("pdb", pdbFormatStr) Then - If StringComparer.Ordinal.Equals(pdbFormatStr, "portable") Then - debugInfoFormat = DebugInformationFormat.PortablePdb - ElseIf StringComparer.Ordinal.Equals(pdbFormatStr, "embedded") Then - debugInfoFormat = DebugInformationFormat.Embedded - emitPdb = False - End If - End If - Dim compilationName As String = Nothing GetCompilationAndModuleNames(diagnostics, outputKind, sourceFiles, moduleAssemblyName, outputFileName, moduleName, compilationName) @@ -1223,7 +1216,7 @@ lVbRuntimePlus: Dim emitOptions = New EmitOptions( metadataOnly:=False, - debugInformationFormat:=debugInfoFormat, + debugInformationFormat:=debugInformationFormat, pdbFilePath:=Nothing, ' to be determined later outputNameOverride:=Nothing, ' to be determined later fileAlignment:=fileAlignment, diff --git a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb index 065d968bd8f..557e3c57ac1 100644 --- a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb +++ b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb @@ -2199,30 +2199,47 @@ a.vb parsedArgs = DefaultParse({"/debug-", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug+", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug+", "/debug-", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug:full", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug:FULL", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug:pdbonly", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) + + parsedArgs = DefaultParse({"/debug:portable", "a.vb"}, _baseDirectory) + parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.PortablePdb) + + parsedArgs = DefaultParse({"/debug:embedded", "a.vb"}, _baseDirectory) + parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Embedded) parsedArgs = DefaultParse({"/debug:PDBONLY", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug:full", "/debug:pdbonly", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() + Assert.Equal(parsedArgs.EmitOptions.DebugInformationFormat, DebugInformationFormat.Pdb) parsedArgs = DefaultParse({"/debug:pdbonly", "/debug:full", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify() @@ -2245,7 +2262,7 @@ a.vb Assert.Equal(DebugInformationFormat.Pdb, parsedArgs.EmitOptions.DebugInformationFormat) parsedArgs = DefaultParse({"/debug:", "a.vb"}, _baseDirectory) - parsedArgs.Errors.Verify(Diagnostic(ERRID.ERR_ArgumentRequired).WithArguments("debug", ":pdbonly|full")) + parsedArgs.Errors.Verify(Diagnostic(ERRID.ERR_InvalidSwitchValue).WithArguments("debug", "")) parsedArgs = DefaultParse({"/debug:+", "a.vb"}, _baseDirectory) parsedArgs.Errors.Verify(Diagnostic(ERRID.ERR_InvalidSwitchValue).WithArguments("debug", "+")) -- GitLab