Skip to content

Commit

Permalink
ctaggart#35 using Roslyn COM interfaces instead of MDbg
Browse files Browse the repository at this point in the history
all Roslyn interfaces moved into SourceLink.SymbolStore.ComSym library
using F# for SourceLink.SymbolStore library
MDbg binary being used from ConsoleTest
  • Loading branch information
Cameron Taggart authored and Chet Husk committed Nov 25, 2014
1 parent 881a680 commit 1b40809
Show file tree
Hide file tree
Showing 37 changed files with 280 additions and 585 deletions.
2 changes: 1 addition & 1 deletion ConsoleTest/Checksums.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[<AutoOpen>]
module Checksums
module SourceLink.Checksums

open System
open System.Collections.Generic
Expand Down
12 changes: 9 additions & 3 deletions ConsoleTest/ConsoleTest.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ProjectGuid>61cbf06d-603e-4cbd-afbf-079c08beec4b</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleTest</RootNamespace>
<AssemblyName>ConsoleTest</AssemblyName>
<AssemblyName>SourceLink.ConsoleTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>ConsoleTest</Name>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
Expand Down Expand Up @@ -344,12 +344,18 @@
<Compile Include="printfn.fs" />
<Compile Include="Checksums.fs" />
<Compile Include="RootAndInfo.fs" />
<Compile Include="MDbg.fs" />
<Compile Include="Program.fs" />
<None Include="Git.fsx" />
<None Include="BuildInfo.fsx" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CorSym\CorSym.csproj">
<Name>CorSym</Name>
<Project>{f764ced4-2f3c-49ec-ba9f-99105707b607}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\Git\Git.fsproj">
<Name>Git</Name>
<Project>{726a13b9-f319-40fa-aef6-fe629cfdaf6a}</Project>
Expand All @@ -365,9 +371,9 @@
<Project>{aaf1b8d7-791e-40f1-a278-9a16d9667866}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\SymbolStore\SymbolStore.csproj">
<ProjectReference Include="..\SymbolStore\SymbolStore.fsproj">
<Name>SymbolStore</Name>
<Project>{f764ced4-2f3c-49ec-ba9f-99105707b607}</Project>
<Project>{22d889db-96e8-475d-922e-4e7eebb60045}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions ConsoleTest/MDbg.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace SourceLink

open Microsoft.Samples.Debugging.SymbolStore
open Microsoft.Samples.Debugging.CorSymbolStore

type SequencePoint = {
Offset: int
Document: ISymbolDocument
Line: int
Column: int
EndLine: int
EndColumn: int
}

[<AutoOpen>]
module MDbg =

type ISymbolReader with
static member Create symUnmanagedReader =
SymbolBinder.GetReaderFromCOM symUnmanagedReader

type ISymbolMethod with
member x.SequencePoints
with get() =
let count = x.SequencePointCount
let offsets = Array.zeroCreate count
let docs = Array.zeroCreate count
let lines = Array.zeroCreate count
let columns = Array.zeroCreate count
let endLines = Array.zeroCreate count
let endColumns = Array.zeroCreate count
x.GetSequencePoints(offsets, docs, lines, columns, endLines, endColumns)
let points = Array.zeroCreate count
for i in 0 .. count - 1 do
points.[0] <- {
Offset = offsets.[i]
Document = docs.[i]
Line = lines.[i]
Column = columns.[i]
EndLine = endLines.[i]
EndColumn = endColumns.[i]
}
48 changes: 26 additions & 22 deletions ConsoleTest/Program.fs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
open System
module SourceLink.Program

open System
//open System.Collections.Generic
open System.IO
open SourceLink
open SourceLink.SymbolStore
open System.Reflection
open Microsoft.Samples.Debugging.SymbolStore
open SourceLink.SymbolStore.CorSym

let pdbSourceLink = @"..\..\..\packages\SourceLink.Fake\tools\SourceLink.pdb"

let printPdbDocuments() =
use s = File.OpenRead pdbSourceLink

let symbolCache = SymbolCache @"C:\tmp\cache"
let pdbReader = symbolCache.ReadPdb(s, pdbSourceLink)
let pdbReader = symbolCache.ReadPdb s pdbSourceLink

for d in pdbReader.ISymbolReader.GetDocuments() do
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
printfn "has download url if source indexed: %s" url
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)
Expand All @@ -31,25 +35,25 @@ let printMethods() =
for m in dt.GetMembers() do
printfn " %d %s" m.MetadataToken m.Name

type PdbReader with
member x.MethodTokens
with get() =
seq {
for d in x.ISymUnmanagedReader.GetDocuments() do
for m in x.GetMethodsInDocument d do
yield m.GetToken() }
member x.Methods
with get() =
x.MethodTokens
|> Seq.map (fun t -> SymbolToken t |> x.ISymbolReader.GetMethod)
//type PdbReader with
// member x.MethodTokens
// with get() =
// seq {
// for d in x.Reader.GetDocuments() do
// for m in x.GetMethodsInDocument d do
// yield m.GetToken() }
// member x.Methods
// with get() =
// x.MethodTokens
// |> Seq.map (fun t -> SymbolToken t |> x.Reader.GetMethod)

// print methods and their files and line numbers
let printMethodsFileLines() =
let dll = @"..\..\..\packages\SourceLink.SymbolStore\lib\net45\SourceLink.SymbolStore.dll"
let pdb = Path.ChangeExtension(dll, ".pdb")
let sc = SymbolCache @"C:\tmp\cache"
use s = File.OpenRead pdb
use pdbReader = sc.ReadPdb(s, pdb)
let pdbReader = sc.ReadPdb s pdb

