From bec955938521800f55ff7cec2921f555a29f9d90 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Feb 2019 22:07:47 +0100 Subject: [PATCH] Add ShowCFGContextMenuEntry - requires GraphViz dot.exe in PATH. --- .../Properties/AssemblyInfo.template.cs | 4 +++ ILSpy/Commands/ShowCFGContextMenuEntry.cs | 35 +++++++++++++++++++ ILSpy/ILSpy.csproj | 1 + 3 files changed, 40 insertions(+) create mode 100644 ILSpy/Commands/ShowCFGContextMenuEntry.cs diff --git a/ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs b/ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs index 4d92e6271..6f7a8faa8 100644 --- a/ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs +++ b/ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs @@ -19,6 +19,10 @@ using System.Diagnostics.CodeAnalysis; [assembly: InternalsVisibleTo("ICSharpCode.Decompiler.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")] +#if DEBUG +[assembly: InternalsVisibleTo("ILSpy, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")] +#endif + [assembly: SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly", Justification = "AssemblyInformationalVersion does not need to be a parsable version")] diff --git a/ILSpy/Commands/ShowCFGContextMenuEntry.cs b/ILSpy/Commands/ShowCFGContextMenuEntry.cs new file mode 100644 index 000000000..d1d2e4c51 --- /dev/null +++ b/ILSpy/Commands/ShowCFGContextMenuEntry.cs @@ -0,0 +1,35 @@ +using System; +using System.Windows; +using ICSharpCode.Decompiler.FlowAnalysis; +using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.IL.ControlFlow; + +namespace ICSharpCode.ILSpy.Commands +{ +#if DEBUG + [ExportContextMenuEntry(Header = "DEBUG -- Show CFG")] + internal class ShowCFGContextMenuEntry : IContextMenuEntry + { + public void Execute(TextViewContext context) + { + try { + var container = (BlockContainer)context.Reference.Reference; + var cfg = new ControlFlowGraph(container); + ControlFlowNode.ExportGraph(cfg.cfg).Show(); + } catch (Exception ex) { + MessageBox.Show("Error generating CFG - requires GraphViz dot.exe in PATH" + Environment.NewLine + Environment.NewLine + ex.ToString()); + } + } + + public bool IsEnabled(TextViewContext context) + { + return context.Reference?.Reference is BlockContainer; + } + + public bool IsVisible(TextViewContext context) + { + return context.Reference?.Reference is BlockContainer; + } + } +#endif +} diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index c92cdb436..ab67d108e 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -109,6 +109,7 @@ +