Skip to content

Commit 3f35532

Browse files
authored
Portable PDB generation did not emit sequence points and local variables correctly (#1516)
1 parent 71c8798 commit 3f35532

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/absil/ilwritepdb.fs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
249249
index.Add(doc.File, handle)
250250
index
251251

252+
let mutable lastLocalVariableHandle = Unchecked.defaultof<LocalVariableHandle>
252253
metadata.SetCapacity(TableIndex.MethodDebugInformation, info.Methods.Length)
253254
info.Methods |> Array.iteri (fun _i minfo ->
254255
let docHandle, sequencePointBlob =
@@ -272,26 +273,28 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
272273
// If part of the method body is in another document returns nil handle.
273274
let tryGetSingleDocumentIndex =
274275
let mutable singleDocumentIndex = 0
275-
for i in 1 .. sps.Length - 1 do
276+
for i in 0 .. sps.Length - 1 do
276277
let index = sps.[i].Document
277278
if index <> singleDocumentIndex then
278279
singleDocumentIndex <- index
279280
singleDocumentIndex
280281

281-
if sps.Length = 0 then
282+
// Filter out feefee (Hidden) sequence points
283+
let sps = sps |> Array.filter(fun sp -> sp.Line <> 0xfeefee && sp.EndLine <> 0xfeefee)
284+
285+
if sps.Length = 0 then
282286
Unchecked.defaultof<DocumentHandle>, Unchecked.defaultof<BlobHandle>
283287
else
284-
let builder = new BlobBuilder()
285-
builder.WriteCompressedInteger(minfo.LocalSignatureToken)
286-
287288
let mutable previousNonHiddenStartLine = -1
288289
let mutable previousNonHiddenStartColumn = -1
289290
let mutable previousDocumentIndex = -1
290291
let mutable singleDocumentIndex = tryGetSingleDocumentIndex
291292
let mutable currentDocumentIndex = previousDocumentIndex
292293

293-
for i in 0 .. (sps.Length - 1) do
294+
let builder = new BlobBuilder()
295+
builder.WriteCompressedInteger(minfo.LocalSignatureToken)
294296

297+
for i in 0 .. (sps.Length - 1) do
295298
if previousDocumentIndex <> currentDocumentIndex then
296299
// optional document in header or document record:
297300
if previousDocumentIndex <> -1 then
@@ -306,16 +309,9 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
306309
else
307310
builder.WriteCompressedInteger(sps.[i].Offset)
308311

309-
// F# does not support hidden sequence points yet !!!
310-
// if (sequencePoints[i].IsHidden)
311-
// {
312-
// builder.WriteInt16(0);
313-
// continue;
314-
// }
315-
316-
let deltaLines = sps.[i].EndLine - sps.[i].Line;
317-
let deltaColumns = sps.[i].EndColumn - sps.[i].Column;
318-
builder.WriteCompressedInteger(deltaLines);
312+
let deltaLines = sps.[i].EndLine - sps.[i].Line
313+
let deltaColumns = sps.[i].EndColumn - sps.[i].Column
314+
builder.WriteCompressedInteger(deltaLines)
319315

320316
if deltaLines = 0 then
321317
builder.WriteCompressedInteger(deltaColumns)
@@ -335,23 +331,30 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
335331

336332
getDocumentHandle singleDocumentIndex, metadata.GetOrAddBlob(builder)
337333

338-
// Write the scopes
339-
let mutable lastLocalVariableHandle = Unchecked.defaultof<LocalVariableHandle>
334+
// Write the scopes
340335
let nextHandle handle = MetadataTokens.LocalVariableHandle(MetadataTokens.GetRowNumber(LocalVariableHandle.op_Implicit(handle)) + 1)
341-
let rec writePdbScope top scope =
342-
if top || scope.Locals.Length <> 0 || scope.Children.Length <> 0 then
343-
lastLocalVariableHandle <- nextHandle lastLocalVariableHandle
336+
let rec writePdbScope scope =
337+
if scope.Children.Length = 0 then
338+
metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
339+
Unchecked.defaultof<ImportScopeHandle>,
340+
nextHandle lastLocalVariableHandle,
341+
Unchecked.defaultof<LocalConstantHandle>,
342+
0,
343+
scope.EndOffset - scope.StartOffset) |>ignore
344+
else
344345
metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
345-
Unchecked.defaultof<ImportScopeHandle>,
346-
lastLocalVariableHandle,
347-
Unchecked.defaultof<LocalConstantHandle>,
348-
scope.StartOffset,
349-
scope.EndOffset - scope.StartOffset) |>ignore
346+
Unchecked.defaultof<ImportScopeHandle>,
347+
nextHandle lastLocalVariableHandle,
348+
Unchecked.defaultof<LocalConstantHandle>,
349+
scope.StartOffset,
350+
scope.EndOffset - scope.StartOffset) |>ignore
351+
350352
for localVariable in scope.Locals do
351353
lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
352-
scope.Children |> Array.iter (writePdbScope false)
353354

354-
writePdbScope true minfo.RootScope
355+
scope.Children |> Array.iter (writePdbScope)
356+
357+
writePdbScope minfo.RootScope
355358
metadata.AddMethodDebugInformation(docHandle, sequencePointBlob) |> ignore)
356359

357360
let entryPoint =

0 commit comments

Comments
 (0)