Handle NotImplemented/NotSupported Exceptions thrown by Cecil (#207)
* fix * bug fix * fix coveragestats * formatting * minor * add additional exception handlign --------- Co-authored-by: Xiaoyu Liu <lixiaoyu@microsoft.com>
This commit is contained in:
Родитель
668d1e1fa5
Коммит
7b912f0558
|
@ -74,12 +74,25 @@ namespace Cilsil
|
|||
/// </summary>
|
||||
public static void PrintCoverageStats(IEnumerable<MethodDefinition> methods)
|
||||
{
|
||||
var totalMethodCount = methods.Count();
|
||||
var failMethodCount = UnfinishedMethods.Count;
|
||||
var succMethodCount = totalMethodCount - failMethodCount;
|
||||
var totalInstr = methods.Sum(m => m.Body.Instructions.Count);
|
||||
var failInstr = UnfinishedMethods.Sum(kv => kv.Value);
|
||||
var succInstr = totalInstr - failInstr;
|
||||
var totalMethodCount = 0;
|
||||
var failMethodCount = 0;
|
||||
var succMethodCount = 0;
|
||||
var totalInstr = 0;
|
||||
var failInstr = 0;
|
||||
var succInstr = 0;
|
||||
try
|
||||
{
|
||||
totalMethodCount = methods.Count();
|
||||
failMethodCount = UnfinishedMethods.Count;
|
||||
succMethodCount = totalMethodCount - failMethodCount;
|
||||
totalInstr = methods.Sum(m => m.Body.Instructions.Count);
|
||||
failInstr = UnfinishedMethods.Sum(kv => kv.Value);
|
||||
succInstr = totalInstr - failInstr;
|
||||
}
|
||||
catch (NotImplementedException ex)
|
||||
{
|
||||
WriteWarning(ex.Message);
|
||||
}
|
||||
|
||||
WriteLine("Coverage Statistics:\n");
|
||||
WriteLine($@"Method successfully translated: {succMethodCount} ({
|
||||
|
|
|
@ -4,6 +4,7 @@ using Cilsil.Cil.Parsers;
|
|||
using Cilsil.Services;
|
||||
using Cilsil.Services.Results;
|
||||
using Cilsil.Sil;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
|
@ -107,8 +108,15 @@ namespace Cilsil
|
|||
new DecoderExceptionFallback()
|
||||
);
|
||||
|
||||
|
||||
File.WriteAllText(cfgtxt ?? "./cfg.txt", cfg.ToString(), Utf8Encoder);
|
||||
try
|
||||
{
|
||||
File.WriteAllText(cfgtxt ?? "./cfg.txt", cfg.ToString(), Utf8Encoder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.WriteWarning("Printing string version of CFG failed.");
|
||||
Log.WriteWarning(e.Message);
|
||||
}
|
||||
cfg.WriteToFile(outcfg);
|
||||
tenv.WriteToFile(outtenv);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ using Cilsil.Sil.Instructions;
|
|||
using Cilsil.Sil.Types;
|
||||
using Cilsil.Utils;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -143,15 +144,29 @@ namespace Cilsil.Services
|
|||
|
||||
private void ComputeMethodCfg(MethodDefinition method)
|
||||
{
|
||||
var methodName = method.GetCompatibleFullName();
|
||||
if (Cfg.Procs.ContainsKey(methodName))
|
||||
string methodName;
|
||||
try
|
||||
{
|
||||
Log.WriteWarning($"Method with duplicate full name found: {methodName }");
|
||||
methodName = method.GetCompatibleFullName();
|
||||
if (Cfg.Procs.ContainsKey(methodName))
|
||||
{
|
||||
Log.WriteWarning($"Method with duplicate full name found: {methodName}");
|
||||
return;
|
||||
}
|
||||
if (method.DebugInformation.SequencePoints.FirstOrDefault() == null)
|
||||
{
|
||||
Log.WriteWarning($"Skipping method not found in source code: {methodName}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (NotImplementedException e)
|
||||
{
|
||||
Log.WriteWarning($"Skipping method {method.GetCompatibleFullName()}: {e.Message}");
|
||||
return;
|
||||
}
|
||||
if (method.DebugInformation.SequencePoints.FirstOrDefault() == null)
|
||||
catch (NotSupportedException e)
|
||||
{
|
||||
Log.WriteWarning($"Skipping method not found in source code: {methodName }");
|
||||
Log.WriteWarning($"Skipping method {method.GetCompatibleFullName()}: {e.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using Cilsil.Services.Results;
|
|||
using Cilsil.Sil;
|
||||
using Cilsil.Sil.Types;
|
||||
using Mono.Cecil;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -95,7 +96,16 @@ namespace Cilsil.Services
|
|||
{
|
||||
foreach (var t in Types)
|
||||
{
|
||||
RegisterCilType(t, tenv);
|
||||
try
|
||||
{
|
||||
RegisterCilType(t, tenv);
|
||||
}
|
||||
catch (NotImplementedException e)
|
||||
{
|
||||
Log.WriteWarning($"Could not parse type {t.FullName}.");
|
||||
Log.WriteWarning($"{e.Message}");
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
bar.Report((double)i / total);
|
||||
if (WriteConsoleProgress)
|
||||
|
|
Загрузка…
Ссылка в новой задаче