internal void FetchFrames (bool mustFetch = false) { lock (fetchingLocker) { if (fetching || !cacheInvalid) return; cacheInvalid = false; fetching = true; fetchingEvent.Reset (); } vm.conn.Thread_GetFrameInfo (id, 0, -1, (frame_info) => { var framesList = new List<StackFrame> (); for (int i = 0; i < frame_info.Length; ++i) { var frameInfo = (FrameInfo)frame_info [i]; var method = vm.GetMethod (frameInfo.method); var f = new StackFrame (vm, frameInfo.id, this, method, frameInfo.il_offset, frameInfo.flags); if (!(f.IsNativeTransition && !NativeTransitions)) framesList.Add (f); } lock (fetchingLocker) { vm.AddThreadToInvalidateList (this); fetching = false; //In case it was invalidated during waiting for response from //runtime and mustFetch was set refetch if (cacheInvalid && mustFetch) { FetchFrames (mustFetch); return; } frames = framesList.ToArray (); fetchingEvent.Set (); } }); }
public MonoProperty(StackFrame frame, LocalVariable localVariable, TypeMirror typeMirror, Mirror childMirror) { this.frame = frame; this.variable = localVariable; this.mirror = typeMirror; this.childMirror = childMirror; }
bool IsSameAsOurFrame(MDS.StackFrame otherFrame) { if (otherFrame == null) { return(false); } // None of the properties below can throw, all values are cached in the StackFrame instance if (__monoFrame_DONT_USE.Method != otherFrame.Method) { return(false); } if (__monoFrame_DONT_USE.ILOffset != otherFrame.ILOffset) { return(false); } if (__monoFrame_DONT_USE.IsDebuggerInvoke != otherFrame.IsDebuggerInvoke) { return(false); } if (__monoFrame_DONT_USE.IsNativeTransition != otherFrame.IsNativeTransition) { return(false); } // Looks like it could be the correct frame. There's no address so we don't know for sure, // but since the properties above matched AND the frame index is probably the same too, // it's very likely the same frame. return(true); }
DbgEngineStackFrame CreateEngineStackFrame(MDS.StackFrame monoFrame, int frameIndex) { engine.DebuggerThread.VerifyAccess(); var method = monoFrame.Method; if (method == null) { if (monoFrame.IsDebuggerInvoke) { return(engine.ObjectFactory.CreateSpecialStackFrame(dnSpy_Debugger_DotNet_Mono_Resources.StackFrame_FunctionEvaluation)); } if (monoFrame.IsNativeTransition) { return(engine.ObjectFactory.CreateSpecialStackFrame(dnSpy_Debugger_DotNet_Mono_Resources.StackFrame_NativeTransition)); } Debug.Fail("Unknown frame without a method"); return(CreateErrorStackFrame()); } else { var module = engine.TryGetModule(method.DeclaringType.Module); if (module != null) { return(new ILDbgEngineStackFrame(engine, module, monoThread, monoFrame, frameIndex, dbgDotNetCodeLocationFactory)); } Debug.Fail("Creating an error stack frame"); return(CreateErrorStackFrame()); } }
public ExpandedProperty(TypeMirror typeMirror, StackFrame frame, LocalVariable localVariable) { this.frame = frame; this.localVariable = localVariable; var properties = typeMirror.GetProperties().Cast<Mirror>(); var methods = typeMirror.GetMethods().Cast<Mirror>(); var fields = typeMirror.GetFields().Cast<Mirror>(); var children = properties.Concat(methods).Concat(fields); allProperties = children.ToList(); }
protected override EvaluationContext GetEvaluationContext(int frameIndex, EvaluationOptions options) { ValidateStack(); if (frameIndex >= frames.Length) { return(null); } MDB.StackFrame frame = frames [frameIndex]; return(new SoftEvaluationContext(session, frame, options)); }
// FIXME: Cache, invalidate when the thread/runtime is resumed public StackFrame[] GetFrames () { FrameInfo[] frame_info = vm.conn.Thread_GetFrameInfo (id, 0, -1); StackFrame[] frames = new StackFrame [frame_info.Length]; for (int i = 0; i < frame_info.Length; ++i) { FrameInfo info = (FrameInfo)frame_info [i]; MethodMirror method = vm.GetMethod (info.method); frames [i] = new StackFrame (vm, info.id, this, method, info.il_offset, info.flags); } return frames; }
DC.StackFrame CreateStackFrame(MDB.StackFrame frame) { string method = frame.Method.Name; if (frame.Method.DeclaringType != null) { method = frame.Method.DeclaringType.FullName + "." + method; } var location = new DC.SourceLocation(method, frame.FileName, frame.LineNumber); var lang = frame.Method != null? "Managed" : "Native"; return(new DC.StackFrame(frame.ILOffset, frame.Method.FullName, location, lang, session.IsExternalCode(frame), true)); }
public MonoStackFrame(MonoThread thread, DebuggedMonoProcess debuggedMonoProcess, StackFrame frame) { this.thread = thread; this.debuggedMonoProcess = debuggedMonoProcess; this.frame = frame; docContext = new MonoDocumentContext(this.frame.FileName, this.frame.LineNumber, this.frame.ColumnNumber); var locals = frame.GetVisibleVariables().ToList(); this.locals = locals.Select(x => new MonoProperty(frame, x)).ToList(); }
// FIXME: Cache, invalidate when the thread/runtime is resumed public StackFrame[] GetFrames () { FrameInfo[] frame_info = vm.conn.Thread_GetFrameInfo (id, 0, -1); var frames = new List<StackFrame> (); for (int i = 0; i < frame_info.Length; ++i) { FrameInfo info = (FrameInfo)frame_info [i]; MethodMirror method = vm.GetMethod (info.method); var f = new StackFrame (vm, info.id, this, method, info.il_offset, info.flags); if (!(f.IsNativeTransition && !NativeTransitions)) frames.Add (f); } return frames.ToArray (); }
DC.StackFrame CreateStackFrame(MDB.StackFrame frame) { MDB.MethodMirror method = frame.Method; MDB.TypeMirror type = method.DeclaringType; string methodName = method.Name; if (type != null) { methodName = type.FullName + "." + methodName; } var location = new DC.SourceLocation(methodName, SoftDebuggerSession.NormalizePath(frame.FileName), frame.LineNumber); var lang = frame.Method != null ? "Managed" : "Native"; return(new DC.StackFrame(frame.ILOffset, method.FullName, location, lang, session.IsExternalCode(frame), true, type.Module.FullyQualifiedName, type.FullName)); }
public AD7StackFrame(AD7Engine engine, AD7Thread thread, Mono.Debugger.Soft.StackFrame threadContext) { Debug.Assert(threadContext != null, "ThreadContext is null"); Engine = engine; Thread = thread; ThreadContext = threadContext; _textPosition = RoslynHelper.GetStatementRange(ThreadContext.FileName, ThreadContext.LineNumber, ThreadContext.ColumnNumber); _functionName = threadContext.Method.Name; if (_textPosition != null) { docContext = new AD7DocumentContext(_textPosition); } this.LocalVariables = threadContext.GetVisibleVariables().Select(x => new MonoProperty(threadContext, x)).ToList(); }
void UpdateFrame() { var frames = frameThread.GetFrames(); // PERF: It's not likely that frames were removed, so always start searching from the frame index for (int i = frameIndex; i < frames.Length; i++) { var currentFrame = frames[i]; if (IsSameAsOurFrame(currentFrame)) { __monoFrame_DONT_USE = currentFrame; frameIndex = i; methodInvokeCounter = engine.MethodInvokeCounter; return; } } Debug.Fail("Failed to find the frame"); }
public ILDbgEngineStackFrame(DbgEngineImpl engine, DbgModule module, ThreadMirror frameThread, MDS.StackFrame monoFrame, int frameIndex, Lazy <DbgDotNetCodeLocationFactory> dbgDotNetCodeLocationFactory) { this.engine = engine ?? throw new ArgumentNullException(nameof(engine)); this.frameThread = frameThread; __monoFrame_DONT_USE = monoFrame ?? throw new ArgumentNullException(nameof(monoFrame)); this.frameIndex = frameIndex; methodInvokeCounter = engine.MethodInvokeCounter; Module = module ?? throw new ArgumentNullException(nameof(module)); FunctionToken = (uint)monoFrame.Method.MetadataToken; // Native transitions have no IL offset so -1 is used by mono, but we should use 0 instead uint ilOffset = (uint)monoFrame.ILOffset; FunctionOffset = ilOffset == uint.MaxValue ? 0 : ilOffset; var moduleId = DbgEngineImpl.TryGetModuleId(module) ?? default; var options = ilOffset == uint.MaxValue || monoFrame.IsNativeTransition ? DbgDotNetCodeLocationOptions.InvalidOffset : 0; Location = dbgDotNetCodeLocationFactory.Value.Create(moduleId, FunctionToken, FunctionOffset, options); }
void GotStepRanges(MDS.StackFrame frame, object tag, bool isStepInto, GetCodeRangeResult result, uint continueCounter) { engine.VerifyMonoDebugThread(); if (IsClosed) { return; } if (stepData != null) { return; } if (continueCounter != engine.ContinueCounter) { RaiseStepComplete(thread, tag, "Internal error"); return; } // If we failed to find the statement ranges (result.Success == false), step anyway. // We'll just step until the next sequence point instead of not doing anything. var stepIntoOverData = new StepIntoOverData(isStepInto, frame.Method, result.StatementRanges); StartStepIntoOver(tag, stepIntoOverData); }
public AD7StackFrame(AD7Engine engine, AD7Thread thread, Mono.Debugger.Soft.StackFrame threadContext) { Debug.Assert(threadContext != null, "ThreadContext is null"); Engine = engine; this.Thread = thread; this.ThreadContext = threadContext; _textPosition = RoslynHelper.GetStatementRange(ThreadContext.FileName, ThreadContext.LineNumber, ThreadContext.ColumnNumber); _functionName = threadContext.Method.Name; //if(threadContext.IsNativeTransition) //{ //} if (_textPosition != null) { docContext = new AD7DocumentContext(_textPosition); } this.LocalVariables = threadContext.GetVisibleVariables().Select(x => new MonoProperty(threadContext, x)).ToList(); }
DC.StackFrame CreateStackFrame(MDB.StackFrame frame, int frameIndex) { MDB.MethodMirror method = frame.Method; MDB.TypeMirror type = method.DeclaringType; string fileName = frame.FileName; string typeFullName = null; string typeFQN = null; string methodName; if (fileName != null) { fileName = SoftDebuggerSession.NormalizePath(fileName); } if (method.VirtualMachine.Version.AtLeast(2, 12) && method.IsGenericMethod) { StringBuilder name = new StringBuilder(method.Name); name.Append('<'); if (method.VirtualMachine.Version.AtLeast(2, 15)) { bool first = true; foreach (var argumentType in method.GetGenericArguments()) { if (!first) { name.Append(", "); } name.Append(session.Adaptor.GetDisplayTypeName(argumentType.FullName)); first = false; } } name.Append('>'); methodName = name.ToString(); } else { methodName = method.Name; } if (string.IsNullOrEmpty(methodName)) { methodName = "[Function Without Name]"; } // Compiler generated anonymous/lambda methods bool special_method = false; if (methodName [0] == '<' && methodName.Contains(">m__")) { int nidx = methodName.IndexOf(">m__", StringComparison.Ordinal) + 2; methodName = "AnonymousMethod" + methodName.Substring(nidx, method.Name.Length - nidx); special_method = true; } if (type != null) { string typeDisplayName = session.Adaptor.GetDisplayTypeName(type.FullName); if (SoftDebuggerAdaptor.IsGeneratedType(type)) { // The user-friendly method name is embedded in the generated type name var mn = SoftDebuggerAdaptor.GetNameFromGeneratedType(type); // Strip off the generated type name int dot = typeDisplayName.LastIndexOf('.'); var tname = typeDisplayName.Substring(0, dot); // Keep any type arguments int targs = typeDisplayName.LastIndexOf('<'); if (targs > dot + 1) { mn += typeDisplayName.Substring(targs, typeDisplayName.Length - targs); } typeDisplayName = tname; if (special_method) { typeDisplayName += "." + mn; } else { methodName = mn; } } methodName = typeDisplayName + "." + methodName; typeFQN = type.Module.FullyQualifiedName; typeFullName = type.FullName; } bool external = false; bool hidden = false; if (session.VirtualMachine.Version.AtLeast(2, 21)) { var ctx = GetEvaluationContext(frameIndex, session.EvaluationOptions); var hiddenAttr = session.Adaptor.GetType(ctx, "System.Diagnostics.DebuggerHiddenAttribute") as MDB.TypeMirror; hidden = method.GetCustomAttributes(hiddenAttr, true).Any(); } if (hidden) { external = true; } else { external = session.IsExternalCode(frame); if (!external && session.Options.ProjectAssembliesOnly && session.VirtualMachine.Version.AtLeast(2, 21)) { var ctx = GetEvaluationContext(frameIndex, session.EvaluationOptions); var nonUserCodeAttr = session.Adaptor.GetType(ctx, "System.Diagnostics.DebuggerNonUserCodeAttribute") as MDB.TypeMirror; external = method.GetCustomAttributes(nonUserCodeAttr, true).Any(); } } var location = new DC.SourceLocation(methodName, fileName, frame.LineNumber, frame.ColumnNumber, frame.Location.EndLineNumber, frame.Location.EndColumnNumber, frame.Location.SourceFileHash); string addressSpace = string.Empty; bool hasDebugInfo = false; string language; if (frame.Method != null) { if (frame.IsNativeTransition) { language = "Transition"; } else { addressSpace = method.FullName; language = "Managed"; hasDebugInfo = true; } } else { language = "Native"; } return(new SoftDebuggerStackFrame(frame, addressSpace, location, language, external, hasDebugInfo, hidden, typeFQN, typeFullName)); }
public bool IsExternalCode(Mono.Debugger.Soft.StackFrame frame) { return(frame.Method == null || string.IsNullOrEmpty(frame.FileName) || (assemblyFilters != null && !assemblyFilters.Contains(frame.Method.DeclaringType.Assembly))); }
DC.StackFrame CreateStackFrame(MDB.StackFrame frame) { MDB.MethodMirror method = frame.Method; MDB.TypeMirror type = method.DeclaringType; string fileName = frame.FileName; string typeFullName = null; string typeFQN = null; string methodName; if (fileName != null) { fileName = SoftDebuggerSession.NormalizePath(fileName); } if (method.VirtualMachine.Version.AtLeast(2, 12) && method.IsGenericMethod) { StringBuilder name = new StringBuilder(method.Name); name.Append('<'); if (method.VirtualMachine.Version.AtLeast(2, 15)) { bool first = true; foreach (var argumentType in method.GetGenericArguments()) { if (!first) { name.Append(", "); } name.Append(session.Adaptor.GetDisplayTypeName(argumentType.FullName)); first = false; } } name.Append('>'); methodName = name.ToString(); } else { methodName = method.Name; } // Compiler generated anonymous/lambda methods bool special_method = false; if (methodName [0] == '<' && methodName.Contains(">m__")) { int nidx = methodName.IndexOf(">m__") + 2; methodName = "AnonymousMethod" + methodName.Substring(nidx, method.Name.Length - nidx); special_method = true; } if (type != null) { string typeDisplayName = session.Adaptor.GetDisplayTypeName(type.FullName); if (SoftDebuggerAdaptor.IsGeneratedType(type)) { // The user-friendly method name is embedded in the generated type name var mn = SoftDebuggerAdaptor.GetNameFromGeneratedType(type); // Strip off the generated type name int dot = typeDisplayName.LastIndexOf('.'); var tname = typeDisplayName.Substring(0, dot); // Keep any type arguments int targs = typeDisplayName.LastIndexOf('<'); if (targs > dot + 1) { mn += typeDisplayName.Substring(targs, typeDisplayName.Length - targs); } typeDisplayName = tname; if (special_method) { typeDisplayName += "." + mn; } else { methodName = mn; } } methodName = typeDisplayName + "." + methodName; typeFQN = type.Module.FullyQualifiedName; typeFullName = type.FullName; } var location = new DC.SourceLocation(methodName, fileName, frame.LineNumber); var external = session.IsExternalCode(frame); return(new SoftDebuggerStackFrame(frame, method.FullName, location, "Managed", external, true, typeFQN, typeFullName)); }
public LocalVariableBatch (StackFrame frame, LocalVariable[] variables) { this.variables = variables; this.frame = frame; }
public MonoProperty(StackFrame frame, LocalVariable variable) : this(frame, variable, null, null) { }
public SdbStackFrame(MDS.StackFrame obj) : base(obj) { }
public ThisValueReference (EvaluationContext ctx, StackFrame frame) : base (ctx) { this.frame = frame; }
public ThisValueReference(EvaluationContext ctx, StackFrame frame) : base(ctx) { this.frame = frame; }
public SoftDebuggerStackFrame (Mono.Debugger.Soft.StackFrame frame, string addressSpace, SourceLocation location, string language, bool isExternalCode, bool hasDebugInfo, bool isDebuggerHidden, string fullModuleName, string fullTypeName) : base (frame.ILOffset, addressSpace, location, language, isExternalCode, hasDebugInfo, isDebuggerHidden, fullModuleName, fullTypeName) { StackFrame = frame; }
public SoftDebuggerStackFrame(Mono.Debugger.Soft.StackFrame frame, string addressSpace, SourceLocation location, string language, bool isExternalCode, bool hasDebugInfo, bool isDebuggerHidden, string fullModuleName, string fullTypeName) : base(frame.ILOffset, addressSpace, location, language, isExternalCode, hasDebugInfo, isDebuggerHidden, fullModuleName, fullTypeName) { StackFrame = frame; }