Skip to content

Commit

Permalink
upgrade cecil
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Jan 4, 2019
1 parent 4355f06 commit 091ee1b
Show file tree
Hide file tree
Showing 335 changed files with 32,799 additions and 20,934 deletions.
12 changes: 0 additions & 12 deletions CodeGenerationTools/CodeGenerationTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@
<Project>{79ef2f29-89d1-4097-986c-5e4eefe0fa33}</Project>
<Name>ILRuntime</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.20\Mono.Cecil.20.csproj">
<Project>{d3785d8b-4d85-4546-8763-47fc848c13e0}</Project>
<Name>Mono.Cecil.20</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Mdb\Mono.Cecil.Mdb.csproj">
<Project>{86f36240-e07c-4840-9c8b-9cd94c03ec62}</Project>
<Name>Mono.Cecil.Mdb</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Pdb\Mono.Cecil.Pdb.csproj">
<Project>{cea7a85f-2523-4ad0-8296-6e8e0a2e6df7}</Project>
<Name>Mono.Cecil.Pdb</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
334 changes: 316 additions & 18 deletions ILRuntime.sln

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions ILRuntime/CLR/Method/ILMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ public ILMethod(MethodDefinition def, ILType type, ILRuntime.Runtime.Enviorment.

Mono.Cecil.Cil.SequencePoint GetValidSequence(int startIdx, int dir)
{
var cur = DebugService.FindSequencePoint(def.Body.Instructions[startIdx]);
var seqMapping = def.DebugInformation.GetSequencePointMapping();
var cur = DebugService.FindSequencePoint(def.Body.Instructions[startIdx], seqMapping);
while (cur != null && cur.StartLine == 0x0feefee)
{
startIdx += dir;
if (startIdx >= 0 && startIdx < def.Body.Instructions.Count)
{
cur = DebugService.FindSequencePoint(def.Body.Instructions[startIdx]);
cur = DebugService.FindSequencePoint(def.Body.Instructions[startIdx], seqMapping);
}
else
break;
Expand Down
15 changes: 3 additions & 12 deletions ILRuntime/ILRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,11 @@
<Compile Include="Runtime\Stack\StackObject.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mono.Cecil.20\Mono.Cecil.20.csproj">
<Project>{d3785d8b-4d85-4546-8763-47fc848c13e0}</Project>
<Name>Mono.Cecil.20</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Mdb\Mono.Cecil.Mdb.csproj">
<Project>{86f36240-e07c-4840-9c8b-9cd94c03ec62}</Project>
<Name>Mono.Cecil.Mdb</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Pdb\Mono.Cecil.Pdb.csproj">
<Project>{cea7a85f-2523-4ad0-8296-6e8e0a2e6df7}</Project>
<Name>Mono.Cecil.Pdb</Name>
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{d68133bd-1e63-496e-9ede-4fbdbf77b486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
27 changes: 17 additions & 10 deletions ILRuntime/Runtime/Debugger/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal bool Break(ILIntepreter intpreter, Exception ex = null)
return false;
}

public string GetStackTrance(ILIntepreter intepreper)
public string GetStackTrace(ILIntepreter intepreper)
{
StringBuilder sb = new StringBuilder();
ILRuntime.CLR.Method.ILMethod m;
Expand All @@ -110,7 +110,8 @@ public string GetStackTrance(ILIntepreter intepreper)
if (f.Address != null)
{
ins = m.Definition.Body.Instructions[f.Address.Value];
var seq = FindSequencePoint(ins);

var seq = FindSequencePoint(ins, m.Definition.DebugInformation.GetSequencePointMapping());
if (seq != null)
{
document = string.Format("{0}:Line {1}", seq.Document.Url, seq.StartLine);
Expand Down Expand Up @@ -179,7 +180,9 @@ public unsafe string GetLocalVariableInfo(ILIntepreter intepreter)
var v = StackObject.ToObject(val, intepreter.AppDomain, intepreter.Stack.ManagedStack);
if (v == null)
v = "null";
string name = string.IsNullOrEmpty(lv.Name) ? "v" + lv.Index : lv.Name;
string vName = null;
m.Definition.DebugInformation.TryGetName(lv, out vName);
string name = string.IsNullOrEmpty(vName) ? "v" + lv.Index : vName;
sb.AppendFormat("{0} {1} = {2}", lv.VariableType.Name, name, v);
if ((i % 3 == 0 && i != 0) || i == m.LocalVariableCount - 1)
sb.AppendLine();
Expand All @@ -194,13 +197,14 @@ public unsafe string GetLocalVariableInfo(ILIntepreter intepreter)
return sb.ToString();
}

internal static Mono.Cecil.Cil.SequencePoint FindSequencePoint(Mono.Cecil.Cil.Instruction ins)
internal static Mono.Cecil.Cil.SequencePoint FindSequencePoint(Mono.Cecil.Cil.Instruction ins, IDictionary<Mono.Cecil.Cil.Instruction, Mono.Cecil.Cil.SequencePoint> seqMapping)
{
Mono.Cecil.Cil.Instruction cur = ins;
while (cur.SequencePoint == null && cur.Previous != null)
Mono.Cecil.Cil.SequencePoint sp;
while (!seqMapping.TryGetValue(cur, out sp) && cur.Previous != null)
cur = cur.Previous;

return cur.SequencePoint;
return sp;
}

unsafe StackObject* Add(StackObject* a, int b)
Expand Down Expand Up @@ -304,7 +308,7 @@ unsafe internal void CheckShouldBreak(ILMethod method, ILIntepreter intp, int ip

if (lst != null)
{
var sp = method.Definition.Body.Instructions[ip].SequencePoint;
var sp = method.Definition.DebugInformation.GetSequencePoint(method.Definition.Body.Instructions[ip]);
if (sp != null)
{
foreach (var i in lst)
Expand All @@ -321,7 +325,7 @@ unsafe internal void CheckShouldBreak(ILMethod method, ILIntepreter intp, int ip

if (!bpHit)
{
var sp = method.Definition.Body.Instructions[ip].SequencePoint;
var sp = method.Definition.DebugInformation.GetSequencePoint(method.Definition.Body.Instructions[ip]);//.SequencePoint;
if (sp != null && IsSequenceValid(sp))
{
switch (intp.CurrentStepType)
Expand Down Expand Up @@ -399,7 +403,8 @@ unsafe StackFrameInfo[] GetStackFrameInfo(ILIntepreter intp)
if (f.Address != null)
{
ins = m.Definition.Body.Instructions[f.Address.Value];
var seq = FindSequencePoint(ins);

var seq = FindSequencePoint(ins, m.Definition.DebugInformation.GetSequencePointMapping());
if (seq != null)
{
info.DocumentName = seq.Document.Url;
Expand Down Expand Up @@ -451,7 +456,9 @@ unsafe StackFrameInfo[] GetStackFrameInfo(ILIntepreter intp)
var val = Add(topFrame.LocalVarPointer, locIdx);
var v = StackObject.ToObject(val, intp.AppDomain, intp.Stack.ManagedStack);
var type = intp.AppDomain.GetType(lv.VariableType, m.DeclearingType, m);
string name = string.IsNullOrEmpty(lv.Name) ? "v" + lv.Index : lv.Name;
string vName = null;
m.Definition.DebugInformation.TryGetName(lv, out vName);
string name = string.IsNullOrEmpty(vName) ? "v" + lv.Index : vName;
VariableInfo vinfo = VariableInfo.FromObject(v);
vinfo.Address = (long)val;
vinfo.Name = name;
Expand Down
15 changes: 0 additions & 15 deletions ILRuntime/Runtime/Enviorment/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ public void LoadAssembly(System.IO.Stream stream, System.IO.Stream symbol, ISymb
doubleType = GetType("System.Double");
objectType = GetType("System.Object");
}
module.AssemblyResolver.ResolveFailure += AssemblyResolver_ResolveFailure;
#if DEBUG && !DISABLE_ILRUNTIME_DEBUG
debugService.NotifyModuleLoaded(module.Name);
#endif
Expand All @@ -425,20 +424,6 @@ public void AddReferenceBytes(string name, byte[] content)
references[name] = content;
}

private AssemblyDefinition AssemblyResolver_ResolveFailure(object sender, AssemblyNameReference reference)
{
byte[] content;
if (references.TryGetValue(reference.Name, out content))
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(content))
{
return AssemblyDefinition.ReadAssembly(ms);
}
}
else
return null;
}

public void RegisterCLRMethodRedirection(MethodBase mi, CLRRedirectionDelegate func)
{
if (mi == null)
Expand Down
2 changes: 1 addition & 1 deletion ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4113,7 +4113,7 @@ public object Run(ILMethod method, object instance, object[] p)
ex.Data["ThisInfo"] = debugger.GetThisInfo(this);
else
ex.Data["ThisInfo"] = "";
ex.Data["StackTrace"] = debugger.GetStackTrance(this);
ex.Data["StackTrace"] = debugger.GetStackTrace(this);
ex.Data["LocalInfo"] = debugger.GetLocalVariableInfo(this);
}
//Clear call stack
Expand Down
2 changes: 1 addition & 1 deletion ILRuntime/Runtime/Intepreter/ILRuntimeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal ILRuntimeException(string message, ILIntepreter intepreter, CLR.Method.
}
else
{
stackTrace = ds.GetStackTrance(intepreter);
stackTrace = ds.GetStackTrace(intepreter);
if (method.HasThis)
thisInfo = ds.GetThisInfo(intepreter);
else
Expand Down
14 changes: 5 additions & 9 deletions ILRuntimeTest/ILRuntimeTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,14 @@
<Project>{bec78343-4ba2-4757-807f-7cdbf1f70c83}</Project>
<Name>LitJson</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.20\Mono.Cecil.20.csproj">
<Project>{d3785d8b-4d85-4546-8763-47fc848c13e0}</Project>
<Name>Mono.Cecil.20</Name>
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{d68133bd-1e63-496e-9ede-4fbdbf77b486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Pdb\Mono.Cecil.Pdb.csproj">
<Project>{cea7a85f-2523-4ad0-8296-6e8e0a2e6df7}</Project>
<ProjectReference Include="..\Mono.Cecil\symbols\pdb\Mono.Cecil.Pdb.csproj">
<Project>{63e6915c-7ea4-4d76-ab28-0d7191eea626}</Project>
<Name>Mono.Cecil.Pdb</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Mdb\Mono.Cecil.Mdb.csproj">
<Project>{86F36240-E07C-4840-9C8B-9CD94C03EC62}</Project>
<Name>Mono.Cecil.Mdb</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions ILRuntimeTest/TestMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ private void OnBtnLoad(object sender, EventArgs e)
Mono.Cecil.Cil.ISymbolReaderProvider symbolReaderProvider = null;
if (pdbPath.EndsWith (".pdb")) {
symbolReaderProvider = new Mono.Cecil.Pdb.PdbReaderProvider ();
} else if (pdbPath.EndsWith (".mdb")) {
}/* else if (pdbPath.EndsWith (".mdb")) {
symbolReaderProvider = new Mono.Cecil.Mdb.MdbReaderProvider ();
}
}*/

_app.LoadAssembly(fs, fs2, symbolReaderProvider);
_isLoadAssembly = true;
Expand Down
Loading

0 comments on commit 091ee1b

Please sign in to comment.