Browse Source

Add Pdb2XmlCommand

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
1719115eab
  1. 66
      ILSpy/Commands/Pdb2XmlCommand.cs
  2. 2
      ILSpy/ILSpy.csproj

66
ILSpy/Commands/Pdb2XmlCommand.cs

@ -0,0 +1,66 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#if DEBUG
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using Microsoft.DiaSymReader.Tools;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_File", Header = "DEBUG -- Dump PDB as XML", MenuCategory = "Open", MenuOrder = 2.6)]
sealed class Pdb2XmlCommand : SimpleCommand
{
public override bool CanExecute(object parameter)
{
var selectedNodes = MainWindow.Instance.SelectedNodes;
return selectedNodes?.Any() == true
&& selectedNodes.All(n => n is AssemblyTreeNode asm && !asm.LoadedAssembly.HasLoadError);
}
public override void Execute(object parameter)
{
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
var language = MainWindow.Instance.CurrentLanguage;
var nodes = MainWindow.Instance.SelectedNodes.OfType<AssemblyTreeNode>();
var options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.IncludeMethodSpans | PdbToXmlOptions.IncludeTokens;
MainWindow.Instance.TextView.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
AvalonEditTextOutput output = new AvalonEditTextOutput();
var writer = new TextOutputWriter(output);
foreach (var node in nodes) {
string pdbFileName = Path.ChangeExtension(node.LoadedAssembly.FileName, ".pdb");
if (!File.Exists(pdbFileName)) continue;
using (var pdbStream = File.OpenRead(pdbFileName))
using (var peStream = File.OpenRead(node.LoadedAssembly.FileName))
PdbToXmlConverter.ToXml(writer, pdbStream, peStream, options);
}
return output;
}, ct)).Then(output => MainWindow.Instance.TextView.ShowNodes(output, null, highlighting)).HandleExceptions();
}
}
}
#endif

2
ILSpy/ILSpy.csproj

@ -49,6 +49,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AvalonEdit" Version="5.0.4" /> <PackageReference Include="AvalonEdit" Version="5.0.4" />
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta1-63314-01" />
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="15.5.23" /> <PackageReference Include="Microsoft.VisualStudio.Composition" Version="15.5.23" />
<PackageReference Include="Mono.Cecil" Version="0.10.3" /> <PackageReference Include="Mono.Cecil" Version="0.10.3" />
</ItemGroup> </ItemGroup>
@ -106,6 +107,7 @@
<Compile Include="Commands\CommandWrapper.cs" /> <Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="Commands\ILSpyCommands.cs" /> <Compile Include="Commands\ILSpyCommands.cs" />
<Compile Include="Commands\OpenListCommand.cs" /> <Compile Include="Commands\OpenListCommand.cs" />
<Compile Include="Commands\Pdb2XmlCommand.cs" />
<Compile Include="Commands\RemoveAssembliesWithLoadErrors.cs" /> <Compile Include="Commands\RemoveAssembliesWithLoadErrors.cs" />
<Compile Include="Commands\ShowDebugSteps.cs" /> <Compile Include="Commands\ShowDebugSteps.cs" />
<Compile Include="Commands\SortAssemblyListCommand.cs" /> <Compile Include="Commands\SortAssemblyListCommand.cs" />

Loading…
Cancel
Save