From 82202e6d3f453b39fc4d291f7d14c03f02306a13 Mon Sep 17 00:00:00 2001 From: rcj1 Date: Fri, 30 Jan 2026 18:08:53 -0800 Subject: [PATCH 1/4] fix mappings --- .../Compiler/DependencyAnalysis/MethodCodeNode.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs index f2853124566b34..014e8ebc9c9c03 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs @@ -263,7 +263,6 @@ public IEnumerable GetNativeSequencePoints() var sequencePoints = new (string Document, int LineNumber, bool IsBackedSequencePoint)[_debugLocInfos.Length * 4 /* chosen empirically */]; try { - int maxOffset = 0; foreach (var sequencePoint in _debugInfo.GetSequencePoints()) { int offset = sequencePoint.Offset; @@ -273,11 +272,10 @@ public IEnumerable GetNativeSequencePoints() Array.Resize(ref sequencePoints, newLength); } sequencePoints[offset] = (sequencePoint.Document, sequencePoint.LineNumber, true); - maxOffset = Math.Max(maxOffset, offset); } // Propagate last known document/line number forward to enable correct mapping when IL offsets decrease at higher native offsets - for (int i = 1; i <= maxOffset; i++) + for (int i = 1; i < sequencePoints.Length; i++) { if (sequencePoints[i].Document == null && sequencePoints[i - 1].Document != null) { @@ -294,7 +292,7 @@ public IEnumerable GetNativeSequencePoints() } int previousNativeOffset = -1; - int previousIlOffset = -1; + int maxIlOffset = -1; foreach (var nativeMapping in _debugLocInfos) { if (nativeMapping.NativeOffset == previousNativeOffset) @@ -306,7 +304,7 @@ public IEnumerable GetNativeSequencePoints() // Emit sequence point if we have it from _debugInfo or if ILOffset decreases. // This handles the case of IL offsets decreasing at higher native offsets. // See WalkILOffsetsCallback in src/coreclr/vm/debugdebugger.cpp for more details. - if ((sequencePoint.IsBackedSequencePoint || nativeMapping.ILOffset < previousIlOffset) && + if ((sequencePoint.IsBackedSequencePoint || nativeMapping.ILOffset <= maxIlOffset) && sequencePoint.Document != null) { yield return new NativeSequencePoint( @@ -314,8 +312,8 @@ public IEnumerable GetNativeSequencePoints() sequencePoint.Document, sequencePoint.LineNumber); previousNativeOffset = nativeMapping.NativeOffset; - previousIlOffset = nativeMapping.ILOffset; } + maxIlOffset = Math.Max(maxIlOffset, nativeMapping.ILOffset); } } } From b1cc0fcc9636ad5fa8757e3dd5fcfa7a5d74df10 Mon Sep 17 00:00:00 2001 From: rcj1 Date: Mon, 2 Feb 2026 11:52:44 -0800 Subject: [PATCH 2/4] code review --- .../StackTraceLineNumbersNode.cs | 8 ---- .../DependencyAnalysis/MethodCodeNode.cs | 38 +++++++++---------- .../JitInterface/CorInfoImpl.RyuJit.cs | 3 ++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs index a58c0af969d3d4..d919a9ce28d959 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs @@ -103,14 +103,6 @@ static Vertex CreateLineNumbersBlob(NativeWriter writer, StackTraceDocumentsNode foreach (NativeSequencePoint sequencePoint in debugInfoNode.GetNativeSequencePoints()) { - if (currentLineNumber == sequencePoint.LineNumber && currentDocument == sequencePoint.FileName) - continue; - - // Make sure a zero native offset delta is not possible because we use it below - // to indicate an update to the current document. - if (currentDocument != null && currentNativeOffset == sequencePoint.NativeOffset) - continue; - if (currentDocument != sequencePoint.FileName) { // We start with currentDocument == null, so the reader knows the first byte of the output diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs index 014e8ebc9c9c03..1086421c8a5fe7 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs @@ -260,7 +260,7 @@ public IEnumerable GetNativeSequencePoints() if (_debugLocInfos == null) yield break; - var sequencePoints = new (string Document, int LineNumber, bool IsBackedSequencePoint)[_debugLocInfos.Length * 4 /* chosen empirically */]; + var sequencePoints = new (string Document, int LineNumber)[_debugLocInfos.Length * 4 /* chosen empirically */]; try { foreach (var sequencePoint in _debugInfo.GetSequencePoints()) @@ -271,7 +271,7 @@ public IEnumerable GetNativeSequencePoints() int newLength = Math.Max(2 * sequencePoints.Length, sequencePoint.Offset + 1); Array.Resize(ref sequencePoints, newLength); } - sequencePoints[offset] = (sequencePoint.Document, sequencePoint.LineNumber, true); + sequencePoints[offset] = (sequencePoint.Document, sequencePoint.LineNumber); } // Propagate last known document/line number forward to enable correct mapping when IL offsets decrease at higher native offsets @@ -279,7 +279,7 @@ public IEnumerable GetNativeSequencePoints() { if (sequencePoints[i].Document == null && sequencePoints[i - 1].Document != null) { - sequencePoints[i] = (sequencePoints[i - 1].Document, sequencePoints[i - 1].LineNumber, false); + sequencePoints[i] = (sequencePoints[i - 1].Document, sequencePoints[i - 1].LineNumber); } } } @@ -292,28 +292,28 @@ public IEnumerable GetNativeSequencePoints() } int previousNativeOffset = -1; - int maxIlOffset = -1; + string previousDocument = null; + int previousLineNumber = -1; + // OffsetMapping is sorted in order of increasing native offset (but not necessarily by IL offset) foreach (var nativeMapping in _debugLocInfos) { + // Make sure we don't emit multiple sequence points for the same native offset + // Because CreateLineNumbersBlob uses zero deltas to indicate document changes. if (nativeMapping.NativeOffset == previousNativeOffset) continue; - if (nativeMapping.ILOffset < sequencePoints.Length) + var sequencePoint = sequencePoints[Math.Min(nativeMapping.ILOffset, sequencePoints.Length - 1)]; + // Emit sequence point if its line number or document differ from the previous one. + // See WalkILOffsetsCallback in src/coreclr/vm/debugdebugger.cpp for more details. + if (sequencePoint.Document != null && (sequencePoint.Document != previousDocument || sequencePoint.LineNumber != previousLineNumber)) { - var sequencePoint = sequencePoints[nativeMapping.ILOffset]; - // Emit sequence point if we have it from _debugInfo or if ILOffset decreases. - // This handles the case of IL offsets decreasing at higher native offsets. - // See WalkILOffsetsCallback in src/coreclr/vm/debugdebugger.cpp for more details. - if ((sequencePoint.IsBackedSequencePoint || nativeMapping.ILOffset <= maxIlOffset) && - sequencePoint.Document != null) - { - yield return new NativeSequencePoint( - nativeMapping.NativeOffset, - sequencePoint.Document, - sequencePoint.LineNumber); - previousNativeOffset = nativeMapping.NativeOffset; - } - maxIlOffset = Math.Max(maxIlOffset, nativeMapping.ILOffset); + yield return new NativeSequencePoint( + nativeMapping.NativeOffset, + sequencePoint.Document, + sequencePoint.LineNumber); + previousNativeOffset = nativeMapping.NativeOffset; + previousDocument = sequencePoint.Document; + previousLineNumber = sequencePoint.LineNumber; } } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index c64ff0f1b49699..c021c96173dffb 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -1048,6 +1048,9 @@ private void setBoundaries(CORINFO_METHOD_STRUCT_* ftn, uint cMap, OffsetMapping case (int)MappingTypes.NO_MAPPING: continue; } + // Ignore these; see WalkILOffsetsCallback in src/coreclr/vm/debugdebugger.cpp. + if (nativeToILInfo->source == SourceTypes.CALL_INSTRUCTION) + continue; debugLocInfos.Add(new DebugLocInfo((int)nativeToILInfo->nativeOffset, ilOffset)); } From 93769ccf4faf7a41454c36afc759a03471476df8 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 2 Feb 2026 13:58:18 -0800 Subject: [PATCH 3/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Strehovský --- .../Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs index d919a9ce28d959..2d4ca78b1f40fd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs @@ -103,6 +103,9 @@ static Vertex CreateLineNumbersBlob(NativeWriter writer, StackTraceDocumentsNode foreach (NativeSequencePoint sequencePoint in debugInfoNode.GetNativeSequencePoints()) { + // Make sure a zero native offset delta is not possible because we use it below + // to indicate an update to the current document. + Debug.Assert(currentDocument == null || currentNativeOffset != sequencePoint.NativeOffset); if (currentDocument != sequencePoint.FileName) { // We start with currentDocument == null, so the reader knows the first byte of the output From 0ea536380aabf4fd020306d4f597c67d181054db Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 2 Feb 2026 14:26:11 -0800 Subject: [PATCH 4/4] Update src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Strehovský --- .../Compiler/DependencyAnalysis/MethodCodeNode.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs index 1086421c8a5fe7..7681e8c062dc27 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs @@ -297,8 +297,6 @@ public IEnumerable GetNativeSequencePoints() // OffsetMapping is sorted in order of increasing native offset (but not necessarily by IL offset) foreach (var nativeMapping in _debugLocInfos) { - // Make sure we don't emit multiple sequence points for the same native offset - // Because CreateLineNumbersBlob uses zero deltas to indicate document changes. if (nativeMapping.NativeOffset == previousNativeOffset) continue;