Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/Microsoft/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
manofstick committed Sep 1, 2016
2 parents 0149ef1 + 074b033 commit 639b46d
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 63 deletions.
19 changes: 10 additions & 9 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,9 @@ let rec GenTypeDefPass4 enc cenv (td:ILTypeDef) =
and GenTypeDefsPass4 enc cenv tds =
List.iter (GenTypeDefPass4 enc cenv) tds


let timestamp = absilWriteGetTimeStamp ()

// --------------------------------------------------------------------
// ILExportedTypesAndForwarders --> ILExportedTypeOrForwarder table
// --------------------------------------------------------------------
Expand Down Expand Up @@ -2888,7 +2891,7 @@ and GenManifestPass3 cenv m =
| None -> ()

and newGuid (modul: ILModuleDef) =
let n = absilWriteGetTimeStamp ()
let n = timestamp
let m = hash n
let m2 = hash modul.Name
[| 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 |]
Expand Down Expand Up @@ -2923,8 +2926,6 @@ let SortTableRows tab (rows:GenericRow[]) =
|> Array.ofList
//|> Array.map SharedRow

let timestamp = absilWriteGetTimeStamp ()

let GenModule (cenv : cenv) (modul: ILModuleDef) =
let midx = AddUnsharedRow cenv TableNames.Module (GetModuleAsRow cenv modul)
List.iter (GenResourcePass3 cenv) modul.Resources.AsList
Expand Down Expand Up @@ -3811,14 +3812,14 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
write (Some peFileHeaderChunk.addr) os "pe file header" [| |];

if (modul.Platform = Some(AMD64)) then
writeInt32AsUInt16 os 0x8664 // Machine - IMAGE_FILE_MACHINE_AMD64
writeInt32AsUInt16 os 0x8664 // Machine - IMAGE_FILE_MACHINE_AMD64
elif isItanium then
writeInt32AsUInt16 os 0x200
else
writeInt32AsUInt16 os 0x014c; // Machine - IMAGE_FILE_MACHINE_I386
writeInt32AsUInt16 os 0x014c; // Machine - IMAGE_FILE_MACHINE_I386

writeInt32AsUInt16 os numSections;
writeInt32 os timestamp; // date since 1970
writeInt32AsUInt16 os numSections;
writeInt32 os timestamp // date since 1970
writeInt32 os 0x00; // Pointer to Symbol Table Always 0
// 00000090
writeInt32 os 0x00; // Number of Symbols Always 0
Expand Down Expand Up @@ -4185,8 +4186,8 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
try
// write the IMAGE_DEBUG_DIRECTORY
os2.BaseStream.Seek (int64 (textV2P debugDirectoryChunk.addr), SeekOrigin.Begin) |> ignore
writeInt32 os2 idd.iddCharacteristics // IMAGE_DEBUG_DIRECTORY.Characteristics
writeInt32 os2 timestamp
writeInt32 os2 idd.iddCharacteristics // IMAGE_DEBUG_DIRECTORY.Characteristics
writeInt32 os2 idd.iddTimestamp
writeInt32AsUInt16 os2 idd.iddMajorVersion
writeInt32AsUInt16 os2 idd.iddMinorVersion
writeInt32 os2 idd.iddType
Expand Down
26 changes: 15 additions & 11 deletions src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,34 @@ type idd =
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddType: int32;
iddTimestamp: int32;
iddData: byte[];}

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

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

let offset, size = offset + size, mvid.Length // mvid Guid
let struct (offset, size) = struct (offset + size, mvid.Length) // mvid Guid
Buffer.BlockCopy(mvid, 0, buffer, offset, size)

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

let offset = offset + size // Path to pdb string
Buffer.BlockCopy(path, 0, buffer, offset, path.Length)
let struct (offset, size) = struct (offset + size, path.Length) // Path to pdb string
Buffer.BlockCopy(path, 0, buffer, offset, size)

buffer

{ iddCharacteristics = 0x0; // Reserved
iddMajorVersion = 0x0; // VersionMajor should be 0
iddMinorVersion = 0x0; // VersionMinor should be 0
iddType = 0x2; // IMAGE_DEBUG_TYPE_CODEVIEW
iddTimestamp = timestamp;
iddData = iddDataBuffer } // Path name to the pdb file when built

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

