Deregister Resources on Translation Exception (#133)

* bug fix

* edit
This commit is contained in:
Matthew Jin 2022-05-02 11:35:53 -07:00 коммит произвёл GitHub
Родитель f080ad72f2
Коммит 71c4382f40
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 57 добавлений и 55 удалений

Просмотреть файл

@ -58,16 +58,7 @@ namespace Cilsil.Services
{
foreach (var method in Methods)
{
try
{
ComputeMethodCfg(method);
}
catch (Exception e)
{
Log.WriteError(e.Message);
Log.RecordUnfinishedMethod(method.GetCompatibleFullName(),
method.Body.Instructions.Count);
}
ComputeMethodCfg(method);
i++;
bar.Report((double)i / total);
if (WriteConsoleProgress)
@ -126,53 +117,64 @@ namespace Cilsil.Services
if (!method.IsAbstract && methodBody.Instructions.Count > 0)
{
programState.PushInstruction(methodBody.Instructions.First());
do
try
{
var nextInstruction = programState.PopInstruction();
// Checks if there is a node for the offset that we can reuse.
(var nodeAtOffset, var excessiveVisits) =
programState.GetOffsetNode(
nextInstruction.Offset,
programState.PreviousNode?.BlockEndOffset ??
MethodExceptionHandlers.DefaultHandlerEndOffset);
// We don't reuse nodes of finally handlers.
if (nodeAtOffset != null &&
!programState.MethodExceptionHandlers
.FinallyOffsetToFinallyHandler
.ContainsKey(nextInstruction.Offset) &&
!programState.MethodExceptionHandlers
.CatchOffsetToCatchHandler
.ContainsKey(nextInstruction.Offset))
programState.PushInstruction(methodBody.Instructions.First());
do
{
programState.PreviousNode.Successors.Add(nodeAtOffset);
}
else if (unhandledExceptionCase)
{
Log.WriteWarning($"Unhandled exception-handling.");
Log.RecordUnknownInstruction("unhandled-exception");
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
else if (excessiveVisits)
{
TimeoutMethodCount++;
Log.WriteWarning("Translation timeout.");
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
else if (!InstructionParser.ParseCilInstruction(nextInstruction, programState))
{
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
} while (programState.HasInstruction);
var nextInstruction = programState.PopInstruction();
// Checks if there is a node for the offset that we can reuse.
(var nodeAtOffset, var excessiveVisits) =
programState.GetOffsetNode(
nextInstruction.Offset,
programState.PreviousNode?.BlockEndOffset ??
MethodExceptionHandlers.DefaultHandlerEndOffset);
// We don't reuse nodes of finally handlers.
if (nodeAtOffset != null &&
!programState.MethodExceptionHandlers
.FinallyOffsetToFinallyHandler
.ContainsKey(nextInstruction.Offset) &&
!programState.MethodExceptionHandlers
.CatchOffsetToCatchHandler
.ContainsKey(nextInstruction.Offset))
{
programState.PreviousNode.Successors.Add(nodeAtOffset);
}
else if (unhandledExceptionCase)
{
Log.WriteWarning($"Unhandled exception-handling.");
Log.RecordUnknownInstruction("unhandled-exception");
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
else if (excessiveVisits)
{
TimeoutMethodCount++;
Log.WriteWarning("Translation timeout.");
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
else if (!InstructionParser.ParseCilInstruction(nextInstruction, programState))
{
Log.RecordUnfinishedMethod(programState.Method.GetCompatibleFullName(),
nextInstruction.RemainingInstructionCount());
translationUnfinished = true;
break;
}
} while (programState.HasInstruction);
}
catch (Exception e)
{
translationUnfinished = true;
Log.WriteWarning(e.Message);
Log.RecordUnfinishedMethod(method.GetCompatibleFullName(),
method.Body.Instructions.Count);
}
}
// We add method to cfg only if its translation is finished. Otherwise, we skip that