Skip to content

Commit 6fd485d

Browse files
authored
Merge pull request #1501 from Microsoft/compilerdeployment
Fix portable pdb debugging
2 parents 3951da6 + f4eab74 commit 6fd485d

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

src/absil/ilwrite.fs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,9 @@ let rec GenTypeDefPass4 enc cenv (td:ILTypeDef) =
28072807
and GenTypeDefsPass4 enc cenv tds =
28082808
List.iter (GenTypeDefPass4 enc cenv) tds
28092809

2810+
2811+
let timestamp = absilWriteGetTimeStamp ()
2812+
28102813
// --------------------------------------------------------------------
28112814
// ILExportedTypesAndForwarders --> ILExportedTypeOrForwarder table
28122815
// --------------------------------------------------------------------
@@ -2888,7 +2891,7 @@ and GenManifestPass3 cenv m =
28882891
| None -> ()
28892892

28902893
and newGuid (modul: ILModuleDef) =
2891-
let n = absilWriteGetTimeStamp ()
2894+
let n = timestamp
28922895
let m = hash n
28932896
let m2 = hash modul.Name
28942897
[| b0 m; b1 m; b2 m; b3 m; b0 m2; b1 m2; b2 m2; b3 m2; 0xa7uy; 0x45uy; 0x03uy; 0x83uy; b0 n; b1 n; b2 n; b3 n |]
@@ -2923,8 +2926,6 @@ let SortTableRows tab (rows:GenericRow[]) =
29232926
|> Array.ofList
29242927
//|> Array.map SharedRow
29252928

2926-
let timestamp = absilWriteGetTimeStamp ()
2927-
29282929
let GenModule (cenv : cenv) (modul: ILModuleDef) =
29292930
let midx = AddUnsharedRow cenv TableNames.Module (GetModuleAsRow cenv modul)
29302931
List.iter (GenResourcePass3 cenv) modul.Resources.AsList
@@ -3811,14 +3812,14 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
38113812
write (Some peFileHeaderChunk.addr) os "pe file header" [| |];
38123813

38133814
if (modul.Platform = Some(AMD64)) then
3814-
writeInt32AsUInt16 os 0x8664 // Machine - IMAGE_FILE_MACHINE_AMD64
3815+
writeInt32AsUInt16 os 0x8664 // Machine - IMAGE_FILE_MACHINE_AMD64
38153816
elif isItanium then
38163817
writeInt32AsUInt16 os 0x200
38173818
else
3818-
writeInt32AsUInt16 os 0x014c; // Machine - IMAGE_FILE_MACHINE_I386
3819+
writeInt32AsUInt16 os 0x014c; // Machine - IMAGE_FILE_MACHINE_I386
38193820

3820-
writeInt32AsUInt16 os numSections;
3821-
writeInt32 os timestamp; // date since 1970
3821+
writeInt32AsUInt16 os numSections;
3822+
writeInt32 os timestamp // date since 1970
38223823
writeInt32 os 0x00; // Pointer to Symbol Table Always 0
38233824
// 00000090
38243825
writeInt32 os 0x00; // Number of Symbols Always 0
@@ -4185,8 +4186,8 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
41854186
try
41864187
// write the IMAGE_DEBUG_DIRECTORY
41874188
os2.BaseStream.Seek (int64 (textV2P debugDirectoryChunk.addr), SeekOrigin.Begin) |> ignore
4188-
writeInt32 os2 idd.iddCharacteristics // IMAGE_DEBUG_DIRECTORY.Characteristics
4189-
writeInt32 os2 timestamp
4189+
writeInt32 os2 idd.iddCharacteristics // IMAGE_DEBUG_DIRECTORY.Characteristics
4190+
writeInt32 os2 idd.iddTimestamp
41904191
writeInt32AsUInt16 os2 idd.iddMajorVersion
41914192
writeInt32AsUInt16 os2 idd.iddMinorVersion
41924193
writeInt32 os2 idd.iddType

src/absil/ilwritepdb.fs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,34 @@ type idd =
9595
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
9696
iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
9797
iddType: int32;
98+
iddTimestamp: int32;
9899
iddData: byte[];}
99100

100101
let magicNumber = 0x53445352L
101-
let pdbGetDebugInfo (mvid:byte[]) (filepath:string) =
102+
let pdbGetDebugInfo (mvid:byte[]) (timestamp:int32) (filepath:string) =
102103
let iddDataBuffer =
103104
let path = (System.Text.Encoding.UTF8.GetBytes filepath)
104105
let buffer = Array.zeroCreate (sizeof<int32> + mvid.Length + sizeof<int32> + path.Length + 1)
105106

