Skip to content

Commit

Permalink
Merge branch 'feature/newcecil'
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Jan 23, 2019
2 parents 03a73dd + 8e9fdaa commit 6124f0e
Show file tree
Hide file tree
Showing 342 changed files with 32,753 additions and 20,943 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
Binary file added Dependencies/Mono.Cecil.Mdb.dll
Binary file not shown.
Binary file added Dependencies/Mono.Cecil.Mdb.pdb
Binary file not shown.
Binary file added Dependencies/Mono.Cecil.Pdb.dll
Binary file not shown.
Binary file added Dependencies/Mono.Cecil.Pdb.pdb
Binary file not shown.
Binary file added Dependencies/Mono.Cecil.dll
Binary file not shown.
Binary file added Dependencies/Mono.Cecil.pdb
Binary file not shown.
258 changes: 240 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
2 changes: 1 addition & 1 deletion ILRuntime/CLR/TypeSystem/ILType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void InitializeInterfaces()
interfaces = new IType[definition.Interfaces.Count];
for (int i = 0; i < interfaces.Length; i++)
{
interfaces[i] = appdomain.GetType(definition.Interfaces[i], this, null);
interfaces[i] = appdomain.GetType(definition.Interfaces[i].InterfaceType, this, null);
//only one clrInterface is valid
if (interfaces[i] is CLRType && firstCLRInterface == null)
{
Expand Down
18 changes: 3 additions & 15 deletions ILRuntime/ILRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil">
<HintPath>..\Dependencies\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -115,21 +118,6 @@
<Compile Include="Runtime\Stack\StackFrame.cs" />
<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>
</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 @@ -94,7 +94,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 @@ -113,7 +113,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 @@ -183,7 +184,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 @@ -198,13 +201,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 @@ -308,7 +312,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 @@ -325,7 +329,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 @@ -403,7 +407,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 @@ -457,7 +462,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
16 changes: 1 addition & 15 deletions ILRuntime/Runtime/Enviorment/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public void LoadAssembly(System.IO.Stream stream)
/// <param name="stream">Assembly Stream</param>
/// <param name="symbol">symbol Stream</param>
/// <param name="symbolReader">symbol 读取器</param>
/// <param name="inMemory">是否完整读入内存</param>
public void LoadAssembly(System.IO.Stream stream, System.IO.Stream symbol, ISymbolReaderProvider symbolReader)
{
var module = ModuleDefinition.ReadModule(stream); //从MONO中加载模块
Expand Down Expand Up @@ -413,7 +414,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 @@ -429,20 +429,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 @@ -4127,7 +4127,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
21 changes: 9 additions & 12 deletions ILRuntimeTest/ILRuntimeTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil">
<HintPath>..\Dependencies\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb">
<HintPath>..\Dependencies\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb">
<HintPath>..\Dependencies\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -234,18 +243,6 @@
<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>
<ProjectReference Include="..\Mono.Cecil.Pdb\Mono.Cecil.Pdb.csproj">
<Project>{cea7a85f-2523-4ad0-8296-6e8e0a2e6df7}</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
13 changes: 9 additions & 4 deletions ILRuntimeTest/TestMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class TestMainForm : Form
{
public static ILRuntime.Runtime.Enviorment.AppDomain _app;
private Assembly _assembly;
FileStream fs, fs2;
private List<TestResultInfo> _resList = new List<TestResultInfo>();
private List<BaseTestUnit> _testUnitList = new List<BaseTestUnit>();

Expand Down Expand Up @@ -103,6 +104,10 @@ private void OnBtnRun(object sender, EventArgs e)

private void OnBtnLoad(object sender, EventArgs e)
{
if (fs != null)
fs.Close();
if (fs2 != null)
fs2.Close();
if (txtPath.Text == "")
{
if (OD.ShowDialog() == DialogResult.OK)
Expand All @@ -118,7 +123,7 @@ private void OnBtnLoad(object sender, EventArgs e)

try
{
using (FileStream fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read))
fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read);
{
var path = Path.GetDirectoryName(txtPath.Text);
var name = Path.GetFileNameWithoutExtension(txtPath.Text);
Expand All @@ -128,14 +133,14 @@ private void OnBtnLoad(object sender, EventArgs e)
pdbPath = Path.Combine(path, name) + ".mdb";
}

using (var fs2 = new System.IO.FileStream(pdbPath, FileMode.Open))
fs2 = new System.IO.FileStream(pdbPath, FileMode.Open);
{
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 6124f0e

Please sign in to comment.