let s1, s2 = '/', '\\'
let separator = if (count name s1) >= (count name s2) then s1 else s2

let writer = new BlobBuilder()
writer.WriteByte(byte(separator))

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

metadata.GetOrAddBlob(writer);
metadata.GetOrAddBlob(writer)

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

let serializer = PortablePdbBuilder(metadata, externalRowCounts, entryPoint, null )
let serializer = PortablePdbBuilder(metadata, externalRowCounts, entryPoint, null)
let blobBuilder = new BlobBuilder()
serializer.Serialize(blobBuilder) |> ignore
let contentId= serializer.Serialize(blobBuilder)

reportTime showTimes "PDB: Created"
use portablePdbStream = new FileStream(fpdb, FileMode.Create, FileAccess.ReadWrite)
blobBuilder.WriteContentTo(portablePdbStream)
reportTime showTimes "PDB: Closed"
pdbGetDebugInfo info.ModuleID fpdb
pdbGetDebugInfo (contentId.Guid.ToByteArray()) (int32(contentId.Stamp)) fpdb

#if FX_NO_PDB_WRITER
#else
Expand Down Expand Up @@ -485,6 +488,7 @@ let writePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
iddMajorVersion = res.iddMajorVersion;
iddMinorVersion = res.iddMinorVersion;
iddType = res.iddType;
iddTimestamp = info.Timestamp;
iddData = res.iddData}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/absil/ilwritepdb.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type idd =
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddType: int32;
iddTimestamp: int32;
iddData: byte[]; }

val writePortablePdbInfo : fixupOverlappingSequencePoints:bool -> showTimes:bool -> fpdb:string -> info:PdbData -> idd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency id="System.Threading.Tasks.Parallel" version="4.0.1" />
<dependency id="System.Threading.Thread" version="4.0.0" />
<dependency id="System.Threading.ThreadPool" version="4.0.10" />
<dependency id="System.ValueTuple" version="4.0.1-beta-24405-03" />
<dependency id="System.ValueTuple" version="4.0.0-rc3-24212-01" />
<dependency id="Microsoft.DiaSymReader.PortablePdb" version="1.1.0" />
<dependency id="Microsoft.DiaSymReader" version="1.0.8" />
</group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,64 @@ type ArrayModule() =
let nullArr = null:string[]
CheckThrowsArgumentNullException (fun () -> Array.filter funcStr nullArr |> ignore)

()
()

[<Test>]
member this.Filter2 () =
// The Array.filter algorith uses a bitmask as a temporary storage mechanism
// for which elements to filter. This introduces some possible error conditions
// around how the filter is filled and subsequently used, so filter test
// does a pretty exhaustive test suite.
// It works by first generating arrays which consist of sequences of unique
// positive and negative numbers, as per arguments, it then filters for the
// positive values, and then compares the results agains the original array.

let makeTestArray size posLength negLength startWithPos startFromEnd =
let array = Array.zeroCreate size

let mutable sign = if startWithPos then 1 else -1
let mutable count = if startWithPos then posLength else negLength
for i = 1 to size do
let idx = if startFromEnd then size-i else i-1
array.[idx] <- (idx+1) * sign
count <- count - 1
if count <= 0 then
sign <- sign * -1
count <- if sign > 0 then posLength else negLength

array

let checkFilter filter (array:array<_>) =
let filtered = array |> filter (fun n -> n > 0)

let mutable idx = 0
for item in filtered do
while array.[idx] < item do
idx <- idx + 1
if item <> array.[idx] then
Assert.Fail ()
idx <- idx + 1
while idx < array.Length do
if array.[idx] > 0 then
Assert.Fail ()
idx <- idx + 1

let checkCombinations filter maxSize =
for size = 0 to maxSize do
for posLength = 1 to size do
for negLength = 1 to size do
for startWithPos in [true; false] do
for startFromEnd in [true; false] do
let testArray = makeTestArray size posLength negLength startWithPos startFromEnd
checkFilter filter testArray

// this could probably be a bit smaller, but needs to at least be > 64 to test chunk copying
// of data, and > 96 gives a safer feel, so settle on a nice decimal rounding of one hundred
// to appease those with digits.
let suitableTestMaxLength = 100

checkCombinations Array.filter suitableTestMaxLength



[<Test>]
Expand Down
Loading

0 comments on commit 639b46d

Please sign in to comment.