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

TS-41003 Move bummer to profiler #194

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions BummerExe/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
66 changes: 66 additions & 0 deletions BummerExe/BummerExe.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{19C457D5-6780-4480-94CB-ED7E055402B8}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Bummer</RootNamespace>
<AssemblyName>Bummer</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentCommandLineParser, Version=1.4.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\FluentCommandLineParser.1.4.3\lib\net35\FluentCommandLineParser.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BummerLib\BummerLib.csproj">
<Project>{721fdfc9-6da9-4159-a54e-e448dfb9097d}</Project>
<Name>BummerLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
89 changes: 89 additions & 0 deletions BummerExe/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//------------------------------------------------------------------------------
// <copyright company="CQSE GmbH">
// Copyright (c) CQSE GmbH
// </copyright>
// <license>
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </license>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Fclp;
using Newtonsoft.Json;

namespace Cqse.ConQAT.Dotnet.Bummer
{
/// <summary>
/// Entry point class to the binary-source mapper.
/// </summary>
internal class Program
{

/// <summary>
/// The entry point of the program, where the program control
/// starts and ends.
/// </summary>
/// <param name="args">The command-line arguments.</param>
public static int Main(string[] args)
{
var commandLineParser = new FluentCommandLineParser();

var filenames = new List<string>();
var assemblyNames = new List<string>();

commandLineParser.Setup<List<string>>('f', "files")
.Callback(items => filenames = items)
.WithDescription("Path(s) to symbol file(s) that should be analyzed.")
.Required();
commandLineParser.Setup<List<string>>('a', "assemblyNames")
.Callback(items => assemblyNames = items)
.WithDescription("Assembly name(s) to be used in the AssemblyMethodMapping(s). Must have the same order and number of elements as the files parameter.")
.Required();

commandLineParser.SetupHelp("?", "help")
.Callback(text => Console.WriteLine(text));

var commandLineParseResult = commandLineParser.Parse(args);

if (!filenames.Count.Equals(assemblyNames.Count))
{
Console.WriteLine("The parameters <files> and <assemblyNames> had different lengths. Aborting analysis.");
return -1;
}
if (!commandLineParseResult.HasErrors)
{
List<AssemblyMethodMappings> methodMappings = Bummer.GetMethodMappings(filenames, assemblyNames);
OutputMethodMappings(methodMappings);
}
else
{
Console.WriteLine(commandLineParseResult.ErrorText);
commandLineParser.HelpOption.ShowHelp(commandLineParser.Options);
}
return 0;
}

/// <summary>
/// Prints the specified list of method mappings on the console as JSON.
/// </summary>
/// <param name="methodMappings">The method mappings to save.</param>
private static void OutputMethodMappings(List<AssemblyMethodMappings> methodMappings)
{
var settings = new JsonSerializerSettings();
settings.Formatting = Formatting.None;
var serializer = JsonSerializer.Create(settings);
serializer.Serialize(Console.Out, methodMappings);
}
}
}
7 changes: 7 additions & 0 deletions BummerExe/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Reflection;

[assembly: AssemblyTitle("Bummer")]
[assembly: AssemblyProduct("Bummer")]
[assembly: AssemblyCompany("CQSE GmbH")]
[assembly: AssemblyCopyright("Copyright © CQSE GmbH")]
[assembly: AssemblyDescription("Creates mappings between binary and source file methods based on .pdb or .mdb symbol files.")]
5 changes: 5 additions & 0 deletions BummerExe/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentCommandLineParser" version="1.4.3" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
</packages>
53 changes: 53 additions & 0 deletions BummerLib/Bummer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
// <copyright company="CQSE GmbH">
// Copyright (c) CQSE GmbH
// </copyright>
// <license>
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </license>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Cqse.ConQAT.Dotnet.Bummer
{
/// <summary>
/// Entry point class to the binary-source mapper.
/// </summary>
public class Bummer
{
/// <summary>
/// Gets the method mappings for the specified list of file names.
/// </summary>
/// <param name="filenames">The list of symbol filenames to analyze.</param>
public static List<AssemblyMethodMappings> GetMethodMappings(List<string> filenames, List<string> assemblyNames)
{
var methodMappings = new List<AssemblyMethodMappings>();
var methodMapper = new MethodMapper();
foreach (var pair in filenames.Zip(assemblyNames, (filename, assemblyName) => new { filename = filename, assemblyName = assemblyName }))
{
if (!File.Exists(pair.filename))
{
Console.WriteLine("File does not exist: " + pair.filename);
continue;
}

methodMappings.Add(methodMapper.GetMethodMappings(pair.filename, pair.assemblyName));
}
return methodMappings;
}
}
}
100 changes: 100 additions & 0 deletions BummerLib/BummerLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{721FDFC9-6DA9-4159-A54E-E448DFB9097D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bummer</RootNamespace>
<AssemblyName>BummerLib</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reflection.Metadata.5.0.0\lib\net461\System.Reflection.Metadata.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bummer.cs" />
<Compile Include="MethodMapper\IMethodMapper.cs" />
<Compile Include="MethodMapper\Mdb\MdbMethodMapper.cs" />
<Compile Include="MethodMapper\MethodMapper.cs" />
<Compile Include="MethodMapper\MethodMapperBase.cs" />
<Compile Include="MethodMapper\Pdb\PdbFile.cs" />
<Compile Include="MethodMapper\Pdb\PdbFunction.cs" />
<Compile Include="MethodMapper\Pdb\PdbMethodMapper.cs" />
<Compile Include="MethodMapping\AssemblyMethodMappings.cs" />
<Compile Include="MethodMapping\MethodMapping.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
</Target>
</Project>
48 changes: 48 additions & 0 deletions BummerLib/MethodMapper/IMethodMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
// <copyright company="CQSE GmbH">
// Copyright (c) CQSE GmbH
// </copyright>
// <license>
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </license>
//------------------------------------------------------------------------------

namespace Cqse.ConQAT.Dotnet.Bummer
{
/// <summary>
/// Specifies the functionality of classes that can interpret symbol files
/// and provide a mapping between source code and binary code
/// based on the contained methods.
/// </summary>
public interface IMethodMapper
{
/// <summary>
/// When implemented in a subclass, determines whether this instance
/// can interpret the specified symbol file.
/// </summary>
/// <returns><c>true</c> if this instance can interpret the specified
/// symbol file; <c>false</c>, otherwise.</returns>
/// <param name="pathToSymbolFile">Path to a symbol file.</param>
bool CanInterpretSymbolFile(string pathToSymbolFile);

/// <summary>
/// When implemented in a subclass, gets the method mappings that allow
/// to match binary methods to source methods, by interpreting
/// the specified symbol file.
/// </summary>
/// <returns>The method mappings for the specified symbol file.</returns>
/// <param name="pathToSymbolFile">Path to the symbol file to interpret.</param>
/// <param name="assemblyName">Assembly name to use for the generated mappings (usually the filename without extension).</param>
AssemblyMethodMappings GetMethodMappings(string pathToSymbolFile, string assemblyName);
}
}
Loading