Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add portable pdb support for net46. #856

Merged
merged 3 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
28 changes: 22 additions & 6 deletions src/Microsoft.TestPlatform.ObjectModel/Navigation/DiaSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel
using System.Diagnostics.CodeAnalysis;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

/// <summary>
/// The class that enables us to get debug information from both managed and native binaries.
Expand Down Expand Up @@ -45,12 +47,7 @@ public DiaSession(string binaryPath)
/// search path.
/// </param>
public DiaSession(string binaryPath, string searchPath)
:
#if NET46
this(binaryPath, searchPath, new FullSymbolReader())
#else
this(binaryPath, searchPath, new PortableSymbolReader())
#endif
: this(binaryPath, searchPath, GetSymbolReader(binaryPath))
{
}

Expand Down Expand Up @@ -94,5 +91,24 @@ public INavigationData GetNavigationDataForMethod(string declaringTypeName, stri
methodName = methodName.TrimEnd(TestNameStripChars);
return this.symbolReader.GetNavigationData(declaringTypeName, methodName);
}

private static ISymbolReader GetSymbolReader(string binaryPath)
{
#if NET46
var pdbFilePath = Path.ChangeExtension(binaryPath, ".pdb");
using (var stream = new FileHelper().GetStream(pdbFilePath, FileMode.Open, FileAccess.Read))
{
if (PortablePdbReader.IsPortable(stream))
{
return new PortableSymbolReader();
}

return new FullSymbolReader();
}
#else
// We don't support full PDB files with .net core
return new PortableSymbolReader();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log on full pdb received for netcore.

#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation
{
#if !NET46
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
Expand Down Expand Up @@ -85,6 +83,24 @@ public DiaNavigationData GetDiaNavigationData(MethodInfo methodInfo)
return this.GetDiaNavigationData(handle);
}

/// <summary>
/// Checks gives stream is from portable pdb or not
/// </summary>
/// <param name="stream">
/// Stream.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
internal static bool IsPortable(Stream stream)
{
// First four bytes should be 'BSJB'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BSJB came from here

var result = (stream.ReadByte() == 'B') && (stream.ReadByte() == 'S') && (stream.ReadByte() == 'J')
&& (stream.ReadByte() == 'B');
stream.Position = 0;
return result;
}

internal static MethodDebugInformationHandle GetMethodDebugInformationHandle(MethodInfo methodInfo)
{
var methodToken = (int)MethodInfoMethodTokenProperty.GetValue(methodInfo);
Expand Down Expand Up @@ -113,24 +129,6 @@ private static void GetMethodMinAndMaxLineNumber(
}
}

/// <summary>
/// Checks gives stream is from portable pdb or not
/// </summary>
/// <param name="stream">
/// Stream.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
private static bool IsPortable(Stream stream)
{
// First four bytes should be 'BSJB'
var result = (stream.ReadByte() == 'B') && (stream.ReadByte() == 'S') && (stream.ReadByte() == 'J')
&& (stream.ReadByte() == 'B');
stream.Position = 0;
return result;
}

private DiaNavigationData GetDiaNavigationData(MethodDebugInformationHandle handle)
{
if (this.reader == null)
Expand Down Expand Up @@ -168,5 +166,4 @@ private string GetMethodFileName(MethodDebugInformation methodDebugDefinition)
return fileName;
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation
{
#if !NET46
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
#if !NET46
using System.Runtime.Loader;
#endif

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

Expand Down Expand Up @@ -96,7 +96,11 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath)
// At this point, the assembly should be already loaded into the load context. We query for a reference to
// find the types and cache the symbol information. Let the loader follow default lookup order instead of
// forcing load from a specific path.
#if NET46
var asm = Assembly.Load(AssemblyName.GetAssemblyName(binaryPath));
#else
var asm = Assembly.Load(AssemblyLoadContext.GetAssemblyName(binaryPath));
#endif

foreach (var type in asm.GetTypes())
{
Expand Down Expand Up @@ -137,5 +141,4 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath)
}
}
}
#endif
}
3 changes: 2 additions & 1 deletion src/package/nuspec/TestPlatform.ObjectModel.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
<dependencies>
<group targetFramework="net46">
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="[4.3.0, )" />
<dependency id="System.Reflection.Metadata" version="[1.3.0, )" />
</group>
<group targetFramework="netstandard1.5">
<dependency id="NETStandard.Library" version="[1.6.1, )" />
<dependency id="System.ComponentModel.EventBasedAsync" version="[4.3.0, )" />
<dependency id="System.ComponentModel.TypeConverter" version="[4.3.0, )" />
<dependency id="System.Reflection.TypeExtensions" version="[4.3.0, )" />
<dependency id="System.Reflection.Metadata" version="[1.4.2, )" />
<dependency id="System.Reflection.Metadata" version="[1.3.0, )" />
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="[4.3.0, )" />
<dependency id="System.Runtime.Loader" version="[4.3.0, )" />
<dependency id="System.Runtime.Serialization.Primitives" version="[4.3.0, )" />
Expand Down
6 changes: 4 additions & 2 deletions test/TestAssets/SimpleClassLibrary/SimpleClassLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<PropertyGroup Condition="$(NetCoreAppTargetFrameWork) == 'true' ">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46'">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' and $(Configuration) == 'Debug'">
<DebugType>full</DebugType>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' and $(Configuration) == 'Release'">
<DebugType>portable</DebugType>
</PropertyGroup>
</Project>