未验证 提交 7fe84de7 编写于 作者: T Tomáš Matoušek 提交者: GitHub

Trim sequence point column numbers greater than 0xffff. (#32688)

Fixes https://github.com/dotnet/roslyn/issues/20118
上级 0e5a7612
......@@ -526,6 +526,130 @@ public void CustomDebugEntryPoint_Errors()
Diagnostic(ErrorCode.ERR_DebugEntryPointNotSourceMethodDefinition));
}
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)]
[WorkItem(768862, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/768862")]
public void TestLargeLineDelta()
{
var verbatim = string.Join("\r\n", Enumerable.Repeat("x", 1000));
var source = $@"
class C {{ public static void Main() => System.Console.WriteLine(@""{verbatim}""); }}
";
var c = CreateCompilationWithMscorlib40AndSystemCore(source, options: TestOptions.DebugDll);
c.VerifyPdb("C.Main", @"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""2"" startColumn=""40"" endLine=""1001"" endColumn=""4"" document=""1"" />
</sequencePoints>
</method>
</methods>
</symbols>
", format: DebugInformationFormat.PortablePdb);
// Native PDBs only support spans with line delta <= 127 (7 bit)
// https://github.com/Microsoft/microsoft-pdb/blob/master/include/cvinfo.h#L4621
c.VerifyPdb("C.Main", @"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""2"" startColumn=""40"" endLine=""129"" endColumn=""4"" document=""1"" />
</sequencePoints>
</method>
</methods>
</symbols>
", format: DebugInformationFormat.Pdb);
}
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)]
[WorkItem(20118, "https://github.com/dotnet/roslyn/issues/20118")]
public void TestLargeStartAndEndColumn_SameLine()
{
var spaces = new string(' ', 0x10000);
var source = $@"
class C
{{
public static void Main() =>
{spaces}System.Console.WriteLine(""{spaces}"");
}}
";
var c = CreateCompilationWithMscorlib40AndSystemCore(source, options: TestOptions.DebugDll);
c.VerifyPdb("C.Main", @"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""5"" startColumn=""65533"" endLine=""5"" endColumn=""65534"" document=""1"" />
</sequencePoints>
</method>
</methods>
</symbols>
");
}
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)]
[WorkItem(20118, "https://github.com/dotnet/roslyn/issues/20118")]
public void TestLargeStartAndEndColumn_DifferentLine()
{
var spaces = new string(' ', 0x10000);
var source = $@"
class C
{{
public static void Main() =>
{spaces}System.Console.WriteLine(
""{spaces}"");
}}
";
var c = CreateCompilationWithMscorlib40AndSystemCore(source, options: TestOptions.DebugDll);
c.VerifyPdb("C.Main", @"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""5"" startColumn=""65534"" endLine=""6"" endColumn=""65534"" document=""1"" />
</sequencePoints>
</method>
</methods>
</symbols>
");
}
#endregion
#region Method Bodies
......
......@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.CodeGen
/// Represents a sequence point before translation by #line/ExternalSource directives.
/// </summary>
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
internal struct RawSequencePoint
internal readonly struct RawSequencePoint
{
internal readonly SyntaxTree SyntaxTree;
internal readonly int ILMarker;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Cci = Microsoft.Cci;
namespace Microsoft.CodeAnalysis.CodeGen
{
......@@ -22,8 +16,6 @@ namespace Microsoft.CodeAnalysis.CodeGen
/// </summary>
internal class SequencePointList
{
internal const int HiddenSequencePointLine = 0xFEEFEE;
private readonly SyntaxTree _tree;
private readonly OffsetAndSpan[] _points;
private SequencePointList _next; // Linked list of all points.
......@@ -142,7 +134,7 @@ private static OffsetAndSpan[] GetSubArray(ArrayBuilder<RawSequencePoint> seqPoi
// a hidden sequence point.
bool isHidden = span == RawSequencePoint.HiddenSequencePointSpan;
FileLinePositionSpan fileLinePositionSpan = default(FileLinePositionSpan);
FileLinePositionSpan fileLinePositionSpan = default;
if (!isHidden)
{
fileLinePositionSpan = currentTree.GetMappedLineSpanAndVisibility(span, out isHidden);
......@@ -161,9 +153,9 @@ private static OffsetAndSpan[] GetSubArray(ArrayBuilder<RawSequencePoint> seqPoi
builder.Add(new Cci.SequencePoint(
lastDebugDocument,
offset: offsetAndSpan.Offset,
startLine: HiddenSequencePointLine,
startLine: Cci.SequencePoint.HiddenLine,
startColumn: 0,
endLine: HiddenSequencePointLine,
endLine: Cci.SequencePoint.HiddenLine,
endColumn: 0));
}
}
......@@ -178,13 +170,34 @@ private static OffsetAndSpan[] GetSubArray(ArrayBuilder<RawSequencePoint> seqPoi
if (lastDebugDocument != null)
{
int startLine = (fileLinePositionSpan.StartLinePosition.Line == -1) ? 0 : fileLinePositionSpan.StartLinePosition.Line + 1;
int endLine = (fileLinePositionSpan.EndLinePosition.Line == -1) ? 0 : fileLinePositionSpan.EndLinePosition.Line + 1;
int startColumn = fileLinePositionSpan.StartLinePosition.Character + 1;
int endColumn = fileLinePositionSpan.EndLinePosition.Character + 1;
// Trim column number if necessary.
// Column must be in range [0, 0xffff) and end column must be greater than start column if on the same line.
// The Portable PDB specifies 0x10000, but System.Reflection.Metadata reader has an off-by-one error.
// Windows PDBs allow the same range.
const int MaxColumn = ushort.MaxValue - 1;
if (startColumn > MaxColumn)
{
startColumn = (startLine == endLine) ? MaxColumn - 1 : MaxColumn;
}
if (endColumn > MaxColumn)
{
endColumn = MaxColumn;
}
builder.Add(new Cci.SequencePoint(
lastDebugDocument,
offset: offsetAndSpan.Offset,
startLine: (fileLinePositionSpan.StartLinePosition.Line == -1) ? 0 : fileLinePositionSpan.StartLinePosition.Line + 1,
startColumn: fileLinePositionSpan.StartLinePosition.Character + 1,
endLine: (fileLinePositionSpan.EndLinePosition.Line == -1) ? 0 : fileLinePositionSpan.EndLinePosition.Line + 1,
endColumn: fileLinePositionSpan.EndLinePosition.Character + 1
startLine: startLine,
startColumn: (ushort)startColumn,
endLine: endLine,
endColumn: (ushort)endColumn
));
}
}
......
......@@ -8,22 +8,24 @@ namespace Microsoft.Cci
{
[SuppressMessage("Performance", "CA1067", Justification = "Equality not actually implemented")]
[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
internal struct SequencePoint
internal readonly struct SequencePoint
{
public const int HiddenLine = 0xfeefee;
public readonly int Offset;
public readonly int StartLine;
public readonly int StartColumn;
public readonly int EndLine;
public readonly int EndColumn;
public readonly ushort StartColumn;
public readonly ushort EndColumn;
public readonly DebugSourceDocument Document;
public SequencePoint(
DebugSourceDocument document,
int offset,
int startLine,
int startColumn,
ushort startColumn,
int endLine,
int endColumn)
ushort endColumn)
{
Debug.Assert(document != null);
......@@ -35,7 +37,7 @@ internal struct SequencePoint
Document = document;
}
public bool IsHidden => StartLine == 0xfeefee;
public bool IsHidden => StartLine == HiddenLine;
public override int GetHashCode()
{
......
......@@ -758,7 +758,7 @@ internal static uint GetOffset(int methodToken, ISymUnmanagedReader symReader, i
{
var sequencePoints = symMethod.GetSequencePoints();
ilOffset = atLineNumber < 0
? sequencePoints.Where(sp => sp.StartLine != SequencePointList.HiddenSequencePointLine).Select(sp => sp.Offset).FirstOrDefault()
? sequencePoints.Where(sp => sp.StartLine != Cci.SequencePoint.HiddenLine).Select(sp => sp.Offset).FirstOrDefault()
: sequencePoints.First(sp => sp.StartLine == atLineNumber).Offset;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册