// Sets the next statement to the given stack frame and code context. int IDebugThread2.SetNextStatement(IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { // CLRDBG TODO: This implementation should be changed to call an MI command ulong addr = ((AD7MemoryAddress)codeContext).Address; AD7StackFrame frame = ((AD7StackFrame)stackFrame); if (frame.ThreadContext.Level != 0 || frame.Thread != this || !frame.ThreadContext.pc.HasValue || _engine.DebuggedProcess.MICommandFactory.Mode == MIMode.Clrdbg) { return(Constants.S_FALSE); } string toFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, addr); string fromFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, frame.ThreadContext.pc.Value); if (toFunc != fromFunc) { return(Constants.S_FALSE); } string result = frame.EvaluateExpression("$pc=" + EngineUtils.AsAddr(addr)); if (result != null) { _engine.DebuggedProcess.ThreadCache.MarkDirty(); return(Constants.S_OK); } return(Constants.S_FALSE); }
// Gets the name of the stack frame. // The name of a stack frame is typically the name of the method being executed. int IDebugStackFrame2.GetName(out string name) { name = null; try { if (_functionName != null) { name = _functionName; } else { name = EngineUtils.GetAddressDescription(Engine.DebuggedProcess, ThreadContext.pc.Value); } return(Constants.S_OK); } catch (MIException e) { return(e.HResult); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } }
// Sets the next statement to the given stack frame and code context. int IDebugThread2.SetNextStatement(IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { ulong addr = ((AD7MemoryAddress)codeContext).Address; AD7StackFrame frame = ((AD7StackFrame)stackFrame); if (frame.ThreadContext.Level != 0 || frame.Thread != this || !frame.ThreadContext.pc.HasValue) { return(Constants.S_FALSE); } string toFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, addr); string fromFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, frame.ThreadContext.pc.Value); if (toFunc != fromFunc) { return(Constants.S_FALSE); } string result = frame.EvaluateExpression("$pc=" + EngineUtils.AsAddr(addr, _engine.DebuggedProcess.Is64BitArch)); if (result != null) { _engine.DebuggedProcess.ThreadCache.MarkDirty(); return(Constants.S_OK); } return(Constants.S_FALSE); }
// Determines whether the next statement can be set to the given stack frame and code context. int IDebugThread2.CanSetNextStatement(IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { ulong addr = ((AD7MemoryAddress)codeContext).Address; AD7StackFrame frame = ((AD7StackFrame)stackFrame); if (frame.ThreadContext.Level != 0 || frame.Thread != this || !frame.ThreadContext.pc.HasValue) { return(Constants.S_FALSE); } if (addr == frame.ThreadContext.pc) { return(Constants.S_OK); } string toFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, addr); string fromFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, frame.ThreadContext.pc.Value); if (toFunc != fromFunc) { return(Constants.S_FALSE); } return(Constants.S_OK); }
// Determines whether the next statement can be set to the given stack frame and code context. int IDebugThread2.CanSetNextStatement(IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { // CLRDBG TODO: This implementation should be changed to compare the method token ulong addr = ((AD7MemoryAddress)codeContext).Address; AD7StackFrame frame = ((AD7StackFrame)stackFrame); if (frame.ThreadContext.Level != 0 || frame.Thread != this || !frame.ThreadContext.pc.HasValue || _engine.DebuggedProcess.MICommandFactory.Mode == MIMode.Clrdbg) { return(Constants.S_FALSE); } if (addr == frame.ThreadContext.pc) { return(Constants.S_OK); } string toFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, addr); string fromFunc = EngineUtils.GetAddressDescription(_engine.DebuggedProcess, frame.ThreadContext.pc.Value); if (toFunc != fromFunc) { return(Constants.S_FALSE); } return(Constants.S_OK); }
public string GetAddressDescription(ulong ip) { return(EngineUtils.GetAddressDescription(_debuggedProcess, ip)); }
// Construct a FRAMEINFO for this stack frame with the requested information. public void SetFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, out FRAMEINFO frameInfo, List <SimpleVariableInformation> parameters) { frameInfo = new FRAMEINFO(); DebuggedModule module = ThreadContext.FindModule(Engine.DebuggedProcess); // The debugger is asking for the formatted name of the function which is displayed in the callstack window. // There are several optional parts to this name including the module, argument types and values, and line numbers. // The optional information is requested by setting flags in the dwFieldSpec parameter. if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME) != 0) { // If there is source information, construct a string that contains the module name, function name, and optionally argument names and values. if (_textPosition != null) { frameInfo.m_bstrFuncName = ""; if (module != null && (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_MODULE) != 0) { frameInfo.m_bstrFuncName = System.IO.Path.GetFileName(module.Name) + "!"; } frameInfo.m_bstrFuncName += _functionName; if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS) != 0 && !Engine.DebuggedProcess.MICommandFactory.SupportsFrameFormatting) { frameInfo.m_bstrFuncName += "("; if (parameters != null && parameters.Count > 0) { for (int i = 0; i < parameters.Count; i++) { if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_TYPES) != 0) { frameInfo.m_bstrFuncName += parameters[i].TypeName + " "; } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_NAMES) != 0) { frameInfo.m_bstrFuncName += parameters[i].Name; } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_NAMES) != 0 && (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_VALUES) != 0) { frameInfo.m_bstrFuncName += "="; } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_VALUES) != 0) { frameInfo.m_bstrFuncName += parameters[i].Value; } if (i < parameters.Count - 1) { frameInfo.m_bstrFuncName += ", "; } } } frameInfo.m_bstrFuncName += ")"; } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_LINES) != 0) { frameInfo.m_bstrFuncName += string.Format(CultureInfo.CurrentCulture, " Line {0}", _textPosition.BeginPosition.dwLine + 1); } } else { // No source information, so only return the module name and the instruction pointer. if (_functionName != null) { if (module != null) { frameInfo.m_bstrFuncName = System.IO.Path.GetFileName(module.Name) + '!' + _functionName; } else { frameInfo.m_bstrFuncName = _functionName; } } else if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_MODULE) != 0 && module != null) { frameInfo.m_bstrFuncName = module.Name + '!' + EngineUtils.GetAddressDescription(Engine.DebuggedProcess, ThreadContext.pc.Value); } else { frameInfo.m_bstrFuncName = EngineUtils.GetAddressDescription(Engine.DebuggedProcess, ThreadContext.pc.Value); } } frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FUNCNAME; } // The debugger is requesting the name of the module for this stack frame. if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_MODULE) != 0) { if (module != null) { frameInfo.m_bstrModule = module.Name; } else { frameInfo.m_bstrModule = ""; } frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_MODULE; } // The debugger is requesting the range of memory addresses for this frame. // For the sample engine, this is the contents of the frame pointer. if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_STACKRANGE) != 0) { frameInfo.m_addrMin = ThreadContext.sp; frameInfo.m_addrMax = ThreadContext.sp; frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_STACKRANGE; } // The debugger is requesting the IDebugStackFrame2 value for this frame info. if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FRAME) != 0) { frameInfo.m_pFrame = this; frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FRAME; } // Does this stack frame of symbols loaded? if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_DEBUGINFO) != 0) { frameInfo.m_fHasDebugInfo = _textPosition != null ? 1 : 0; frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_DEBUGINFO; } // Is this frame stale? if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_STALECODE) != 0) { frameInfo.m_fStaleCode = 0; frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_STALECODE; } // The debugger would like a pointer to the IDebugModule2 that contains this stack frame. if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_DEBUG_MODULEP) != 0) { if (module != null) { AD7Module ad7Module = (AD7Module)module.Client; Debug.Assert(ad7Module != null); frameInfo.m_pModule = ad7Module; frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_DEBUG_MODULEP; } } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FLAGS) != 0) { if (_codeCxt == null && _documentCxt == null) { frameInfo.m_dwFlags |= (uint)enum_FRAMEINFO_FLAGS_VALUES.FIFV_ANNOTATEDFRAME; } frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FLAGS; } if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_LANGUAGE) != 0) { Guid unused = Guid.Empty; if (GetLanguageInfo(ref frameInfo.m_bstrLanguage, ref unused) == 0) { frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_LANGUAGE; } } }