Skip to content

Commit

Permalink
Emit sequence points in ascending offset order
Browse files Browse the repository at this point in the history
This is required by the Portable PDB specification, and the sequence
point collection in `MethodDebugInfo` does not guarantee it.

This also tweaks the writing of hidden sequence points to use two
writes of 0 as compressed unsigned integer, instead of a single
write of 0 as a plain short, to more closely match the specification.

Fixes jbevain#840.
  • Loading branch information
Zastai committed Jun 10, 2022
1 parent f7b64f7 commit 343cf93
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Mono.Cecil/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3302,8 +3302,15 @@ public void WriteSequencePoints (MethodDebugInformation info)
if (!info.TryGetUniqueDocument (out previous_document))
previous_document = null;

for (int i = 0; i < info.SequencePoints.Count; i++) {
var sequence_point = info.SequencePoints [i];
// The sequence points need to be emitted in strict ascending offset order, which is not guaranteed to be the case for
// info.SequencePoints.
var sequencePoints = new SortedDictionary<int, SequencePoint> ();
foreach (var sequence_point in info.SequencePoints) {
sequencePoints [sequence_point.Offset] = sequence_point;
}

var previous_offset = 0;
foreach (var sequence_point in sequencePoints.Values) {

var document = sequence_point.Document;
if (previous_document != document) {
Expand All @@ -3316,13 +3323,12 @@ public void WriteSequencePoints (MethodDebugInformation info)
previous_document = document;
}

if (i > 0)
WriteCompressedUInt32 ((uint) (sequence_point.Offset - info.SequencePoints [i - 1].Offset));
else
WriteCompressedUInt32 ((uint) sequence_point.Offset);
WriteCompressedUInt32 ((uint) (sequence_point.Offset - previous_offset));
previous_offset = sequence_point.Offset;

if (sequence_point.IsHidden) {
WriteInt16 (0);
WriteCompressedUInt32 (0);
WriteCompressedUInt32 (0);
continue;
}

Expand Down

0 comments on commit 343cf93

Please sign in to comment.