VariableInfo[] EnumDictionary(IDictionary lst, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[lst.Count]; var keys = GetArray(lst.Keys); var values = GetArray(lst.Values); for (int i = 0; i < lst.Count; i++) { try { var obj = values[i]; VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Type = VariableTypes.IndexAccess; info.Offset = i; info.Value = string.Format("{0},{1}", SafeToString(keys[i]), SafeToString(values[i])); info.Expandable = true; res[i] = info; } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return res; }
VariableInfo[] EnumList(IList lst, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[lst.Count]; for (int i = 0; i < lst.Count; i++) { try { var obj = lst[i]; VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Offset = i; info.Type = VariableTypes.IndexAccess; res[i] = info; } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return res; }
VariableInfo[] EnumArray(Array arr, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[arr.Length]; for(int i = 0; i < arr.Length; i++) { try { var obj = arr.GetValue(i); VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Offset = i; info.Type = VariableTypes.IndexAccess; res[i] = info; } catch(Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return res; }
VariableInfo[] EnumObject(object obj, Type t) { List<VariableInfo> lst = new List<VariableInfo>(); foreach (var i in t.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)) { try { if (i.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false).Length > 0) continue; var val = i.GetValue(obj); VariableInfo info = VariableInfo.FromObject(val); info.Type = VariableTypes.FieldReference; info.TypeName = i.FieldType.FullName; info.Name = i.Name; info.Expandable = !i.FieldType.IsPrimitive && val != null; info.IsPrivate = i.IsPrivate; info.IsProtected = i.IsFamily; lst.Add(info); } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = i.Name; lst.Add(info); } } foreach (var i in t.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)) { try { if (i.GetIndexParameters().Length > 0) continue; var val = i.GetValue(obj, null); VariableInfo info = VariableInfo.FromObject(val); info.Type = VariableTypes.PropertyReference; info.TypeName = i.PropertyType.FullName; info.Name = i.Name; info.Expandable = !i.PropertyType.IsPrimitive && val != null; info.IsPrivate = i.GetGetMethod(true).IsPrivate; info.IsProtected = i.GetGetMethod(true).IsFamily; lst.Add(info); } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = i.Name; lst.Add(info); } } return lst.ToArray(); }
VariableInfo ResolveMember(object obj, string name, out object res) { res = null; Type type = null; if (obj is ILTypeInstance) { type = ((ILTypeInstance)obj).Type.ReflectionType; } else if (obj is Enviorment.CrossBindingAdaptorType) { type = ((Enviorment.CrossBindingAdaptorType)obj).ILInstance.Type.ReflectionType; } else { type = obj.GetType(); } var fi = type.GetField(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (fi != null) { res = fi.GetValue(obj); VariableInfo info = VariableInfo.FromObject(res); info.Address = 0; info.Name = name; info.Type = VariableTypes.FieldReference; info.TypeName = fi.FieldType.FullName; info.IsPrivate = fi.IsPrivate; info.IsProtected = fi.IsFamily; info.Expandable = res != null && !fi.FieldType.IsPrimitive; return(info); } else { var pi = type.GetProperty(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (pi != null) { res = pi.GetValue(obj, null); VariableInfo info = VariableInfo.FromObject(res); info.Address = 0; info.Name = name; info.Type = VariableTypes.PropertyReference; info.TypeName = pi.PropertyType.FullName; info.IsPrivate = pi.GetGetMethod(true).IsPrivate; info.IsProtected = pi.GetGetMethod(true).IsFamily; info.Expandable = res != null && !pi.PropertyType.IsPrimitive; return(info); } } return(VariableInfo.GetCannotFind(name)); }
internal unsafe VariableInfo ResolveIndexAccess(int threadHashCode, VariableReference body, VariableReference idx, out object res) { ILIntepreter intepreter; res = null; if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter)) { object obj; var info = ResolveVariable(threadHashCode, body, out obj); if (obj != null) { object idxObj; info = ResolveVariable(threadHashCode, idx, out idxObj); if (obj is Array) { res = ((Array)obj).GetValue((int)idxObj); info = VariableInfo.FromObject(res); info.Type = VariableTypes.IndexAccess; info.TypeName = obj.GetType().GetElementType().FullName; info.Expandable = res != null && !obj.GetType().GetElementType().IsPrimitive; return(info); } else { if (obj is ILTypeInstance) { var m = ((ILTypeInstance)obj).Type.GetMethod("get_Item"); if (m != null) { res = intepreter.AppDomain.Invoke(m, obj, idxObj); info = VariableInfo.FromObject(res); info.Type = VariableTypes.IndexAccess; info.TypeName = m.ReturnType.FullName; info.Expandable = res != null && !m.ReturnType.IsPrimitive; return(info); } else { return(VariableInfo.NullReferenceExeption); } } else { if (obj is ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType) { throw new NotImplementedException(); } else { if (obj is IDictionary && idxObj is int) { IDictionary dic = (IDictionary)obj; var keys = GetArray(dic.Keys); if (keys[0].GetType() != typeof(int)) { int index = (int)idxObj; var values = GetArray(dic.Values); var t = typeof(KeyValuePair <,>).MakeGenericType(keys[index].GetType(), values[index].GetType()); var ctor = t.GetConstructor(new Type[] { keys[index].GetType(), values[index].GetType() }); res = ctor.Invoke(new object[] { keys[index], values[index] }); info = VariableInfo.FromObject(res); info.Type = VariableTypes.IndexAccess; info.Offset = index; info.TypeName = t.FullName; info.Expandable = true; return(info); } } var pi = obj.GetType().GetProperty("Item"); if (pi != null) { res = pi.GetValue(obj, new object[] { idxObj }); info = VariableInfo.FromObject(res); info.Type = VariableTypes.IndexAccess; info.TypeName = pi.PropertyType.FullName; info.Expandable = res != null && !pi.PropertyType.IsPrimitive; return(info); } else { return(VariableInfo.NullReferenceExeption); } } } } } else { return(VariableInfo.NullReferenceExeption); } } else { return(VariableInfo.NullReferenceExeption); } }
internal unsafe VariableInfo[] EnumChildren(int threadHashCode, VariableReference parent) { ILIntepreter intepreter; if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter)) { object obj; var info = ResolveVariable(threadHashCode, parent, out obj); if (obj != null) { if (obj is Array) { return(EnumArray((Array)obj, intepreter)); } else if (obj is IList) { return(EnumList((IList)obj, intepreter)); } else if (obj is IDictionary) { return(EnumDictionary((IDictionary)obj, intepreter)); } else if (obj is ILTypeInstance) { return(EnumILTypeInstance((ILTypeInstance)obj, intepreter)); } else if (obj is ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType) { return(EnumILTypeInstance(((Enviorment.CrossBindingAdaptorType)obj).ILInstance, intepreter)); } else { return(EnumCLRObject(obj, intepreter)); } } else { return new VariableInfo[] { VariableInfo.NullReferenceExeption } }; } else { return new VariableInfo[] { VariableInfo.NullReferenceExeption } }; } VariableInfo[] EnumArray(Array arr, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[arr.Length]; for (int i = 0; i < arr.Length; i++) { try { var obj = arr.GetValue(i); VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Offset = i; info.Type = VariableTypes.IndexAccess; res[i] = info; } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return(res); } VariableInfo[] EnumList(IList lst, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[lst.Count]; for (int i = 0; i < lst.Count; i++) { try { var obj = lst[i]; VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Offset = i; info.Type = VariableTypes.IndexAccess; res[i] = info; } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return(res); } VariableInfo[] EnumDictionary(IDictionary lst, ILIntepreter intepreter) { VariableInfo[] res = new VariableInfo[lst.Count]; var keys = GetArray(lst.Keys); var values = GetArray(lst.Values); for (int i = 0; i < lst.Count; i++) { try { var obj = values[i]; VariableInfo info = VariableInfo.FromObject(obj, true); info.Name = string.Format("[{0}]", i); info.Type = VariableTypes.IndexAccess; info.Offset = i; info.Value = string.Format("{0},{1}", SafeToString(keys[i]), SafeToString(values[i])); info.Expandable = true; res[i] = info; } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = string.Format("[{0}]", i); res[i] = info; } } return(res); } string SafeToString(object obj) { if (obj != null) { return(obj.ToString()); } else { return("null"); } } object[] GetArray(ICollection lst) { object[] res = new object[lst.Count]; int idx = 0; foreach (var i in lst) { res[idx++] = i; } return(res); } VariableInfo[] EnumILTypeInstance(ILTypeInstance obj, ILIntepreter intepreter) { return(EnumObject(obj, obj.Type.ReflectionType)); } VariableInfo[] EnumCLRObject(object obj, ILIntepreter intepreter) { return(EnumObject(obj, obj.GetType())); } VariableInfo[] EnumObject(object obj, Type t) { List <VariableInfo> lst = new List <VariableInfo>(); foreach (var i in t.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)) { try { if (i.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false).Length > 0) { continue; } var val = i.GetValue(obj); VariableInfo info = VariableInfo.FromObject(val); info.Type = VariableTypes.FieldReference; info.TypeName = i.FieldType.FullName; info.Name = i.Name; info.Expandable = !i.FieldType.IsPrimitive && val != null; info.IsPrivate = i.IsPrivate; info.IsProtected = i.IsFamily; lst.Add(info); } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = i.Name; lst.Add(info); } } foreach (var i in t.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)) { try { if (i.GetIndexParameters().Length > 0) { continue; } var val = i.GetValue(obj, null); VariableInfo info = VariableInfo.FromObject(val); info.Type = VariableTypes.PropertyReference; info.TypeName = i.PropertyType.FullName; info.Name = i.Name; info.Expandable = !i.PropertyType.IsPrimitive && val != null; info.IsPrivate = i.GetGetMethod(true).IsPrivate; info.IsProtected = i.GetGetMethod(true).IsFamily; lst.Add(info); } catch (Exception ex) { var info = VariableInfo.GetException(ex); info.Name = i.Name; lst.Add(info); } } return(lst.ToArray()); }
unsafe StackFrameInfo[] GetStackFrameInfo(ILIntepreter intp) { StackFrame[] frames = intp.Stack.Frames.ToArray(); Mono.Cecil.Cil.Instruction ins = null; ILMethod m; StackFrameInfo[] frameInfos = new StackFrameInfo[frames.Length]; for (int j = 0; j < frames.Length; j++) { StackFrameInfo info = new Debugger.StackFrameInfo(); var f = frames[j]; m = f.Method; info.MethodName = m.ToString(); if (f.Address != null) { ins = m.Definition.Body.Instructions[f.Address.Value]; var seq = FindSequencePoint(ins); if (seq != null) { info.DocumentName = seq.Document.Url; info.StartLine = seq.StartLine - 1; info.StartColumn = seq.StartColumn - 1; info.EndLine = seq.EndLine - 1; info.EndColumn = seq.EndColumn - 1; } } StackFrame topFrame = f; m = topFrame.Method; int argumentCount = m.ParameterCount; if (m.HasThis) { argumentCount++; } info.LocalVariables = new VariableInfo[argumentCount + m.LocalVariableCount]; for (int i = 0; i < argumentCount; i++) { int argIdx = m.HasThis ? i - 1 : i; var arg = Minus(topFrame.LocalVarPointer, argumentCount); string name = null; object v = null; string typeName = null; var val = Add(arg, i); v = StackObject.ToObject(val, intp.AppDomain, intp.Stack.ManagedStack); if (argIdx >= 0) { var lv = m.Definition.Parameters[argIdx]; name = string.IsNullOrEmpty(lv.Name) ? "arg" + lv.Index : lv.Name; typeName = lv.ParameterType.FullName; } else { name = "this"; typeName = m.DeclearingType.FullName; } VariableInfo vinfo = VariableInfo.FromObject(v); vinfo.Address = (long)val; vinfo.Name = name; vinfo.TypeName = typeName; vinfo.Expandable = GetValueExpandable(val, intp.Stack.ManagedStack); info.LocalVariables[i] = vinfo; } for (int i = argumentCount; i < info.LocalVariables.Length; i++) { var locIdx = i - argumentCount; var lv = m.Definition.Body.Variables[locIdx]; 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; VariableInfo vinfo = VariableInfo.FromObject(v); vinfo.Address = (long)val; vinfo.Name = name; vinfo.TypeName = lv.VariableType.FullName; vinfo.Expandable = GetValueExpandable(val, intp.Stack.ManagedStack); info.LocalVariables[i] = vinfo; } frameInfos[j] = info; } return(frameInfos); }