Skip to content
Open
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
14 changes: 1 addition & 13 deletions .nuget/BuildCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@
<!-- Set compile time constants to detect target framework version during compilation -->
<CustomConstants Condition=" '$(TargetFrameworkVersion)' == 'v2.0' ">TARGET_NET_20</CustomConstants>
<CustomConstants Condition=" '$(TargetFrameworkVersion)' == 'v4.0' ">TARGET_NET_40</CustomConstants>
<CustomConstants Condition=" '$(TargetFrameworkIdentifier)' == 'Silverlight' ">SILVERLIGHT</CustomConstants>
<DefineConstants Condition=" '$(DefineConstants)' != '' And '$(CustomConstants)' != '' ">$(DefineConstants);</DefineConstants>
<DefineConstants>$(DefineConstants)$(CustomConstants)</DefineConstants>
</PropertyGroup>


<!--
Define BuildPackage if .nuspec specified
-->
<PropertyGroup>
<NuspecFile Condition="'$(NuspecFile)' == ''">$(ProjectDir)$(ProjectName).nuspec</NuspecFile>
<BuildPackage Condition="'$(BuildPackageIfMarked)' == 'true' And $([System.IO.File]::Exists($(NuspecFile)))">true</BuildPackage>
<BuildDependsOn Condition="!$(BuildDependsOn.Contains('BuildPackage;')) And '$(BuildPackage)' == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>


<!--
Define NuGet pack command based on the NuSpec and found version.
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@
-->
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="$(SolutionDir)\.nuget\BuildCommon.targets" />
<PropertyGroup>
<NuspecFile Condition="'$(NuspecFile)' == ''">$(ProjectDir)$(ProjectName).nuspec</NuspecFile>
</PropertyGroup>
<Target Name="AfterBuild" Condition="'$(TargetFrameworkVersion)' == 'v4.5'">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v4.0;TargetFrameworkProfile=Client;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v2.0;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildPackage" Condition="'$(BuildPackageIfMarked)' == 'true' And $([System.IO.File]::Exists($(NuspecFile)))" />
</Target>
</Project>
31 changes: 21 additions & 10 deletions ProductionStackTrace.Analyze/ExceptionReportInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ExceptionReportInterpreter
// MODULE: AssemblyName => AssemblyFullyQualifiedName; G:27657a27fg376787d6; A:1

private static readonly Regex s_regexAssemblyMapping =
new Regex(@"MODULE: (?<Assembly>[^\s]+(?=\s+\=>))\s+\=>\s+(?<AssemblyFQN>[^;]+)(;\s+(?<KeyValue>[a-z]+\:[^;]+))+", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
new Regex(@"MODULE: (?<Assembly>[^\s]+(?=\s+\=>))\s+\=>\s+(?<AssemblyFQN>[^;]+)(;(\s+)?(?<KeyValue>[a-z]+\:[^;]+)?)+", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

private SymbolSearch _symSearch;

Expand Down Expand Up @@ -101,6 +101,13 @@ public void Translate(TextReader r, TextWriter w)
info.Attributes[kv[0]] = kv[1];
}

// PDB filename is derived from assembly name + '.pdb' extension

var assemblyFileName = info.FullyQualifiedName;
int idxShortNameEnd = assemblyFileName.IndexOf(',');
if (idxShortNameEnd > 0) assemblyFileName = assemblyFileName.Substring(0, idxShortNameEnd);
var pdbFileName = assemblyFileName + ".pdb";

// If GUID and Age are specified, that means that assembly has debug information
// and the correspodning PDB file would have the matching GUID + Age attributes

Expand All @@ -117,21 +124,25 @@ public void Translate(TextReader r, TextWriter w)
info.PdbGuid = pdbGuid;
info.fPdbSpecified = true;

// PDB filename is derived from assembly name + '.pdb' extension

var assemblyFileName = info.FullyQualifiedName;
int idxShortNameEnd = assemblyFileName.IndexOf(',');
if (idxShortNameEnd > 0) assemblyFileName = assemblyFileName.Substring(0, idxShortNameEnd);

// Lookup PDB file using configured Symbol Search Paths. If found, then
// load PDB symbol information - it will be used below to find source line numbers

info.PdbPath = _symSearch.FindPdbFile(assemblyFileName + ".pdb", info.PdbGuid, info.PdbAge);
if (info.PdbPath != null)
info.PdbSymbolLoader = SymbolLoader.Load(info.PdbPath);
info.PdbPath = _symSearch.FindPdbFile(pdbFileName, info.PdbGuid, info.PdbAge);
}
}
else
{
// try to search for it anyway
info.PdbPath = _symSearch.FindPdbFile(pdbFileName);
if (info.PdbPath != null)
{
info.fPdbSpecified = true;
}
}

