Skip to content

Commit

Permalink
Distribute one common private version of DIA with GoogleTestExplorer.…
Browse files Browse the repository at this point in the history
… Remove all the complexity of handling different DIA versions. (#124)
  • Loading branch information
jgefele committed Apr 14, 2017
1 parent 747db11 commit 0a2b80f
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 48,327 deletions.
1 change: 1 addition & 0 deletions GoogleTestAdapter/DiaResolver/ComComponents/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Taken from ``C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow``.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" processorArchitecture="x86" name="ComComponents\x86\msdia140.dll" version="1.0.0.0" />
<file name="msdia140.dll" hashalg="SHA1">
<comClass clsid="{E6756135-1E65-4D17-8576-610761398C3C}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" threadingModel="Both" description="DiaSource Class"></comClass>
<comClass clsid="{91904831-49CA-4766-B95C-25397E2DD6DC}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" threadingModel="Both" description="Local Heap DiaSource Class"></comClass>
<comClass clsid="{CE4A85DB-5768-475B-A4E1-C0BCA2112A6B}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" threadingModel="Both" description="General Stackwalk Class"></comClass>
<typelib tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" resourceid="1" version="2.0" helpdir="" flags="HASDISKIMAGE"></typelib>
</file>
<comInterfaceExternalProxyStub name="IDiaDataSource" iid="{79F1BB5F-B66E-48E5-B6A9-1545C323CA3D}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{79F1BB5F-B66E-48E5-B6A9-1545C323CA3D}"></comInterfaceExternalProxyStub>
<!-- Problem: standard COM intercace -->
<!--<comInterfaceExternalProxyStub name="IStream" iid="{0000000C-0000-0000-C000-000000000046}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{0000000C-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub>-->
<!-- Problem: standard Ole32 interface -->
<!--<comInterfaceExternalProxyStub name="ISequentialStream" iid="{0C733A30-2A1C-11CE-ADE5-00AA0044773D}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{0C733A30-2A1C-11CE-ADE5-00AA0044773D}"></comInterfaceExternalProxyStub>-->
<comInterfaceExternalProxyStub name="IDiaSession" iid="{2F609EE1-D1C8-4E24-8288-3326BADCD211}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{2F609EE1-D1C8-4E24-8288-3326BADCD211}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaSymbol" iid="{CB787B2F-BD6C-4635-BA52-933126BD2DCD}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{CB787B2F-BD6C-4635-BA52-933126BD2DCD}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumSymbols" iid="{CAB72C48-443B-48F5-9B0B-42F0820AB29A}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{CAB72C48-443B-48F5-9B0B-42F0820AB29A}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumLineNumbers" iid="{FE30E878-54AC-44F1-81BA-39DE940F6052}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{FE30E878-54AC-44F1-81BA-39DE940F6052}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaLineNumber" iid="{B388EB14-BE4D-421D-A8A1-6CF7AB057086}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{B388EB14-BE4D-421D-A8A1-6CF7AB057086}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaSourceFile" iid="{A2EF5353-F5A8-4EB3-90D2-CB526ACB3CDD}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{A2EF5353-F5A8-4EB3-90D2-CB526ACB3CDD}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaInputAssemblyFile" iid="{3BFE56B0-390C-4863-9430-1F3D083B7684}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{3BFE56B0-390C-4863-9430-1F3D083B7684}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumTables" iid="{C65C2B0A-1150-4D7A-AFCC-E05BF3DEE81E}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{C65C2B0A-1150-4D7A-AFCC-E05BF3DEE81E}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaTable" iid="{4A59FB77-ABAC-469B-A30B-9ECC85BFEF14}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{4A59FB77-ABAC-469B-A30B-9ECC85BFEF14}"></comInterfaceExternalProxyStub>
<!-- Problem: standard COM intercace -->
<!--<comInterfaceExternalProxyStub name="IEnumUnknown" iid="{00000100-0000-0000-C000-000000000046}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{00000100-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub>-->
<comInterfaceExternalProxyStub name="IDiaEnumSymbolsByAddr" iid="{624B7D9C-24EA-4421-9D06-3B577471C1FA}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{624B7D9C-24EA-4421-9D06-3B577471C1FA}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumSourceFiles" iid="{10F3DBD9-664F-4469-B808-9471C7A50538}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{10F3DBD9-664F-4469-B808-9471C7A50538}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumInjectedSources" iid="{D5612573-6925-4468-8883-98CDEC8C384A}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{D5612573-6925-4468-8883-98CDEC8C384A}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaInjectedSource" iid="{AE605CDC-8105-4A23-B710-3259F1E26112}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{AE605CDC-8105-4A23-B710-3259F1E26112}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumDebugStreams" iid="{08CBB41E-47A6-4F87-92F1-1C9C87CED044}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{08CBB41E-47A6-4F87-92F1-1C9C87CED044}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumDebugStreamData" iid="{486943E8-D187-4A6B-A3C4-291259FFF60D}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{486943E8-D187-4A6B-A3C4-291259FFF60D}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumInputAssemblyFiles" iid="{1C7FF653-51F7-457E-8419-B20F57EF7E4D}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{1C7FF653-51F7-457E-8419-B20F57EF7E4D}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaStackWalker" iid="{5485216B-A54C-469F-9670-52B24D5229BB}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{5485216B-A54C-469F-9670-52B24D5229BB}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaStackWalkHelper" iid="{21F81B1B-C5BB-42A3-BC4F-CCBAA75B9F19}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{21F81B1B-C5BB-42A3-BC4F-CCBAA75B9F19}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaFrameData" iid="{A39184B7-6A36-42DE-8EEC-7DF9F3F59F33}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{A39184B7-6A36-42DE-8EEC-7DF9F3F59F33}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaStackWalkFrame" iid="{07C590C1-438D-4F47-BDCD-4397BC81AD75}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{07C590C1-438D-4F47-BDCD-4397BC81AD75}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaEnumStackFrames" iid="{EC9D461D-CE74-4711-A020-7D8F9A1DD255}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{EC9D461D-CE74-4711-A020-7D8F9A1DD255}"></comInterfaceExternalProxyStub>
<comInterfaceExternalProxyStub name="IDiaStackFrame" iid="{5EDBC96D-CDD6-4792-AFBE-CC89007D9610}" tlbid="{106173A0-0173-4E5C-84E7-E915422BE997}" proxyStubClsid32="{5EDBC96D-CDD6-4792-AFBE-CC89007D9610}"></comInterfaceExternalProxyStub>
</assembly>
74 changes: 16 additions & 58 deletions GoogleTestAdapter/DiaResolver/DiaResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using Dia;
using GoogleTestAdapter.Common;

Expand All @@ -20,65 +21,18 @@ public override string ToString()
return Symbol;
}
}