// for doc in pdbReader.ISymUnmanagedReader.GetDocuments() do
//// printfn "%s %s" (doc.GetCheckSum() |> Hex.encode) doc.URL / in managed
Expand All @@ -65,12 +69,12 @@ let printMethodsFileLines() =
//// for p in m. do
//// printfn "%d, %d" p.Line p.Column

for m in pdbReader.Methods do
// printfn "%s" (m.GetNamespace().Name) // NIE
let count = m.SequencePointCount
printfn "method %d %d" (m.Token.GetToken()) count
for s in m.GetSequencePoints() do
printfn " point %d, %d" s.Line s.Column
// for m in pdbReader.Methods do
//// printfn "%s" (m.GetNamespace().Name) // NIE
// let count = m.SequencePointCount
// printfn "method %d %d" (m.Token.GetToken()) count
// for s in m.GetSequencePoints() do
// printfn " point %d, %d" s.Line s.Column
()


Expand Down
2 changes: 1 addition & 1 deletion ConsoleTest/RootAndInfo.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[<AutoOpen>]
module RootAndInfo
module SourceLink.RootAndInfo

open System
open System.Collections.Generic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Runtime.InteropServices.ComTypes;

//namespace Roslyn.Utilities
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
internal sealed class ComStreamWrapper : IStream
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;

//namespace Roslyn.Test.PdbUtilities
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
internal sealed class DummyMetadataImport : IMetadataImport
{
Expand Down
2 changes: 1 addition & 1 deletion SymbolStore/HResults.cs → CorSym/HResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------

namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
public enum HResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;

//namespace Roslyn.Test.PdbUtilities
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
internal struct COR_FIELD_OFFSET
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComVisible(false)]
[Guid("40DE4037-7C81-3E1E-B022-AE1ABFF2CA08")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComImport]
[Guid("B62B923C-B500-3158-A543-24F307A8B7E1")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComImport]
[Guid("0DFF7289-54F8-11d3-BD28-0000F80849BD")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Runtime.InteropServices.ComTypes;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComImport]
[Guid("B4CE6286-2A6B-3712-A3B7-1EE1DAD467B5")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[Guid("A09E53B2-2A57-4cca-8F63-B84F7C35D4AA")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComImport]
[Guid("68005D0F-B8E0-3B01-84D5-A11A94154942")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;

//namespace Roslyn.Utilities.Pdb
namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[ComImport]
[Guid("9F60EEBE-2D9A-3F7C-BF58-80BC991C60BB")]
Expand Down
2 changes: 1 addition & 1 deletion SymbolStore/SrcSrv.cs → CorSym/SrcSrv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Runtime.InteropServices;
using System.Text;

namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
[
ComImport,
Expand Down
2 changes: 1 addition & 1 deletion SymbolStore/SymSrv.cs → CorSym/SymSrv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using System.Runtime.InteropServices;

namespace SourceLink.SymbolStore
namespace SourceLink.SymbolStore.CorSym
{
public static class SymSrv
{
Expand Down
2 changes: 1 addition & 1 deletion Fake/Fake.nuspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.7">
<metadata>
<id>SourceLink.Fake</id>
<version>0.0.0</version>
<authors>Cameron Taggart</authors>
Expand Down
2 changes: 1 addition & 1 deletion Git/Git.nuspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.7">
<metadata>
<id>SourceLink.Git</id>
<version>0.0.0</version>
<title>SourceLink.Git</title>
Expand Down
10 changes: 8 additions & 2 deletions SourceLink.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SourceLink", "SourceLink\SourceLink.fsproj", "{AAF1B8D7-791E-40F1-A278-9A16D9667866}"
EndProject
Expand Down Expand Up @@ -45,7 +45,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{D3E73D0A-2
docs\content\visualstudio.md = docs\content\visualstudio.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SymbolStore", "SymbolStore\SymbolStore.csproj", "{F764CED4-2F3C-49EC-BA9F-99105707B607}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CorSym", "CorSym\CorSym.csproj", "{F764CED4-2F3C-49EC-BA9F-99105707B607}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SymbolStore", "SymbolStore\SymbolStore.fsproj", "{22D889DB-96E8-475D-922E-4E7EEBB60045}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -85,6 +87,10 @@ Global
{F764CED4-2F3C-49EC-BA9F-99105707B607}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F764CED4-2F3C-49EC-BA9F-99105707B607}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F764CED4-2F3C-49EC-BA9F-99105707B607}.Release|Any CPU.Build.0 = Release|Any CPU
{22D889DB-96E8-475D-922E-4E7EEBB60045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22D889DB-96E8-475D-922E-4E7EEBB60045}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22D889DB-96E8-475D-922E-4E7EEBB60045}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22D889DB-96E8-475D-922E-4E7EEBB60045}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion SourceLink/SourceLink.nuspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.7">
<metadata>
<id>SourceLink</id>
<version>0.0.0</version>
<title>SourceLink</title>
Expand Down
27 changes: 27 additions & 0 deletions SymbolStore/CorSymExt.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[<AutoOpen>]
module SourceLink.SymbolStore.CorSymExt

open System.IO
open SourceLink.SymbolStore.CorSym

type ISymUnmanagedReader with
static member Create pdb =
TempPdbReader.CreateRawReader pdb

member x.AsReader2 = x :?> ISymUnmanagedReader2
member x.AsSourceServer = x :?> ISymUnmanagedSourceServerModule

member x.Documents
with get() =
let mutable count = 0
x.GetDocuments(0, &count, null)
let docs = Array.zeroCreate count
x.GetDocuments(count, &count, docs)
docs

member x.GetMethodsInDocument doc =
let mutable count = 0
x.AsReader2.GetMethodsInDocument(doc, 0, &count, null)
let methods = Array.zeroCreate count
x.AsReader2.GetMethodsInDocument(doc, count, &count, methods)
methods
Loading

0 comments on commit 1b40809

Please sign in to comment.