Skip to content

Commit

Permalink
ctaggart#35 fixed the ISymUnmanagedDocument imports
Browse files Browse the repository at this point in the history
exposed .SourceFilePath, .Checksum
standardized FSharp.targets includes
  • Loading branch information
Cameron Taggart authored and Chet Husk committed Nov 25, 2014
1 parent a15317b commit 1939a81
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 64 deletions.
7 changes: 2 additions & 5 deletions Build/Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>Build</Name>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -159,10 +159,7 @@
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<PropertyGroup>
<PostBuildEvent>
if not exist "$(TargetDir)NativeBinaries" md "$(TargetDir)NativeBinaries"
Expand Down
11 changes: 4 additions & 7 deletions ConsoleTest/ConsoleTest.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>ConsoleTest</Name>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -25,7 +25,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -37,7 +37,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
Expand Down Expand Up @@ -377,10 +377,7 @@
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<PropertyGroup>
<PostBuildEvent>
if not exist "$(TargetDir)NativeBinaries" md "$(TargetDir)NativeBinaries"
Expand Down
18 changes: 8 additions & 10 deletions ConsoleTest/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ let printPdbDocuments() =
let symbolCache = SymbolCache @"C:\tmp\cache"
let pdbReader = symbolCache.ReadPdb s pdbSourceLink

let symbolReader = ISymbolReader.Create pdbReader.Reader
for d in symbolReader.GetDocuments() do
printfn "\npdb original source file path: %s" d.URL
printfn "it had an md5 checksum of: %s" (d.GetCheckSum() |> Hex.encode)
let url = pdbReader.GetDownloadUrl d.URL
for d in pdbReader.Documents do
printfn "\npdb original source file path: %s" d.SourceFilePath
printfn "it had an md5 checksum of: %s" d.ChecksumHex
let url = pdbReader.GetDownloadUrl d.SourceFilePath |> Option.get
printfn "has download url if source indexed: %A" url
// let downloadedFile = symbolCache.DownloadFile url
// printfn "downloaded the file to the cache %s" downloadedFile
// printfn "downloaded file has md5 of: %s" (Crypto.hashMD5 downloadedFile |> Hex.encode)
()
let downloadedFile = symbolCache.DownloadFile url
printfn "downloaded the file to the cache %s" downloadedFile
printfn "downloaded file has md5 of: %s" (Crypto.hashMD5 downloadedFile |> Hex.encode)

let printMethods() =
let dll = Assembly.LoadFrom @"..\..\..\packages\SourceLink.SymbolStore\lib\net45\SourceLink.SymbolStore.dll"
Expand Down Expand Up @@ -87,5 +85,5 @@ let printMethodsFileLines() =
[<EntryPoint>]
let main argv =
printPdbDocuments()
printMethodsFileLines()
// printMethodsFileLines()
0
3 changes: 3 additions & 0 deletions CorSym/CorSym.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
<ItemGroup>
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
<None Include="corsym.h" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
30 changes: 17 additions & 13 deletions CorSym/ISymUnmanagedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