[SuppressMessage("ReSharper", "InconsistentNaming")]
internal interface IDiaSession
{
IDiaSymbol globalScope { get; }
void findLinesByAddr(uint seg, uint offset, uint length, out IDiaEnumLineNumbers ppResult);
}

internal class DiaSessionAdapter : IDiaSession
{
private readonly IDiaSession140 _diaSession140;
private readonly IDiaSession110 _diaSession110;

public DiaSessionAdapter(IDiaSession140 diaSession)
{
_diaSession140 = diaSession;
}
public DiaSessionAdapter(IDiaSession110 diaSession)
{
_diaSession110 = diaSession;
}

public IDiaSymbol globalScope => _diaSession140?.globalScope ?? _diaSession110?.globalScope;

public void findLinesByAddr(uint seg, uint offset, uint length, out IDiaEnumLineNumbers ppResult)
{
ppResult = null;
_diaSession140?.findLinesByAddr(seg, offset, length, out ppResult);
_diaSession110?.findLinesByAddr(seg, offset, length, out ppResult);
}
}


internal sealed class DiaResolver : IDiaResolver
{
private static readonly Guid Dia140 = new Guid("e6756135-1e65-4d17-8576-610761398c3c");
private static readonly Guid Dia120 = new Guid("3bfcea48-620f-4b6b-81f7-b9af75454c7d");
private static readonly Guid Dia110 = new Guid("761D3BCD-1304-41D5-94E8-EAC54E4AC172");
private static readonly Guid Dia140Guid = new Guid("e6756135-1e65-4d17-8576-610761398c3c");
private const string ManifestFileNameX86 = "GoogleTestAdapter.DiaResolver.x86.manifest";
private const string ManifestFileNameX64 = "GoogleTestAdapter.DiaResolver.x64.manifest";

private readonly string _binary;
private readonly ILogger _logger;
private readonly Stream _fileStream;
private readonly IDiaSession _diaSession;

private IDiaDataSource _diaDataSource;

private bool TryCreateDiaInstance(Guid clsid)
{
try
{
Type comType = Type.GetTypeFromCLSID(clsid);
_diaDataSource = (IDiaDataSource)Activator.CreateInstance(comType);
return true;
}
catch (Exception)
{
return false;
}
}
private readonly IDiaDataSource _diaDataSource;

internal DiaResolver(string binary, string pathExtension, ILogger logger)
{
Expand All @@ -92,20 +46,24 @@ internal DiaResolver(string binary, string pathExtension, ILogger logger)
return;
}

if (!TryCreateDiaInstance(Dia140) && !TryCreateDiaInstance(Dia120) && !TryCreateDiaInstance(Dia110))
try
{
_logger.LogError("Couldn't find the msdia.dll to parse *.pdb files. You will not get any source locations for your tests.");
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var manifest = IntPtr.Size == 8 ? ManifestFileNameX64 : ManifestFileNameX86;
var path = Path.Combine(directory, manifest);
_diaDataSource = (IDiaDataSource)NRegFreeCom.ActivationContext.CreateInstanceWithManifest(Dia140Guid, path);
}
catch (Exception e)
{
_logger.LogError($"Couldn't load the msdia.dll to parse *.pdb files. You will not get any source locations for your tests.\n{e.Message}");
return;
}

_logger.DebugInfo($"Parsing pdb file \"{pdb}\"");

_fileStream = File.Open(pdb, FileMode.Open, FileAccess.Read, FileShare.Read);
_diaDataSource.loadDataFromIStream(new DiaMemoryStream(_fileStream));

dynamic diaSession110Or140;
_diaDataSource.openSession(out diaSession110Or140);
_diaSession = new DiaSessionAdapter(diaSession110Or140);
_diaDataSource.openSession(out _diaSession);
}