if (info.PdbPath != null)
info.PdbSymbolLoader = SymbolLoader.Load(info.PdbPath);

mapping[assemblyName] = info;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ItemGroup>
<Reference Include="dia2lib" Condition="'$(TargetFrameworkVersion)' != 'v2.0'">
<HintPath>..\Lib\dia2lib\net40\dia2lib.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="dia2lib" Condition="'$(TargetFrameworkVersion)' == 'v2.0'">
<HintPath>..\Lib\dia2lib\net20\dia2lib.dll</HintPath>
Expand Down Expand Up @@ -66,6 +66,9 @@
-->
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="$(SolutionDir)\.nuget\BuildCommon.targets" />
<PropertyGroup>
<NuspecFile Condition="'$(NuspecFile)' == ''">$(ProjectDir)$(ProjectName).nuspec</NuspecFile>
</PropertyGroup>
<Target Name="AssemblyMerge" AfterTargets="PrepareForRun" Condition="'$(TargetFrameworkVersion)' == 'v2.0'">
<MakeDir Directories="$(TargetDir)merged" />
<PropertyGroup>
Expand All @@ -86,5 +89,6 @@
<Target Name="AfterBuild" Condition="'$(TargetFrameworkVersion)' == 'v4.5'">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v4.0;TargetFrameworkProfile=Client;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v2.0;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildPackage" Condition="'$(BuildPackageIfMarked)' == 'true' And $([System.IO.File]::Exists($(NuspecFile)))" />
</Target>
</Project>
31 changes: 30 additions & 1 deletion ProductionStackTrace.Analyze/SymbolSearch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Dia2Lib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

Expand Down Expand Up @@ -116,5 +118,32 @@ public string FindPdbFile(string pdbFileName, Guid guid, int age)

return filePath.ToString();
}

/// <summary>
/// Looks through the configured symbol paths to find a PDB symbol
/// file matching specified name.
/// </summary>
/// <param name="pdbFileName">Name of the PDB file.</param>
/// <returns>The pdb file path or null the pdf file wasn't found.</returns>
public string FindPdbFile(string pdbFileName)
{
foreach (string symbolPath in this.SymbolPaths)
{
string filePath = Path.Combine(symbolPath, pdbFileName);
if (File.Exists(filePath))
{
DiaSourceClass dia = new DiaSourceClass();
dia.loadDataFromPdb(filePath);
IDiaSession session;
dia.openSession(out session);

IDiaSymbol symbol = session.globalScope;

return FindPdbFile(pdbFileName, symbol.guid, (int)symbol.age);
}
}

return null;
}
}
}
4 changes: 2 additions & 2 deletions ProductionStackTrace.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductionStackTrace", "ProductionStackTrace\ProductionStackTrace.csproj", "{6F8A759B-6096-468E-A370-09C9785D673C}"
EndProject
Expand Down
6 changes: 6 additions & 0 deletions ProductionStackTrace/ExceptionReporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static string GetExceptionReport(Exception ex)
{
var info = ctx.AssemblyInfo[key];
builder.AppendFormat("MODULE: {0} => {1};", key, info.Assembly.FullName);
#if !SILVERLIGHT
if (info.DebugInfo != null)
{
builder.AppendFormat(" G:{0:N}; A:{1}", info.DebugInfo.Guid, info.DebugInfo.Age);
Expand All @@ -46,6 +47,7 @@ public static string GetExceptionReport(Exception ex)
if (!string.Equals(pdbFileName, info.ShortName + ".pdb", StringComparison.OrdinalIgnoreCase))
builder.Append("; F:").Append(pdbFileName);
}
#endif
builder.AppendLine();
}
}
Expand Down Expand Up @@ -228,7 +230,9 @@ private static void AppendAssemblyName(StringBuilder builder, Assembly assembly,
if (info == null)
{
ctx.AssemblyInfo.Add(assemblyName, info = new AssemblyReportInfo() { Assembly = assembly, ShortName = originalAssemblyName });
#if !SILVERLIGHT
info.DebugInfo = AssemblyDebugInfo.ReadAssemblyDebugInfo(assembly);
#endif
}
}

Expand All @@ -243,7 +247,9 @@ private class ExceptionReportingContext
private class AssemblyReportInfo
{
public Assembly Assembly;
#if !SILVERLIGHT
public AssemblyDebugInfo DebugInfo;
#endif
public string ShortName;
}

Expand Down
2 changes: 2 additions & 0 deletions ProductionStackTrace/Internals/AssemblyDebugInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private AssemblyDebugInfo()
{
}

#if !SILVERLIGHT
/// <summary>
/// Retrieve PDB information from Assembly, by reading it's PE header.
/// </summary>
Expand Down Expand Up @@ -88,6 +89,7 @@ public static AssemblyDebugInfo ReadAssemblyDebugInfo(Assembly assembly)
Path = path
};
}
#endif