using System;
using System.Runtime.InteropServices;
using System.Text;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore.CorSym
{
[ComVisible(false)]
[Guid("40DE4037-7C81-3E1E-B022-AE1ABFF2CA08")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
// COM interface method order is important. These methods must match:
// https://github.com/ctaggart/SourceLink/blob/8e4a3a5d2c4c9b9179b23d2be560ecf8822f9d22/CorSym/corsym.h#L895-L944

[ ComImport, Guid("40DE4037-7C81-3E1E-B022-AE1ABFF2CA08"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComVisible(false) ]
public interface ISymUnmanagedDocument
{
int __FindClosestLine(int line, out int pRetVal);
int __GetCheckSum(int cData, out int pcData, byte[] data);
int __GetCheckSumAlgorithmId(ref Guid pRetVal);
int __GetDocumentType(ref Guid pRetVal);
int __GetLanguage(ref Guid pRetVal);
int __GetLanguageVendor(ref Guid pRetVal);
int __GetSourceLength(out int pRetVal);
int __GetSourceRange(int startLine, int startColumn, int endLine, int endColumn, int cSourceBytes, out int pcSourceBytes, byte[] source);
int __GetURL(int cchUrl, out int pcchUrl, IntPtr szUrl);
int __HasEmbeddedSource(out bool pRetVal);
void GetURL(int cchUrl, out int pcchUrl, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder szUrl);
void GetDocumentType(ref Guid pRetVal);
void GetLanguage(ref Guid pRetVal);
void GetLanguageVendor(ref Guid pRetVal);
void GetCheckSumAlgorithmId(ref Guid pRetVal);
void GetCheckSum(int cData, out int pcData, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] byte[] data);
void FindClosestLine(int line, out int pRetVal);
void HasEmbeddedSource(out bool pRetVal);
void GetSourceLength(out int pRetVal);
void GetSourceRange(int startLine, int startColumn, int endLine, int endColumn, int cSourceBytes, out int pcSourceBytes,
[In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] byte[] source);
}
}
7 changes: 2 additions & 5 deletions Fake/Fake.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Fake</Name>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -58,8 +58,5 @@
<None Include="build.cmd" />
<None Include="build.sh" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
</Project>
9 changes: 4 additions & 5 deletions Git/Git.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Git</Name>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -24,6 +24,7 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<NoWarn>2003</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -33,11 +34,9 @@
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\SourceLink.Git.xml</DocumentationFile>
<NoWarn>2003</NoWarn>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
<Choose>
Expand Down
7 changes: 2 additions & 5 deletions Pe/Pe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>Pe</Name>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -35,10 +35,7 @@
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
<Choose>
Expand Down
7 changes: 2 additions & 5 deletions SourceLink/SourceLink.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>SourceLink</Name>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -40,10 +40,7 @@
<OtherFlags>
</OtherFlags>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<ItemGroup>
<Compile Include="SystemExtensions.fs" />
<Compile Include="AppConfig.fs" />
Expand Down
29 changes: 28 additions & 1 deletion SymbolStore/CorSymExt.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[<AutoOpen>]
module SourceLink.SymbolStore.CorSymExt

open System
open System.IO
open System.Text
open SourceLink.SymbolStore.CorSym

type ISymUnmanagedReader with
Expand All @@ -24,4 +26,29 @@ type ISymUnmanagedReader with
x.AsReader2.GetMethodsInDocument(doc, 0, &count, null)
let methods = Array.zeroCreate count
x.AsReader2.GetMethodsInDocument(doc, count, &count, methods)
methods
methods

type ISymUnmanagedDocument with
member x.SourceFilePath
with get() =
let mutable count = 0
x.GetURL(0, &count, null)
let path = StringBuilder count
x.GetURL(count, &count, path)
path.ToString()

member x.DocumentType
with get() =
let mutable guid = Guid()
x.GetDocumentType(&guid)
guid

member x.Checksum
with get() =
let mutable count = 0
x.GetCheckSum(0, &count, null) |> ignore
let data = Array.zeroCreate count
x.GetCheckSum(count, &count, data) |> ignore
data

member x.ChecksumHex with get() = x.Checksum |> Hex.encode
43 changes: 43 additions & 0 deletions SymbolStore/Hex.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// http://fssnip.net/25 and slightly modified
module SourceLink.SymbolStore.Hex

open System

let toHexDigit n =
if n < 10 then char (n + 0x30) else char (n + 0x37)

let fromHexDigit c =
if c >= '0' && c <= '9' then int c - int '0'
elif c >= 'A' && c <= 'F' then (int c - int 'A') + 10
elif c >= 'a' && c <= 'f' then (int c - int 'a') + 10
else raise <| new ArgumentException()

let encode (buf:byte array) =
let hex = Array.zeroCreate (buf.Length * 2)
let mutable n = 0
for i = 0 to buf.Length - 1 do
hex.[n] <- toHexDigit ((int buf.[i] &&& 0xF0) >>> 4)
n <- n + 1
hex.[n] <- toHexDigit (int buf.[i] &&& 0xF)
n <- n + 1
String hex

let decode (s:string) =
match s with
| null -> nullArg "s"
| _ when s.Length = 0 -> Array.empty
| _ ->
let mutable len = s.Length
let mutable i = 0
if len >= 2 && s.[0] = '0' && (s.[1] = 'x' || s.[1] = 'X') then do
len <- len - 2
i <- i + 2
if len % 2 <> 0 then invalidArg "s" "Invalid hex format"
else
let buf = Array.zeroCreate (len / 2)
let mutable n = 0
while i < s.Length do
buf.[n] <- byte (((fromHexDigit s.[i]) <<< 4) ||| (fromHexDigit s.[i + 1]))
i <- i + 2
n <- n + 1
buf
4 changes: 3 additions & 1 deletion SymbolStore/PdbReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ type PdbReader(reader:ISymUnmanagedReader, sessionCookie:IntPtr, fileName:string
member x.GetDownloadUrl sourceFilePath =
if isSourceIndexed then
SrcSrv.GetFileUrl(sessionCookie, moduleCookie, sourceFilePath) |> Option.ofNull
else None
else None

member x.Documents = x.Reader.Documents
7 changes: 5 additions & 2 deletions SymbolStore/SymbolStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>SymbolStore</Name>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -24,6 +24,7 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<NoWarn>2003</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -33,10 +34,12 @@
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\SourceLink.SymbolStore.xml</DocumentationFile>
<NoWarn>2003</NoWarn>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<ItemGroup>
<Compile Include="SystemExt.fs" />
<Compile Include="Hex.fs" />
<Compile Include="CorSymExt.fs" />
<Compile Include="PdbReader.fs" />
<Compile Include="SymbolCache.fs" />
Expand Down
7 changes: 2 additions & 5 deletions Tfs/Tfs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Tfs</Name>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">12</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -36,10 +36,7 @@
<DocumentationFile>bin\Release\SourceLink.Tfs.xml</DocumentationFile>
<NoWarn>2003</NoWarn>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
<Choose>
Expand Down

0 comments on commit 1939a81

Please sign in to comment.