bool TryFormatKeyValuePair(DbgDotNetValue value) { var info = KeyValuePairTypeUtils.TryGetFields(value.Type); if ((object)info.keyField == null) { return(false); } var runtime = context.Runtime.GetDotNetRuntime(); DbgDotNetValueResult keyResult = default, valueResult = default;
public DynamicViewMembersValueNodeProvider(DbgDotNetValueNodeProviderFactory valueNodeProviderFactory, LanguageValueNodeFactory valueNodeFactory, DbgDotNetValue instanceValue, DmdType expectedType, string valueExpression, DmdAppDomain appDomain, DbgValueNodeEvaluationOptions evalOptions) : base(valueNodeFactory, dynamicViewName, valueExpression + ", " + PredefinedFormatSpecifiers.DynamicView, default, evalOptions) { this.valueNodeProviderFactory = valueNodeProviderFactory; this.instanceValue = instanceValue; this.expectedType = expectedType; this.valueExpression = valueExpression; this.appDomain = appDomain; dynamicViewProxyExpression = string.Empty; }
internal bool StoreInstanceField(DbgDotNetValue objValue, DmdFieldInfo field, object value) { var error = runtime.StoreField(context, frame, objValue, field, value, cancellationToken); if (error != null) { throw new InterpreterMessageException(error); } return(true); }
public ResultsViewMembersValueNodeProvider(DbgDotNetValueNodeProviderFactory valueNodeProviderFactory, LanguageValueNodeFactory valueNodeFactory, DmdType enumerableType, DbgDotNetValue instanceValue, DmdType expectedType, string valueExpression, DbgValueNodeEvaluationOptions evalOptions) : base(valueNodeFactory, resultsViewName, valueExpression + ", " + PredefinedFormatSpecifiers.ResultsView, default, evalOptions) { this.valueNodeProviderFactory = valueNodeProviderFactory; this.enumerableType = enumerableType; this.instanceValue = instanceValue; this.expectedType = expectedType; this.valueExpression = valueExpression; resultsViewProxyExpression = string.Empty; }
internal ILValue CreateILValue(DbgDotNetValue value) { try { Debug.Assert(value != null); valuesToDispose.Add(value); return CreateILValueCore(value); } catch { value.Dispose(); throw; } }
internal ILValue CreateILValue(DbgDotNetValue value) { try { valuesToDispose.Add(value); return(CreateILValueCore(value)); } catch { value.Dispose(); throw; } }
public override ulong GetChildCount(DbgEvaluationInfo evalInfo) { if (!initialized) { initialized = true; // Fails if it's not supported by the runtime derefValue = value.LoadIndirect().Value; Debug.Assert((derefValue == null) == ((evalInfo.Runtime.GetDotNetRuntime().Features & DbgDotNetRuntimeFeatures.NoDereferencePointers) != 0)); } return(derefValue != null ? 1UL : 0); }
internal bool StoreIndirect(DbgDotNetValue byRefValue, object value) { Debug.Assert(byRefValue.Type.IsByRef); var error = byRefValue.StoreIndirect(context, frame, value, cancellationToken); if (error != null) { throw new InterpreterMessageException(error); } return(true); }
internal bool StoreIndirect(DbgDotNetValue refValue, object value) { Debug.Assert(refValue.Type.IsByRef || refValue.Type.IsPointer); var error = refValue.StoreIndirect(evalInfo, value); if (error != null) { throw new InterpreterMessageException(error); } return(true); }
internal bool Equals(DbgDotNetValue a, DbgDotNetValue b) { if (a == b) return true; if (a.Type != b.Type) return false; var res = runtime.Equals(a, b); if (res != null) return res.Value; return false; }
internal ILValue LoadReferenceTypeFieldAddress(DbgDotNetValue objValue, DmdFieldInfo field) { Debug.Assert(!field.ReflectedType.IsValueType); var addrValue = runtime.LoadFieldAddress(evalInfo, objValue, field); if (addrValue != null) { Debug.Assert(addrValue.Type.IsByRef); return(new ByRefILValueImpl(this, RecordValue(addrValue))); } return(new ReferenceTypeFieldAddress(this, objValue, field)); }
internal DbgDotNetValue RecordValue(DbgDotNetValue value) { try { cancellationToken.ThrowIfCancellationRequested(); valuesToDispose.Add(value); return(value); } catch { value.Dispose(); throw; } }
internal DbgDotNetValue RecordValue(DbgDotNetValue value) { try { evalInfo.CancellationToken.ThrowIfCancellationRequested(); Debug.Assert(value != null); valuesToDispose.Add(value); return(value); } catch { value.Dispose(); throw; } }
public void Clear(DbgDotNetValue returnValue) { context = null; frame = null; cancellationToken = default; foreach (var v in valuesToDispose) { if (v != returnValue) { v.Dispose(); } } valuesToDispose.Clear(); }
string TryGetExceptionName(DbgDotNetValue exObj) { if (exObj == null) { return(null); } var type = exObj.Type; if (type.IsConstructedGenericType) { type = type.GetGenericTypeDefinition(); } return(type.FullName); }
bool Format(DbgDotNetValue value, TypeState typeState, DisplayPart[] displayParts) { if (displayParts.Length == 0) { return(false); } var evaluator = evalInfo.Context.GetDebuggerDisplayAttributeEvaluator(); foreach (var part in displayParts) { if ((part.Flags & DisplayPartFlags.EvaluateText) == 0) { output.Write(DbgTextColor.DebuggerDisplayAttributeEval, part.Text); } else { var eeState = typeState.GetExpressionEvaluatorState(evalInfo.Context.Language.ExpressionEvaluator, part.Text); DbgDotNetEvalResult evalRes = default; try { var evalInfo2 = new DbgEvaluationInfo(typeState.TypeContext !, evalInfo.Frame, evalInfo.CancellationToken); evalRes = evaluator.Evaluate(evalInfo2, value, part.Text, DbgEvaluationOptions.Expression, eeState); if (evalRes.Error is not null) { output.Write(DbgTextColor.Error, "<<<"); output.Write(DbgTextColor.Error, evalRes.Error); output.Write(DbgTextColor.Error, ">>>"); } else { // Prevent recursive calls var options = this.options | DbgValueFormatterOptions.NoDebuggerDisplay; options &= ~DbgValueFormatterOptions.NoStringQuotes; options = PredefinedFormatSpecifiers.GetValueFormatterOptions(evalRes.FormatSpecifiers, options); languageFormatter.FormatValue(evalInfo, output, evalRes.Value !, options, cultureInfo); } } finally { if (evalRes.Value != value) { evalRes.Value?.Dispose(); } } } } return(true); }
DbgDotNetValueResult CallCore(DbgDotNetValue obj, bool isCallvirt, DmdMethodBase method, ILValue[] arguments) { var options = isCallvirt ? DotNetClassHookCallOptions.IsCallvirt : DotNetClassHookCallOptions.None; foreach (var anyHook in anyClassHooks) { var res = anyHook.Call(options, obj, method, arguments); if (res != null) { return(DbgDotNetValueResult.Create(res)); } } var type = method.DeclaringType; if (type.IsConstructedGenericType) { type = type.GetGenericTypeDefinition(); } var typeName = DmdTypeName.Create(type); if (classHooks.TryGetValue(typeName, out var hook)) { if (DmdWellKnownTypeUtils.TryGetWellKnownType(typeName, out var wellKnownType)) { if (type != type.AppDomain.GetWellKnownType(wellKnownType, isOptional: true)) { hook = null; } } if (hook != null) { var res = hook.Call(options, obj, method, arguments); if (res != null) { return(DbgDotNetValueResult.Create(res)); } } } if (!canFuncEval) { throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } var invokeOptions = isCallvirt ? DbgDotNetInvokeOptions.None : DbgDotNetInvokeOptions.NonVirtual; return(runtime.Call(evalInfo, obj, method, Convert(arguments, method.GetMethodSignature().GetParameterTypes()), invokeOptions)); }
public override void Clear(DbgDotNetValue returnValue) { evalInfo = null; canFuncEval = false; foreach (var v in valuesToDispose) { if (v != returnValue && argumentsProvider.CanDispose(v) && interpreterLocalsProvider.CanDispose(v)) { v.Dispose(); } } valuesToDispose.Clear(); argumentsProvider.Clear(); interpreterLocalsProvider.Clear(); argumentsProvider = null; }
public override void Clear(DbgDotNetValue returnValue) { context = null; frame = null; cancellationToken = default; canFuncEval = false; foreach (var v in valuesToDispose) { if (v != returnValue && argumentsProvider.CanDispose(v) && localsProvider.CanDispose(v)) v.Dispose(); } valuesToDispose.Clear(); argumentsProvider.Clear(); localsProvider.Clear(); argumentsProvider = null; localsProvider = null; reflectionAppDomain = null; }
public void Format(DbgDotNetValue value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } evalInfo.CancellationToken.ThrowIfCancellationRequested(); try { if (recursionCounter++ >= MAX_RECURSION) { OutputWrite("???", DbgTextColor.Error); return; } if (TrySimpleFormat(value)) { return; } var type = value.Type; int tupleArity = TypeFormatterUtils.GetTupleArity(type); if (tupleArity > 0 && TryFormatTuple(value, tupleArity)) { return; } if (KeyValuePairTypeUtils.IsKeyValuePair(type) && TryFormatKeyValuePair(value, KeyValuePairTypeUtils.TryGetFields(value.Type))) { return; } if (DictionaryEntryTypeUtils.IsDictionaryEntry(type) && TryFormatKeyValuePair(value, DictionaryEntryTypeUtils.TryGetFields(value.Type))) { return; } if (TryFormatWithDebuggerAttributes(value)) { return; } if (TryFormatToString(value)) { return; } FormatTypeName(value); } finally { recursionCounter--; } }
protected override string InitializeCore(DbgEvaluationContext context, DbgStackFrame frame, CancellationToken cancellationToken) { if ((evalOptions & DbgValueNodeEvaluationOptions.NoFuncEval) != 0) { return(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } var proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); if ((object)proxyCtor == null) { var loadState = enumerableType.AppDomain.GetOrCreateData <ForceLoadAssemblyState>(); if (Interlocked.Exchange(ref loadState.Counter, 1) == 0) { var loader = new ReflectionAssemblyLoader(context, frame, enumerableType.AppDomain, cancellationToken); if (loader.TryLoadAssembly(GetRequiredAssemblyFullName(context.Runtime))) { proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); } } if ((object)proxyCtor == null) { var asmFilename = GetRequiredAssemblyFilename(context.Runtime); var asm = enumerableType.AppDomain.GetAssembly(Path.GetFileNameWithoutExtension(asmFilename)); if (asm == null) { return(string.Format(dnSpy_Roslyn_Shared_Resources.SystemCoreDllNotLoaded, asmFilename)); } return(string.Format(dnSpy_Roslyn_Shared_Resources.TypeDoesNotExistInAssembly, EnumerableDebugViewHelper.GetDebugViewTypeDisplayName(enumerableType), asmFilename)); } } var runtime = context.Runtime.GetDotNetRuntime(); var proxyTypeResult = runtime.CreateInstance(context, frame, proxyCtor, new[] { instanceValue }, DbgDotNetInvokeOptions.None, cancellationToken); if (proxyTypeResult.HasError) { return(proxyTypeResult.ErrorMessage); } resultsViewProxyExpression = valueNodeProviderFactory.GetNewObjectExpression(proxyCtor, valueExpression); getResultsViewValue = proxyTypeResult.Value; valueNodeProviderFactory.GetMemberCollections(getResultsViewValue.Type, evalOptions, out membersCollection, out _); return(null); }
protected override string InitializeCore(DbgEvaluationInfo evalInfo) { if ((evalOptions & DbgValueNodeEvaluationOptions.NoFuncEval) != 0) { return(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } var proxyCtor = DynamicMetaObjectProviderDebugViewHelper.GetDynamicMetaObjectProviderDebugViewConstructor(appDomain); if ((object)proxyCtor == null) { var loadState = appDomain.GetOrCreateData <ForceLoadAssemblyState>(); if (Interlocked.Exchange(ref loadState.Counter, 1) == 0) { var loader = new ReflectionAssemblyLoader(evalInfo, appDomain); if (loader.TryLoadAssembly(GetRequiredAssemblyFullName(evalInfo.Runtime))) { proxyCtor = DynamicMetaObjectProviderDebugViewHelper.GetDynamicMetaObjectProviderDebugViewConstructor(appDomain); } } if ((object)proxyCtor == null) { var asmFilename = GetRequiredAssemblyFilename(evalInfo.Runtime); var asm = appDomain.GetAssembly(Path.GetFileNameWithoutExtension(asmFilename)); if (asm == null) { return(string.Format(dnSpy_Roslyn_Resources.DynamicViewAssemblyNotLoaded, asmFilename)); } return(string.Format(dnSpy_Roslyn_Resources.TypeDoesNotExistInAssembly, DynamicMetaObjectProviderDebugViewHelper.GetDebugViewTypeDisplayName(), asmFilename)); } } var runtime = evalInfo.Runtime.GetDotNetRuntime(); var proxyTypeResult = runtime.CreateInstance(evalInfo, proxyCtor, new[] { instanceValue }, DbgDotNetInvokeOptions.None); if (proxyTypeResult.HasError) { return(proxyTypeResult.ErrorMessage); } dynamicViewProxyExpression = valueNodeProviderFactory.GetNewObjectExpression(proxyCtor, valueExpression, expectedType); getDynamicViewValue = proxyTypeResult.Value; valueNodeProviderFactory.GetMemberCollections(getDynamicViewValue.Type, evalOptions, out membersCollection, out _); return(null); }
public void Clear(DbgDotNetValue returnValue) { context = null; frame = null; cancellationToken = default; foreach (var v in valuesToDispose) { if (v != returnValue && argumentsProvider.CanDispose(v) && localsProvider.CanDispose(v)) { v.Dispose(); } } valuesToDispose.Clear(); argumentsProvider.Clear(); localsProvider.Clear(); argumentsProvider = null; localsProvider = null; }
internal bool Equals(DbgDotNetValue a, DbgDotNetValue b) { if (a == b) { return(true); } if (a.Type != b.Type) { return(false); } var res = runtime.Equals(a, b); if (res != null) { return(res.Value); } return(false); }
string InitializeEnumerableDebugView(DbgEvaluationInfo evalInfo) { var proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); if ((object)proxyCtor == null) { var loadState = enumerableType.AppDomain.GetOrCreateData <ForceLoadAssemblyState>(); if (Interlocked.Exchange(ref loadState.Counter, 1) == 0) { var loader = new ReflectionAssemblyLoader(evalInfo, enumerableType.AppDomain); if (loader.TryLoadAssembly(GetRequiredAssemblyFullName(evalInfo.Runtime))) { proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); } } if ((object)proxyCtor == null) { var asmFilename = GetRequiredAssemblyFilename(evalInfo.Runtime); var asm = enumerableType.AppDomain.GetAssembly(Path.GetFileNameWithoutExtension(asmFilename)); if (asm == null) { return(string.Format(dnSpy_Roslyn_Resources.SystemCoreDllNotLoaded, asmFilename)); } return(string.Format(dnSpy_Roslyn_Resources.TypeDoesNotExistInAssembly, EnumerableDebugViewHelper.GetDebugViewTypeDisplayName(enumerableType), asmFilename)); } } var runtime = evalInfo.Runtime.GetDotNetRuntime(); var proxyTypeResult = runtime.CreateInstance(evalInfo, proxyCtor, new[] { instanceValue }, DbgDotNetInvokeOptions.None); if (proxyTypeResult.HasError) { return(proxyTypeResult.ErrorMessage); } resultsViewProxyExpression = valueNodeProviderFactory.GetNewObjectExpression(proxyCtor, valueExpression, expectedType); getResultsViewValue = proxyTypeResult.Value; valueNodeProviderFactory.GetMemberCollections(getResultsViewValue.Type, evalOptions, out membersCollection, out _); return(null); }
bool FormatValue(uint index, bool needSpace) { var runtime = evalInfo.Runtime.GetDotNetRuntime(); DbgDotNetValueResult parameterValue = default; DbgDotNetValue dereferencedValue = null; try { parameterValue = runtime.GetParameterValue(evalInfo, index); if (parameterValue.IsNormalResult) { if (needSpace) { WriteSpace(); OutputWrite("=", BoxedTextColor.Operator); WriteSpace(); } needSpace = true; var valueFormatter = new CSharpValueFormatter(output, evalInfo, languageFormatter, valueOptions, cultureInfo); var value = parameterValue.Value; if (value.Type.IsByRef) { value = dereferencedValue = value.LoadIndirect().Value; } if (value == null) { OutputWrite("???", BoxedTextColor.Error); } else { valueFormatter.Format(value); } } } finally { parameterValue.Value?.Dispose(); dereferencedValue?.Dispose(); } return(needSpace); }
bool FormatValue(DbgStackFrame frame, uint index, bool needSpace) { var runtime = context.Runtime.GetDotNetRuntime(); DbgDotNetValueResult parameterValue = default; DbgDotNetValue dereferencedValue = null; try { parameterValue = runtime.GetParameterValue(context, frame, index, cancellationToken); if (parameterValue.IsNormalResult) { if (needSpace) { WriteSpace(); OutputWrite("=", BoxedTextColor.Operator); WriteSpace(); } needSpace = true; var valueFormatter = new VisualBasicValueFormatter(output, context, frame, languageFormatter, valueOptions, cultureInfo, cancellationToken); var value = parameterValue.Value; if (value.Type.IsByRef) { value = dereferencedValue = value.LoadIndirect(); } if (value == null) { OutputWrite("???", BoxedTextColor.Error); } else { valueFormatter.Format(value); } } } finally { parameterValue.Value?.Dispose(); dereferencedValue?.Dispose(); } return(needSpace); }
DbgDotNetRawValue?ReadField_CorDebug(DbgDotNetValueImpl obj, string fieldName) { var field = obj.Type.GetField(fieldName, DmdBindingFlags.Public | DmdBindingFlags.NonPublic | DmdBindingFlags.Instance); Debug.Assert((object)field != null); if ((object)field == null) { return(null); } var dnAppDomain = ((DbgCorDebugInternalAppDomainImpl)obj.Type.AppDomain.GetDebuggerAppDomain().InternalAppDomain).DnAppDomain; var corFieldDeclType = GetType(dnAppDomain.CorAppDomain, field.DeclaringType); var objValue = DbgCorDebugInternalRuntimeImpl.TryGetObjectOrPrimitiveValue(obj.TryGetCorValue(), out int hr); if (objValue == null) { return(null); } if (objValue.IsObject) { // This isn't a generic read-field method, so we won't try to load any classes by calling cctors. var fieldValue = objValue.GetFieldValue(corFieldDeclType.Class, (uint)field.MetadataToken, out hr); if (fieldValue == null) { return(null); } DbgDotNetValue dnValue = null; try { dnValue = CreateDotNetValue_CorDebug(fieldValue, field.AppDomain, tryCreateStrongHandle: false); return(dnValue.GetRawValue()); } finally { dnValue?.Dispose(); } } return(null); }
protected override string InitializeCore(DbgEvaluationContext context, DbgStackFrame frame, CancellationToken cancellationToken) { if ((evalOptions & DbgValueNodeEvaluationOptions.NoFuncEval) != 0) { return(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } var proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); if ((object)proxyCtor == null) { var loadState = enumerableType.AppDomain.GetOrCreateData <ForceLoadAssemblyState>(); if (Interlocked.Increment(ref loadState.Counter) == 1) { var loader = new ReflectionAssemblyLoader(context, frame, enumerableType.AppDomain, cancellationToken); if (loader.TryLoadAssembly(GetRequiredAssemblyFullName(context.Runtime))) { proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); } } if ((object)proxyCtor == null) { return(string.Format(dnSpy_Roslyn_Shared_Resources.SystemCoreDllNotLoaded, GetRequiredAssemblyFileName(context.Runtime))); } } var runtime = context.Runtime.GetDotNetRuntime(); var proxyTypeResult = runtime.CreateInstance(context, frame, proxyCtor, new[] { instanceValue }, cancellationToken); if (proxyTypeResult.HasError) { return(proxyTypeResult.ErrorMessage); } getResultsViewValue = proxyTypeResult.Value; valueNodeProviderFactory.GetMemberCollections(getResultsViewValue.Type, evalOptions, out membersCollection, out _); return(null); }
protected override string InitializeCore(DbgEvaluationContext context, DbgStackFrame frame, CancellationToken cancellationToken) { if ((evalOptions & DbgValueNodeEvaluationOptions.NoFuncEval) != 0) { return(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } var proxyCtor = EnumerableDebugViewHelper.GetEnumerableDebugViewConstructor(enumerableType); if ((object)proxyCtor == null) { var loadState = enumerableType.AppDomain.GetOrCreateData <ForceLoadAssemblyState>(); if (Interlocked.Increment(ref loadState.Counter) == 1) { //TODO: Try to force load the assembly // .NET Framework: // System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // .NET Core: // v1: System.Linq, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a // v2: System.Linq, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a } return(string.Format(dnSpy_Roslyn_Shared_Resources.SystemCoreDllNotLoaded, GetRequiredAssemblyFileName(enumerableType.AppDomain))); } var runtime = context.Runtime.GetDotNetRuntime(); var proxyTypeResult = runtime.CreateInstance(context, frame, proxyCtor, new[] { instanceValue }, cancellationToken); if (proxyTypeResult.HasError) { return(proxyTypeResult.ErrorMessage); } getResultsViewValue = proxyTypeResult.Value; valueNodeProviderFactory.GetMemberCollections(getResultsViewValue.Type, evalOptions, out membersCollection, out _); return(null); }