public void Dispose()
Expand Down
29 changes: 27 additions & 2 deletions GoogleTestAdapter/DiaResolver/DiaResolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="msdia110to140typelib">
<HintPath>msdia110to140typelib\msdia110to140typelib.dll</HintPath>
<Reference Include="msdia140typelib_clr0200">
<HintPath>ComComponents\msdia140typelib_clr0200.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="NRegFreeCom, Version=0.1.6.0, Culture=neutral, PublicKeyToken=db25130896b113af, processorArchitecture=MSIL">
<HintPath>..\packages\NRegFreeCom.0.1.6.0\lib\net40\NRegFreeCom.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
Expand All @@ -59,6 +63,22 @@
<Compile Include="SourceFileLocation.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="ComComponents\x64\msdia140.dll.manifest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ComComponents\x86\msdia140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ComComponents\x86\msdia140.dll.manifest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="ComComponents\Readme.md" />
<Content Include="GoogleTestAdapter.DiaResolver.x64.manifest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="GoogleTestAdapter.DiaResolver.x86.manifest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Key.snk" />
<None Include="packages.config" />
</ItemGroup>
Expand All @@ -68,6 +88,11 @@
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="ComComponents\x64\msdia140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>if exist "$(SolutionDir)Keys\Key_Release.snk" (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="amd64" name="GoogleTestAdapter.DiaResolver.x64" type="win32"></assemblyIdentity>
<description>Google Test Adapter DIA Resolver</description>
<dependency optional="yes">
<dependentAssembly>
<assemblyIdentity type="win32" processorArchitecture="amd64" name="ComComponents\x64\msdia140.dll" version="1.0.0.0"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="GoogleTestAdapter.DiaResolver.x86" type="win32"></assemblyIdentity>
<description>Google Test Adapter DIA Resolver</description>
<dependency optional="yes">
<dependentAssembly>
<assemblyIdentity type="win32" processorArchitecture="X86" name="ComComponents\x86\msdia140.dll" version="1.0.0.0"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>

This file was deleted.

Loading

0 comments on commit 0a2b80f

Please sign in to comment.