106-
let offset, size = 0, sizeof<int32> // Magic Number RSDS dword: 0x53445352L
107+
let struct (offset, size) = struct(0, sizeof<int32>) // Magic Number RSDS dword: 0x53445352L
107108
Buffer.BlockCopy(BitConverter.GetBytes(magicNumber), 0, buffer, offset, size)
108109

109-
let offset, size = offset + size, mvid.Length // mvid Guid
110+
let struct (offset, size) = struct (offset + size, mvid.Length) // mvid Guid
110111
Buffer.BlockCopy(mvid, 0, buffer, offset, size)
111112

112-
let offset, size = offset + size, sizeof<int32> // # of pdb files generated (1)
113+
let struct (offset, size) = struct (offset + size, sizeof<int32>) // # of pdb files generated (1)
113114
Buffer.BlockCopy(BitConverter.GetBytes(1), 0, buffer, offset, size)
114115

115-
let offset = offset + size // Path to pdb string
116-
Buffer.BlockCopy(path, 0, buffer, offset, path.Length)
116+
let struct (offset, size) = struct (offset + size, path.Length) // Path to pdb string
117+
Buffer.BlockCopy(path, 0, buffer, offset, size)
118+
117119
buffer
118120

119121
{ iddCharacteristics = 0x0; // Reserved
120122
iddMajorVersion = 0x0; // VersionMajor should be 0
121123
iddMinorVersion = 0x0; // VersionMinor should be 0
122124
iddType = 0x2; // IMAGE_DEBUG_TYPE_CODEVIEW
125+
iddTimestamp = timestamp;
123126
iddData = iddDataBuffer } // Path name to the pdb file when built
124127

125128
// Document checksum algorithms
@@ -215,15 +218,15 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
215218

216219
let s1, s2 = '/', '\\'
217220
let separator = if (count name s1) >= (count name s2) then s1 else s2
218-
221+
219222
let writer = new BlobBuilder()
220223
writer.WriteByte(byte(separator))
221224

222225
for part in name.Split( [| separator |] ) do
223226
let partIndex = MetadataTokens.GetHeapOffset(BlobHandle.op_Implicit(metadata.GetOrAddBlobUTF8(part)))
224227
writer.WriteCompressedInteger(int(partIndex))
225228

226-
metadata.GetOrAddBlob(writer);
229+
metadata.GetOrAddBlob(writer)
227230

228231
let corSymLanguageTypeFSharp = System.Guid(0xAB4F38C9u, 0xB6E6us, 0x43baus, 0xBEuy, 0x3Buy, 0x58uy, 0x08uy, 0x0Buy, 0x2Cuy, 0xCCuy, 0xE3uy)
229232
let documentIndex =
@@ -356,15 +359,15 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
356359
| None -> MetadataTokens.MethodDefinitionHandle(0)
357360
| Some x -> MetadataTokens.MethodDefinitionHandle(x)
358361

359-
let serializer = PortablePdbBuilder(metadata, externalRowCounts, entryPoint, null )
362+
let serializer = PortablePdbBuilder(metadata, externalRowCounts, entryPoint, null)
360363
let blobBuilder = new BlobBuilder()
361-
serializer.Serialize(blobBuilder) |> ignore
364+
let contentId= serializer.Serialize(blobBuilder)
362365

363366
reportTime showTimes "PDB: Created"
364367
use portablePdbStream = new FileStream(fpdb, FileMode.Create, FileAccess.ReadWrite)
365368
blobBuilder.WriteContentTo(portablePdbStream)
366369
reportTime showTimes "PDB: Closed"
367-
pdbGetDebugInfo info.ModuleID fpdb
370+
pdbGetDebugInfo (contentId.Guid.ToByteArray()) (int32(contentId.Stamp)) fpdb
368371

369372
#if FX_NO_PDB_WRITER
370373
#else
@@ -485,6 +488,7 @@ let writePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
485488
iddMajorVersion = res.iddMajorVersion;
486489
iddMinorVersion = res.iddMinorVersion;
487490
iddType = res.iddType;
491+
iddTimestamp = info.Timestamp;
488492
iddData = res.iddData}
489493
#endif
490494

src/absil/ilwritepdb.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type idd =
7272
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
7373
iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
7474
iddType: int32;
75+
iddTimestamp: int32;
7576
iddData: byte[]; }
7677

7778
val writePortablePdbInfo : fixupOverlappingSequencePoints:bool -> showTimes:bool -> fpdb:string -> info:PdbData -> idd

tests/fsharp/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"System.Threading.Thread": "4.0.0",
3434
"System.Threading.ThreadPool": "4.0.10",
3535
"System.Threading.Timer": "4.0.1",
36+
"System.ValueTuple": "4.0.0-rc3-24212-01",
3637

3738
"Microsoft.DiaSymReader.PortablePdb": "1.1.0",
3839
"Microsoft.DiaSymReader": "1.0.8",

0 commit comments

Comments
 (0)