#region Struct definitions

Expand Down
16 changes: 16 additions & 0 deletions ProductionStackTrace/Internals/PeHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,13 @@ private PeHeaders()
{
}

#if !SILVERLIGHT
public static PeHeaders FromAssembly(Assembly assembly)
{
var modulePtr = Marshal.GetHINSTANCE(assembly.ManifestModule);
return FromUnmanagedPtr(modulePtr);
}
#endif

public static PeHeaders FromUnmanagedPtr(IntPtr memoryPtr)
{
Expand Down Expand Up @@ -512,15 +514,25 @@ private static T FromBinaryReader<T>(BinaryReader reader, byte[] lookahead)

// Pin the managed memory while, copy it out the data, then unpin it
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
#if SILVERLIGHT
T theStructure = default(T);
Marshal.PtrToStructure(handle.AddrOfPinnedObject(), theStructure);
#else
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
#endif
handle.Free();

return theStructure;
}

private static T FromMemoryPtr<T>(IntPtr memPtr, ref long index)
{
#if SILVERLIGHT
T obj = default(T);
Marshal.PtrToStructure(new IntPtr(memPtr.ToInt64() + index), obj);
#else
var obj = (T)Marshal.PtrToStructure(new IntPtr(memPtr.ToInt64() + index), typeof(T));
#endif
index += Marshal.SizeOf(typeof(T));
return obj;
}
Expand Down Expand Up @@ -594,7 +606,11 @@ public DateTime TimeStamp
// Add in the number of seconds since 1970/1/1
returnValue = returnValue.AddSeconds(fileHeader.TimeDateStamp);
// Adjust to local timezone
#if SILVERLIGHT
returnValue += TimeZoneInfo.Local.GetUtcOffset(returnValue);
#else
returnValue += TimeZone.CurrentTimeZone.GetUtcOffset(returnValue);
#endif

return returnValue;
}
Expand Down
11 changes: 9 additions & 2 deletions ProductionStackTrace/ProductionStackTrace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<AssemblyName>ProductionStackTrace</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<OutputPath>bin\$(Configuration)\$(TargetFrameworkVersion)\</OutputPath>
<OutputPath Condition="'$(TargetFrameworkIdentifier)'==''">bin\$(Configuration)\$(TargetFrameworkVersion)\</OutputPath>
<OutputPath Condition="'$(TargetFrameworkIdentifier)'=='Silverlight' and $(TargetFrameworkVersion) == 'v5.0'">bin\$(Configuration)\sl5\</OutputPath>
<PackageOutputDir>bin\$(Configuration)</PackageOutputDir>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
Expand Down Expand Up @@ -46,7 +47,8 @@
<ItemGroup>
<None Include="ProductionStackTrace.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition="'$(TargetFrameworkIdentifier)'!='Silverlight'" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" Condition="'$(TargetFrameworkIdentifier)'=='Silverlight'" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand All @@ -56,8 +58,13 @@
-->
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="$(SolutionDir)\.nuget\BuildCommon.targets" />
<PropertyGroup>
<NuspecFile Condition="'$(NuspecFile)' == ''">$(ProjectDir)$(ProjectName).nuspec</NuspecFile>
</PropertyGroup>
<Target Name="AfterBuild" Condition="'$(TargetFrameworkVersion)' == 'v4.5'">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v4.0;TargetFrameworkProfile=Client;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v2.0;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="TargetFrameworkVersion=v5.0;TargetFrameworkIdentifier=Silverlight;SilverlightVersion=v5.0;Configuration=$(Configuration);Platform=$(Platform)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildPackage" Properties="Configuration=$(Configuration);NuspecFile=$(NuspecFile)" Condition="'$(BuildPackageIfMarked)' == 'true' And $([System.IO.File]::Exists($(NuspecFile)))" />
</Target>
</Project>
1 change: 1 addition & 0 deletions ProductionStackTrace/ProductionStackTrace.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<file src="bin\$configuration$\v2.0\*" exclude="**\*.tmp" target="lib\net20\" />
<file src="bin\$configuration$\v4.0\*" exclude="**\*.tmp" target="lib\net40\" />
<file src="bin\$configuration$\v4.5\*" exclude="**\*.tmp" target="lib\net45\" />
<file src="bin\$configuration$\sl5\*" exclude="**\*.tmp" target="lib\sl5\" />
<file src="**\*.cs" exclude="obj\**" target="src" />
</files>
</package>
11 changes: 11 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1.0.{build}
build_script:
- cmd: build.cmd package
test_script:
- cmd: >-
nuget install NUnit.Runners -Version 2.6.4

.\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe .\ProductionStackTrace.Test\bin\Release\ProductionStackTrace.Test.dll
artifacts:
- path: _deploy\*.nupkg
name: NuGet Package