1 From a7ac2facce91c15940e466f67a4ba9a31f687a1a Mon Sep 17 00:00:00 2001
2 From: Kevin Ransom <kevinr@microsoft.com>
3 Date: Sun, 3 Sep 2017 17:00:18 -0700
4 Subject: [PATCH 1/3] Fix MethodDebugTable for portablePDBs
7 src/absil/ilwritepdb.fs | 27 ++++++++++++++-------------
8 1 file changed, 14 insertions(+), 13 deletions(-)
10 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
11 index 009d39f653..3d68edee38 100644
12 --- a/src/absil/ilwritepdb.fs
13 +++ b/src/absil/ilwritepdb.fs
14 @@ -330,17 +330,22 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
15 | None -> Array.empty<PdbSequencePoint>
16 | Some (_,_) -> minfo.SequencePoints
18 - let getDocumentHandle d =
19 - if docs.Length = 0 || d < 0 || d > docs.Length then
20 - Unchecked.defaultof<DocumentHandle>
22 - match documentIndex.TryGetValue(docs.[d].File) with
23 - | false, _ -> Unchecked.defaultof<DocumentHandle>
26 - if sps.Length = 0 then
27 + let builder = new BlobBuilder()
28 + builder.WriteCompressedInteger(minfo.LocalSignatureToken)
30 + if sps = Array.empty then
31 + builder.WriteCompressedInteger( 0 )
32 + builder.WriteCompressedInteger( 0 )
33 Unchecked.defaultof<DocumentHandle>, Unchecked.defaultof<BlobHandle>
35 + let getDocumentHandle d =
36 + if docs.Length = 0 || d < 0 || d > docs.Length then
37 + Unchecked.defaultof<DocumentHandle>
39 + match documentIndex.TryGetValue(docs.[d].File) with
40 + | false, _ -> Unchecked.defaultof<DocumentHandle>
43 // Return a document that the entire method body is declared within.
44 // If part of the method body is in another document returns nil handle.
45 let tryGetSingleDocumentIndex =
46 @@ -350,12 +355,8 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
47 singleDocumentIndex <- -1
50 - let builder = new BlobBuilder()
51 - builder.WriteCompressedInteger(minfo.LocalSignatureToken)
53 // Initial document: When sp's spread over more than one document we put the initial document here.
54 let singleDocumentIndex = tryGetSingleDocumentIndex
56 if singleDocumentIndex = -1 then
57 builder.WriteCompressedInteger( MetadataTokens.GetRowNumber(DocumentHandle.op_Implicit(getDocumentHandle (sps.[0].Document))) )
60 From 01d3e175e7e5c8c554c92bf121adba44e1287f9a Mon Sep 17 00:00:00 2001
61 From: Kevin Ransom <kevinr@microsoft.com>
62 Date: Tue, 5 Sep 2017 02:59:55 -0700
63 Subject: [PATCH 2/3] ensure that pdb gets a record for abstract methods
66 src/absil/ilread.fs | 1 -
67 src/absil/ilsupp.fs | 3 --
68 src/absil/ilsupp.fsi | 1 -
69 src/absil/ilwrite.fs | 17 +++++--
70 src/absil/ilwritepdb.fs | 113 ++++++++++++++++++++++++++---------------------
71 src/absil/ilwritepdb.fsi | 2 +-
72 6 files changed, 77 insertions(+), 60 deletions(-)
74 diff --git a/src/absil/ilread.fs b/src/absil/ilread.fs
75 index c7a435291c..2d42a6abd8 100644
76 --- a/src/absil/ilread.fs
77 +++ b/src/absil/ilread.fs
78 @@ -2903,7 +2903,6 @@ and seekReadMethodRVA ctxt (idx,nm,_internalcall,noinline,aggressiveinline,numty
81 let pdbm = pdbReaderGetMethod pdbr (uncodedToken TableNames.Method idx)
82 - //let rootScope = pdbMethodGetRootScope pdbm
83 let sps = pdbMethodGetSequencePoints pdbm
84 (*dprintf "#sps for 0x%x = %d\n" (uncodedToken TableNames.Method idx) (Array.length sps) *)
85 (* let roota,rootb = pdbScopeGetOffsets rootScope in *)
86 diff --git a/src/absil/ilsupp.fs b/src/absil/ilsupp.fs
87 index c95480bc06..66a1a6aa16 100644
88 --- a/src/absil/ilsupp.fs
89 +++ b/src/absil/ilsupp.fs
90 @@ -1230,9 +1230,6 @@ let pdbMethodGetToken (meth:PdbMethod) : int32 =
91 let token = meth.symMethod.Token
94 -let pdbMethodGetRootScope (meth:PdbMethod) : PdbMethodScope =
95 - { symScope = meth.symMethod.RootScope }
97 let pdbMethodGetSequencePoints (meth:PdbMethod) : PdbSequencePoint array =
98 let pSize = meth.symMethod.SequencePointCount
99 let offsets = Array.zeroCreate pSize
100 diff --git a/src/absil/ilsupp.fsi b/src/absil/ilsupp.fsi
101 index 15da0aa215..3a3748c6d2 100644
102 --- a/src/absil/ilsupp.fsi
103 +++ b/src/absil/ilsupp.fsi
104 @@ -73,7 +73,6 @@ val pdbDocumentGetLanguageVendor: PdbDocument -> byte[] (* guid *)
105 val pdbDocumentFindClosestLine: PdbDocument -> int -> int
107 val pdbMethodGetToken: PdbMethod -> int32
108 -val pdbMethodGetRootScope: PdbMethod -> PdbMethodScope
109 val pdbMethodGetSequencePoints: PdbMethod -> PdbSequencePoint array
111 val pdbScopeGetChildren: PdbMethodScope -> PdbMethodScope array
112 diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs
113 index 838b78783b..3b10ff4340 100644
114 --- a/src/absil/ilwrite.fs
115 +++ b/src/absil/ilwrite.fs
116 @@ -2577,7 +2577,7 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
118 LocalSignatureToken=localToken
119 Params= [| |] (* REVIEW *)
120 - RootScope = rootScope
121 + RootScope = Some rootScope
123 match ilmbody.SourceMarker with
124 | Some m when cenv.generatePdb ->
125 @@ -2592,9 +2592,20 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
126 Column=m.EndColumn })
128 SequencePoints=seqpoints }
133 + | MethodBody.Abstract ->
134 + // Now record the PDB record for this method - we write this out later.
135 + if cenv.generatePdb then
137 + { MethToken = getUncodedToken TableNames.Method midx
139 + LocalSignatureToken = 0x0 // No locals it's abstract
143 + SequencePoints = [| |] }
145 | MethodBody.Native ->
146 failwith "cannot write body of native method - Abstract IL cannot roundtrip mixed native/managed binaries"
148 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
149 index 3d68edee38..996110e9b7 100644
150 --- a/src/absil/ilwritepdb.fs
151 +++ b/src/absil/ilwritepdb.fs
152 @@ -81,7 +81,7 @@ type PdbMethodData =
154 LocalSignatureToken: int32
155 Params: PdbLocalVar array
156 - RootScope: PdbMethodScope
157 + RootScope: PdbMethodScope option
158 Range: (PdbSourceLoc * PdbSourceLoc) option
159 SequencePoints: PdbSequencePoint array }
161 @@ -224,7 +224,7 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
162 let externalRowCounts = getRowCounts info.TableRowCounts
164 match info.Documents with
165 - | null -> Array.empty<PdbDocumentData>
166 + | null -> Array.empty
167 | _ -> info.Documents
169 let metadata = MetadataBuilder()
170 @@ -324,16 +324,16 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
171 let docHandle, sequencePointBlob =
173 match minfo.SequencePoints with
174 - | null -> Array.empty<PdbSequencePoint>
175 + | null -> Array.empty
177 match minfo.Range with
178 - | None -> Array.empty<PdbSequencePoint>
179 + | None -> Array.empty
180 | Some (_,_) -> minfo.SequencePoints
182 let builder = new BlobBuilder()
183 builder.WriteCompressedInteger(minfo.LocalSignatureToken)
185 - if sps = Array.empty then
186 + if sps.Length = 0 then
187 builder.WriteCompressedInteger( 0 )
188 builder.WriteCompressedInteger( 0 )
189 Unchecked.defaultof<DocumentHandle>, Unchecked.defaultof<BlobHandle>
190 @@ -407,38 +407,41 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
192 let nextHandle handle = MetadataTokens.LocalVariableHandle(MetadataTokens.GetRowNumber(LocalVariableHandle.op_Implicit(handle)) + 1)
193 let writeMethodScope scope =
194 - let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
195 - if scope1.StartOffset > scope2.StartOffset then 1
196 - elif scope1.StartOffset < scope2.StartOffset then -1
197 - elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
198 - elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
201 - let collectScopes scope =
202 - let list = new List<PdbMethodScope>()
203 - let rec toList scope =
205 - scope.Children |> Seq.iter(fun s -> toList s)
207 - list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
209 - collectScopes scope |> Seq.iter(fun s ->
210 - if s.Children.Length = 0 then
211 - metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
212 - Unchecked.defaultof<ImportScopeHandle>,
213 - nextHandle lastLocalVariableHandle,
214 - Unchecked.defaultof<LocalConstantHandle>,
215 - 0, s.EndOffset - s.StartOffset ) |>ignore
217 - metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
218 - Unchecked.defaultof<ImportScopeHandle>,
219 - nextHandle lastLocalVariableHandle,
220 - Unchecked.defaultof<LocalConstantHandle>,
221 - s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
223 - for localVariable in s.Locals do
224 - lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
228 + let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
229 + if scope1.StartOffset > scope2.StartOffset then 1
230 + elif scope1.StartOffset < scope2.StartOffset then -1
231 + elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
232 + elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
235 + let collectScopes scope =
236 + let list = new List<PdbMethodScope>()
237 + let rec toList scope =
239 + scope.Children |> Seq.iter(fun s -> toList s)
241 + list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
243 + collectScopes scope |> Seq.iter(fun s ->
244 + if s.Children.Length = 0 then
245 + metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
246 + Unchecked.defaultof<ImportScopeHandle>,
247 + nextHandle lastLocalVariableHandle,
248 + Unchecked.defaultof<LocalConstantHandle>,
249 + 0, s.EndOffset - s.StartOffset ) |>ignore
251 + metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
252 + Unchecked.defaultof<ImportScopeHandle>,
253 + nextHandle lastLocalVariableHandle,
254 + Unchecked.defaultof<LocalConstantHandle>,
255 + s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
257 + for localVariable in s.Locals do
258 + lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
261 writeMethodScope minfo.RootScope )
264 @@ -554,18 +557,20 @@ let writePdbInfo showTimes f fpdb info cvChunk =
267 let rec writePdbScope parent sco =
268 - if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
269 - // Only nest scopes if the child scope is a different size from
272 - | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
274 - if nested then pdbOpenScope !pdbw sco.StartOffset
275 - sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
276 - sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
277 - if nested then pdbCloseScope !pdbw sco.EndOffset
279 - writePdbScope None minfo.RootScope
280 + if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
281 + // Only nest scopes if the child scope is a different size from
284 + | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
286 + if nested then pdbOpenScope !pdbw sco.StartOffset
287 + sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
288 + sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
289 + if nested then pdbCloseScope !pdbw sco.EndOffset
291 + match minfo.RootScope with
293 + | Some rootscope -> writePdbScope None rootscope
296 reportTime showTimes "PDB: Wrote methods"
297 @@ -675,7 +680,10 @@ let writeMdbInfo fmdb f info =
298 for child in scope.Children do
300 wr?CloseScope(scope.EndOffset)
301 - writeScope(meth.RootScope)
302 + match meth.RootScope with
304 + | Some rootscope -> writeScope(rootscope)
307 // Finished generating debug information for the curretn method
309 @@ -722,5 +730,8 @@ let logDebugInfo (outfile:string) (info:PdbData) =
310 if scope.Locals.Length > 0 then
311 fprintfn sw " %s Locals: %A" offs [ for p in scope.Locals -> sprintf "%d: %s" p.Index p.Name ]
312 for child in scope.Children do writeScope (offs + " ") child
313 - writeScope "" meth.RootScope
315 + match meth.RootScope with
317 + | Some rootscope -> writeScope "" rootscope
319 diff --git a/src/absil/ilwritepdb.fsi b/src/absil/ilwritepdb.fsi
320 index e5d1c8d03a..af9f16be9e 100644
321 --- a/src/absil/ilwritepdb.fsi
322 +++ b/src/absil/ilwritepdb.fsi
323 @@ -44,7 +44,7 @@ type PdbMethodData =
325 LocalSignatureToken: int32
326 Params: PdbLocalVar array
327 - RootScope: PdbMethodScope
328 + RootScope: PdbMethodScope option
329 Range: (PdbSourceLoc * PdbSourceLoc) option
330 SequencePoints: PdbSequencePoint array }
333 From 64ecadb27b24c1486610deb32c3044ad0b3449ae Mon Sep 17 00:00:00 2001
334 From: Kevin Ransom <kevinr@microsoft.com>
335 Date: Tue, 5 Sep 2017 03:13:04 -0700
336 Subject: [PATCH 3/3] minimise diff
339 src/absil/ilwritepdb.fs | 92 ++++++++++++++++++++++++-------------------------
340 1 file changed, 46 insertions(+), 46 deletions(-)
342 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
343 index 996110e9b7..f8baa3aea4 100644
344 --- a/src/absil/ilwritepdb.fs
345 +++ b/src/absil/ilwritepdb.fs
346 @@ -407,42 +407,42 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
348 let nextHandle handle = MetadataTokens.LocalVariableHandle(MetadataTokens.GetRowNumber(LocalVariableHandle.op_Implicit(handle)) + 1)
349 let writeMethodScope scope =
352 - let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
353 - if scope1.StartOffset > scope2.StartOffset then 1
354 - elif scope1.StartOffset < scope2.StartOffset then -1
355 - elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
356 - elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
359 - let collectScopes scope =
360 - let list = new List<PdbMethodScope>()
361 - let rec toList scope =
363 - scope.Children |> Seq.iter(fun s -> toList s)
365 - list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
367 - collectScopes scope |> Seq.iter(fun s ->
368 - if s.Children.Length = 0 then
369 - metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
370 - Unchecked.defaultof<ImportScopeHandle>,
371 - nextHandle lastLocalVariableHandle,
372 - Unchecked.defaultof<LocalConstantHandle>,
373 - 0, s.EndOffset - s.StartOffset ) |>ignore
375 - metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
376 - Unchecked.defaultof<ImportScopeHandle>,
377 - nextHandle lastLocalVariableHandle,
378 - Unchecked.defaultof<LocalConstantHandle>,
379 - s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
381 - for localVariable in s.Locals do
382 - lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
385 - writeMethodScope minfo.RootScope )
386 + let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
387 + if scope1.StartOffset > scope2.StartOffset then 1
388 + elif scope1.StartOffset < scope2.StartOffset then -1
389 + elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
390 + elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
393 + let collectScopes scope =
394 + let list = new List<PdbMethodScope>()
395 + let rec toList scope =
397 + scope.Children |> Seq.iter(fun s -> toList s)
399 + list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
401 + collectScopes scope |> Seq.iter(fun s ->
402 + if s.Children.Length = 0 then
403 + metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
404 + Unchecked.defaultof<ImportScopeHandle>,
405 + nextHandle lastLocalVariableHandle,
406 + Unchecked.defaultof<LocalConstantHandle>,
407 + 0, s.EndOffset - s.StartOffset ) |>ignore
409 + metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
410 + Unchecked.defaultof<ImportScopeHandle>,
411 + nextHandle lastLocalVariableHandle,
412 + Unchecked.defaultof<LocalConstantHandle>,
413 + s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
415 + for localVariable in s.Locals do
416 + lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
419 + match minfo.RootScope with
421 + | Some scope -> writeMethodScope scope )
424 match info.EntryPoint with
425 @@ -557,16 +557,16 @@ let writePdbInfo showTimes f fpdb info cvChunk =
428 let rec writePdbScope parent sco =
429 - if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
430 - // Only nest scopes if the child scope is a different size from
433 - | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
435 - if nested then pdbOpenScope !pdbw sco.StartOffset
436 - sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
437 - sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
438 - if nested then pdbCloseScope !pdbw sco.EndOffset
439 + if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
440 + // Only nest scopes if the child scope is a different size from
443 + | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
445 + if nested then pdbOpenScope !pdbw sco.StartOffset
446 + sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
447 + sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
448 + if nested then pdbCloseScope !pdbw sco.EndOffset
450 match minfo.RootScope with