internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()]; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.GetFunction(); this.chainIndex = chainIndex; this.frameIndex = frameIndex; MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData; int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length; // Class parameters are first, then the method ones List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); // Remove method parametrs at the end corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs); List<DebugType> genArgs = new List<DebugType>(corGenArgs.Count); foreach(ICorDebugType corGenArg in corGenArgs) { genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg)); } DebugType debugType = DebugType.CreateFromCorClass( this.AppDomain, null, corFunction.GetClass(), genArgs.ToArray() ); this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken()); }
public CorValue GetLocalVariable(int index) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { return(null); } ICorDebugValue value; try { ilframe.GetLocalVariable((uint)index, out value); } catch (System.Runtime.InteropServices.COMException e) { // If you are stopped in the Prolog, the variable may not be available. // CORDBG_E_IL_VAR_NOT_AVAILABLE is returned after dubugee triggers StackOverflowException if (e.ErrorCode == (int)HResult.CORDBG_E_IL_VAR_NOT_AVAILABLE) { return(null); } else { throw; } } return((value == null)?null:new CorValue(value)); }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()]; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.GetFunction(); this.chainIndex = chainIndex; this.frameIndex = frameIndex; MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData; int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length; // Class parameters are first, then the method ones List <ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); // Remove method parametrs at the end corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs); List <DebugType> genArgs = new List <DebugType>(corGenArgs.Count); foreach (ICorDebugType corGenArg in corGenArgs) { genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg)); } DebugType debugType = DebugType.CreateFromCorClass( this.AppDomain, null, corFunction.GetClass(), genArgs.ToArray() ); this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken()); }
private ICorDebugILFrame GetILFrame() { if (!m_ilFrameCached) { m_ilFrameCached = true; m_ilFrame = m_frame as ICorDebugILFrame; } return(m_ilFrame); }
public void SetIP(int offset) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { throw new Exception("Cannot set an IP on non-il frame"); } ilframe.SetIP((uint)offset); }
public bool CanSetIP(int offset) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { return(false); } return(ilframe.CanSetIP((uint)offset) == (int)HResult.S_OK); }
public void RemapFunction(int newILOffset) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { throw new Exception("Cannot remap on non-il frame."); } ICorDebugILFrame2 ilframe2 = (ICorDebugILFrame2)ilframe; ilframe2.RemapFunction((uint)newILOffset); }
public bool CanSetIP(int offset, out int hresult) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { hresult = (int)HResult.E_FAIL; return(false); } hresult = ilframe.CanSetIP((uint)offset); return(hresult == (int)HResult.S_OK); }
public void GetIP(out uint offset, out CorDebugMappingResult mappingResult) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { offset = 0; mappingResult = CorDebugMappingResult.MAPPING_NO_INFO; } else { ilframe.GetIP(out offset, out mappingResult); } }
public CorValue GetArgument(int index) { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { return(null); } ICorDebugValue value; ilframe.GetArgument((uint)index, out value); return((value == null)?null:new CorValue(value)); }
Function GetFunctionFromCache(FrameID frameID, ICorDebugILFrame corFrame) { Function function; if (functionCache.TryGetValue(frameID, out function) && !function.HasExpired) { function.CorILFrame = corFrame; return(function); } else { function = new Function(this, frameID, corFrame); functionCache[frameID] = function; return(function); } }
public int GetArgumentCount() { ICorDebugILFrame ilframe = GetILFrame(); if (ilframe == null) { return(-1); } ICorDebugValueEnum ve; ilframe.EnumerateArguments(out ve); uint count; ve.GetCount(out count); return((int)count); }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.Process = thread.Process; this.Thread = thread; this.AppDomain = this.Process.GetAppDomain(corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()); this.corILFrame = corILFrame; this.corILFramePauseSession = this.Process.PauseSession; this.CorFunction = corILFrame.GetFunction(); this.ChainIndex = chainIndex; this.FrameIndex = frameIndex; // Class parameters are first, then the method ones List <ICorDebugType> typeArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); this.Module = thread.Process.GetModule(this.CorFunction.GetModule()); this.MethodInfo = this.Module.Assembly.Compilation.Import(this.CorFunction, typeArgs); }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.Process = thread.Process; this.Thread = thread; this.AppDomain = this.Process.GetAppDomain(corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()); this.corILFrame = corILFrame; this.corILFramePauseSession = this.Process.PauseSession; this.CorFunction = corILFrame.GetFunction(); this.ChainIndex = chainIndex; this.FrameIndex = frameIndex; // Class parameters are first, then the method ones List<ICorDebugType> typeArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); this.Module = thread.Process.GetModule(this.CorFunction.GetModule()); this.MethodInfo = this.Module.Assembly.Compilation.Import(this.CorFunction, typeArgs); }
internal Function(Thread thread, FrameID frameID, ICorDebugILFrame corILFrame) { this.process = thread.Process; this.thread = thread; this.frameID = frameID; this.CorILFrame = corILFrame; corFunction = corILFrame.Function; module = process.GetModule(corFunction.Module); methodProps = module.MetaData.GetMethodProps(corFunction.Token); // Force some callback when function steps out so that we can expire it stepOutStepper = new Stepper(this, "Function Tracker"); stepOutStepper.StepOut(); stepOutStepper.PauseWhenComplete = false; process.TraceMessage("Function " + this.ToString() + " created"); }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.Function; this.chainIndex = chainIndex; this.frameIndex = frameIndex; DebugType debugType = DebugType.Create( this.Process, corFunction.Class, corILFrame.CastTo <ICorDebugILFrame2>().EnumerateTypeParameters().ToList().ToArray() ); this.methodInfo = debugType.GetMethod(corFunction.Token); }
internal unsafe void InitLocalData() { if (_corDebugInit) { return; } _corDebugInit = true; ICorDebugThread3 thread = (ICorDebugThread3)CorDebugThread; ICorDebugStackWalk stackwalk; thread.CreateStackWalk(out stackwalk); do { ICorDebugFrame frame; stackwalk.GetFrame(out frame); ICorDebugILFrame ilFrame = frame as ICorDebugILFrame; if (ilFrame == null) { continue; } byte[] context = ContextHelper.Context; uint size; fixed(byte *ptr = context) stackwalk.GetContext(ContextHelper.ContextFlags, ContextHelper.Length, out size, new IntPtr(ptr)); ulong ip = BitConverter.ToUInt32(context, ContextHelper.InstructionPointerOffset); ulong sp = BitConverter.ToUInt32(context, ContextHelper.StackPointerOffset); DesktopStackFrame result = _stackTrace.Where(frm => sp == frm.StackPointer && ip == frm.InstructionPointer).Select(p => (DesktopStackFrame)p).SingleOrDefault(); if (result != null) { result.CordbFrame = ilFrame; } } while (stackwalk.Next() == 0); }
static ICorDebugValue _FindLocal(string name, ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip) { int varcount; unmScope.GetLocalCount(out varcount); ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount]; unmScope.GetLocals(varcount, out varcount, vars); for (int iv = 0; iv < varcount; iv++) { ISymUnmanagedVariable var = vars[iv]; string varname; { int namelen; var.GetName(0, out namelen, null); StringBuilder sbName = new StringBuilder(namelen); var.GetName(sbName.Capacity, out namelen, sbName); namelen--; // Remove nul. sbName.Length = namelen; varname = sbName.ToString(); } if (name == varname) { int field1; var.GetAddressField1(out field1); ICorDebugValue pvalue; ilframe.GetLocalVariable((uint)field1, out pvalue); return pvalue; } } int cChildren; unmScope.GetChildren(0, out cChildren, null); ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren]; unmScope.GetChildren(children.Length, out cChildren, children); for (int ic = 0; ic < cChildren; ic++) { ICorDebugValue pvalue = _FindLocal(name, ilframe, children[ic], ip); if (null != pvalue) { return pvalue; } } return null; }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.Function; this.chainIndex = chainIndex; this.frameIndex = frameIndex; DebugType debugType = DebugType.Create( this.Process, corFunction.Class, corILFrame.CastTo<ICorDebugILFrame2>().EnumerateTypeParameters().ToList().ToArray() ); this.methodInfo = debugType.GetMethod(corFunction.Token); }
static void _PrintArgs(ICorDebugILFrame ilframe, IMetaDataImport importer, System.IO.TextWriter writer) { uint argcount; { ICorDebugValueEnum ven; ilframe.EnumerateArguments(out ven); ven.GetCount(out argcount); } if (argcount < 1) { return; } uint ftoken; ilframe.GetFunctionToken(out ftoken); System.Reflection.MethodAttributes fattribs; { uint chMethod; uint dwAttr; IntPtr pvSigBlob; uint cbSigBlob; uint ulCodeRVA; uint dwImplFlags; uint ftypedeftoken; int hrmethodprops = (int)importer.GetMethodProps(ftoken, out ftypedeftoken, null, 0, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); char[] methodnamechars = new char[chMethod]; hrmethodprops = (int)importer.GetMethodProps(ftoken, out ftypedeftoken, methodnamechars, (uint)methodnamechars.Length, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); chMethod--; // Remove nul. //MethodName = new string(methodnamechars, 0, (int)chMethod); fattribs = (System.Reflection.MethodAttributes)dwAttr; } List<uint> paramtoks = new List<uint>(); { uint henum = 0; try { uint[] aoneparamtok = new uint[1]; for (; ; ) { uint count; importer.EnumParams(ref henum, ftoken, aoneparamtok, 1, out count); if (1 != count) { break; } paramtoks.Add(aoneparamtok[0]); } } finally { importer.CloseEnum(henum); } } uint ia = 0; int ip = 0; //paramtoks.Count - (int)argcount; for (; ia < argcount; ia++) { string argname; if (0 == ia && System.Reflection.MethodAttributes.Static != (fattribs & System.Reflection.MethodAttributes.Static)) { argname = "this"; } else { if (ip >= paramtoks.Count) { argname = "unnamed_param_" + (1 + ia).ToString(); } else { { uint ptok = paramtoks[ip++]; uint parenttok; uint pulSequence; uint argnamelen = 0; uint dwAttr, dwCPlusTypeFlag, cchValue; IntPtr pValue; importer.GetParamProps(ptok, out parenttok, out pulSequence, null, argnamelen, out argnamelen, out dwAttr, out dwCPlusTypeFlag, out pValue, out cchValue); char[] argnamebuf = new char[argnamelen]; importer.GetParamProps(ptok, out parenttok, out pulSequence, argnamebuf, argnamelen, out argnamelen, out dwAttr, out dwCPlusTypeFlag, out pValue, out cchValue); argnamelen--; // Remove nul. argname = new string(argnamebuf, 0, (int)argnamelen); } } } string argstr; { ICorDebugValue pvalue; ilframe.GetArgument(ia, out pvalue); argstr = ToString(pvalue); } writer.WriteLine("{0}={1}", argname, argstr); } }
Function GetFunctionFromCache(FrameID frameID, ICorDebugILFrame corFrame) { Function function; if (functionCache.TryGetValue(frameID, out function) && !function.HasExpired) { function.CorILFrame = corFrame; return function; } else { function = new Function(this, frameID, corFrame); functionCache[frameID] = function; return function; } }
private ICorDebugILFrame GetILFrame() { if(!m_ilFrameCached) { m_ilFrameCached = true; m_ilFrame = m_frame as ICorDebugILFrame; } return m_ilFrame; }
static void _PrintLocals(ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip, System.IO.TextWriter writer) { int varcount; unmScope.GetLocalCount(out varcount); ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount]; unmScope.GetLocals(varcount, out varcount, vars); for (int iv = 0; iv < varcount; iv++) { ISymUnmanagedVariable var = vars[iv]; string varname; { int namelen; var.GetName(0, out namelen, null); StringBuilder sbName = new StringBuilder(namelen); var.GetName(sbName.Capacity, out namelen, sbName); namelen--; // Remove nul. sbName.Length = namelen; varname = sbName.ToString(); } string valstr; { int field1; var.GetAddressField1(out field1); ICorDebugValue pvalue; ilframe.GetLocalVariable((uint)field1, out pvalue); valstr = ToString(pvalue); } writer.WriteLine("{0}={1}", varname, valstr); } int cChildren; unmScope.GetChildren(0, out cChildren, null); ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren]; unmScope.GetChildren(children.Length, out cChildren, children); for (int ic = 0; ic < cChildren; ic++) { _PrintLocals(ilframe, children[ic], ip, writer); } }
private ICorDebugILFrame GetILFrame() { if(!m_ilFrameCached) { m_ilFrameCached = true; try { m_ilFrame = (ICorDebugILFrame) m_frame; } catch(InvalidCastException ) { m_ilFrame = null; // running on free version without ini file ??? } } return m_ilFrame; }