public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { var heap = DebuggerSession.Instance.Runtime.GetHeap(); var type = heap.GetTypeByMethodTable(model.ObjectAddress); if (type == null) { return new[] { new { Signature = "Type not found" } }; } return new[] { new { Name = type.Name, BaseTYpe = type.BaseType.Name, MetadataToken = type.MetadataToken, MethodTable = type.MethodTable, } }; })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { _token = token; _heap = DebuggerSession.Instance.Runtime.GetHeap(); _found = false; var stack = new Stack <ulong>(); foreach (var root in _heap.EnumerateRoots()) { stack.Clear(); stack.Push(root.Object); if (token.IsCancellationRequested) { break; } GetRefChainFromRootToObject(model.ObjectAddress, stack, new HashSet <ulong>()); if (_found) { break; } } var enumerable = from address in stack orderby address ascending let type = _heap.GetObjectType(address) select new { Address = address, Type = type.Name, MetadataToken = type.MetadataToken, }; return enumerable.ToList(); })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { var heap = DebuggerSession.Instance.Heap; var enumerable = from finalizer in DebuggerSession.Instance.Runtime.EnumerateFinalizerQueueObjectAddresses() let type = heap.GetObjectType(finalizer) select new ClrObject(finalizer, type).Fields.Value; return enumerable.ToList(); })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { var heap = DebuggerSession.Instance.Runtime.GetHeap(); ClrType type = heap.GetObjectType(model.ObjectAddress); if (type == null) { return null; } return new ClrObject(model.ObjectAddress, type).Fields.Value; })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { var enumerable = from handle in DebuggerSession.Instance.Runtime.EnumerateHandles() where model.ObjectAddress <= 0 || handle.Address == model.ObjectAddress select new { Address = handle.Address, Type = handle.Type != null ? handle.Type.Name : "{UNKNOWN}", IsStrong = handle.IsStrong, IsPinned = handle.IsPinned, HandlType = handle.HandleType, RefCount = handle.RefCount, DependentTarget = handle.DependentTarget, DependentType = handle.DependentType != null ? handle.DependentType.Name : "{UNKNOWN}", AppDomain = handle.AppDomain != null ? handle.AppDomain.Name : "{UNKNOWN}", }; return enumerable.ToList(); })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { _token = token; uint count; ulong size; GetObjSize(DebuggerSession.Instance.Runtime.GetHeap(), model.ObjectAddress, out count, out size); var enumerable = new List <object> { new { ReferencedCount = count, TotalSize = size } }; var results = new List <object>(); foreach (var item in enumerable) { results.Add(item); if (token.IsCancellationRequested) { break; } } return results; })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => { var heap = DebuggerSession.Instance.Runtime.GetHeap(); // the first 8 bytes is some padding (maybe the first 5 is code stub and the rest some flags) // so we need to read the 7th byte to get the offset to first MethodDesc // and the 6th byte to see the offset inside the MethodDescs slots // then reading from the 8th byte + offset to first MethodDesc + offset to actual method // will give us the correct MethodDesc // It seems that in x86 process there isn't offsets at all, // so just skip the 8 bytes padding and you will get the correct MethodDesc ulong methodHandle; if (DebuggerSession.Instance.Runtime.PointerSize == 4) { heap.ReadPointer(model.ObjectAddress + 8, out methodHandle); } else { var offsetToFirstMethodDescByte = new byte[1]; var offsetInMethodDescTableByte = new byte[1]; heap.ReadMemory(model.ObjectAddress + 7, offsetToFirstMethodDescByte, 0, 1); heap.ReadMemory(model.ObjectAddress + 6, offsetInMethodDescTableByte, 0, 1); // Its only for x64 bit so multiply by 8 bytes heap.ReadPointer(model.ObjectAddress + 8 + offsetToFirstMethodDescByte[0] * 8ul, out var firstMethodDesc); methodHandle = firstMethodDesc + offsetInMethodDescTableByte[0] * 8ul; } var method = DebuggerSession.Instance.Runtime.GetMethodByHandle(methodHandle); //var methodPtrWithOffset = model.ObjectAddress + 5; ////heap.ReadPointer( model.ObjectAddress, out ulong someVal3); ////heap.ReadPointer(methodPtrWithOffset, out ulong someVal4); //heap.ReadPointer(methodPtrWithOffset + 2, out ulong someVal1); //heap.ReadPointer(methodPtrWithOffset + 1, out ulong someVal2); //heap.ReadPointer(methodPtrWithOffset + (someVal1 & 0xFF) * 8 + 3, out ulong baseMethodDesc); ////var offset = Environment.Is64BitProcess ? (someVal2 & 0xFF) * 8 : (someVal2 & 0xFF) * 4; //var offset = (someVal2 & 0xFF) * (ulong)DebuggerSession.Instance.Runtime.PointerSize; //var handle = baseMethodDesc + offset; //var method = DebuggerSession.Instance.Runtime.GetMethodByHandle(handle); if (method == null) { return new[] { new { Signature = "Method not found" } }; } return new[] { new { Signature = method.GetFullSignature(), MetadataToken = method.MetadataToken, MethodDesc = method.MethodDesc, CompilationType = method.CompilationType, EnclosingType = method.Type } }; })); }
public async Task <IEnumerable <object> > Execute(Models.OperationModel model, CancellationToken token, object customeParameter) { return(await DebuggerSession.Instance.ExecuteOperation(() => DebuggerSession.Instance.Runtime.GetHeap().EnumerateBlockingObjects())); }