Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit d3dd63e

Browse files
committed
Properly detect when .pdb file use the new Portable PDB format
1 parent 75f9935 commit d3dd63e

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/GitLink/GitLink.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Compile Include="Pdb\PdbStream.cs" />
7676
<Compile Include="Pdb\SrcSrv.cs" />
7777
<Compile Include="Pdb\SrcSrvContext.cs" />
78+
<Compile Include="Helpers\PortablePdbHelper.cs" />
7879
<Compile Include="Program.cs" />
7980
<Compile Include="Properties\AssemblyInfo.cs" />
8081
<Compile Include="Providers\BitBucketProvider.cs" />
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="PortablePdbHelper.cs" company="CatenaLogic">
3+
// Copyright (c) 2014 - 2016 CatenaLogic. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace GitLink
8+
{
9+
using System.IO;
10+
11+
internal static class PortablePdbHelper
12+
{
13+
/// <summary>
14+
/// Is the given .pdb using the new Portable format ? (https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PortablePdb-Metadata.md)
15+
/// </summary>
16+
/// <param name="pdbPath">.pdb file path</param>
17+
/// <returns>Returns if it's a Portable PDB</returns>
18+
public static bool IsPortablePdb(string pdbPath)
19+
{
20+
using (var fs = File.Open(pdbPath, FileMode.Open, FileAccess.Read))
21+
using (var br = new BinaryReader(fs))
22+
{
23+
// More infos in chapter II.24.2 of ECMA-335 (http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf)
24+
var signature = 0x424A5342;
25+
if (br.ReadUInt32() != signature)
26+
{
27+
return false;
28+
}
29+
30+
var majorVersion = br.ReadUInt16();
31+
if (majorVersion != 1)
32+
{
33+
return false;
34+
}
35+
36+
var minorVersion = br.ReadUInt16();
37+
if (minorVersion != 1)
38+
{
39+
return false;
40+
}
41+
42+
var reserved = br.ReadUInt32();
43+
if (reserved != 0)
44+
{
45+
return false;
46+
}
47+
48+
var versionLength = br.ReadUInt32();
49+
var version = System.Text.Encoding.UTF8.GetString(br.ReadBytes((int)versionLength));
50+
51+
return version.StartsWith("PDB v1.0");
52+
}
53+
}
54+
}
55+
}

src/GitLink/Linker.cs

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public static class Linker
5050
}
5151
}
5252

53+
if (PortablePdbHelper.IsPortablePdb(pdbPath))
54+
{
55+
Log.Warning("Portable PDB format is not compatible with GitLink. Please use SourceLink (https://github.com/ctaggart/SourceLink).");
56+
return true;
57+
}
58+
5359
if (options.IndexAllDepotFiles)
5460
{
5561
if (repositoryDirectory == null)

0 commit comments

Comments
 (0)