protected MembersValueNodeProvider(LanguageValueNodeFactory valueNodeFactory, DbgDotNetText name, string expression, MemberValueNodeInfoCollection membersCollection, DbgValueNodeEvaluationOptions evalOptions)
 {
     this.valueNodeFactory = valueNodeFactory;
     Name                   = name;
     Expression             = expression;
     this.membersCollection = membersCollection;
     this.evalOptions       = evalOptions;
 }
Beispiel #2
0
 public MemberValueNodeInfo(DmdMemberInfo member, byte inheritanceLevel)
 {
     Member           = member;
     InheritanceLevel = inheritanceLevel;
     Flags            = GetFlags(member);
     // The caller initializes it later
     Name = default;
 }
Beispiel #3
0
        public TypeVariableValueNode(LanguageValueNodeFactory valueNodeFactory, DbgDotNetTypeVariableInfo info)
        {
            ExpectedType = info.GenericArgumentType;
            Value        = new TypeVariableValue(info.GenericArgumentType);
            var  paramType     = info.GenericParameterType;
            bool isMethodParam = (object)paramType.DeclaringMethod != null;

            ImageName = isMethodParam ? PredefinedDbgValueNodeImageNames.GenericMethodParameter : PredefinedDbgValueNodeImageNames.GenericTypeParameter;
            Name      = new DbgDotNetText(new DbgDotNetTextPart(isMethodParam ? BoxedTextColor.MethodGenericParameter : BoxedTextColor.TypeGenericParameter, valueNodeFactory.EscapeIdentifier(paramType.Name ?? string.Empty)));
        }
        DbgDotNetValueNode CreateValue(DbgEvaluationInfo evalInfo, DbgDotNetText name, DbgDotNetValue value, ReadOnlyCollection <string>?formatSpecifiers, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType, bool isRootExpression, ColumnFormatter?columnFormatter)
        {
            // Could be a by-ref property, local, or parameter.
            if (expectedType.IsByRef)
            {
                if (value.Type.IsByRef)
                {
                    var newValue = value.LoadIndirect();
                    value.Dispose();
                    if (newValue.HasError)
                    {
                        return(CreateError(evalInfo, name, newValue.ErrorMessage !, expression, causesSideEffects));
                    }
                    value = newValue.Value !;
                }
                expectedType = expectedType.GetElementType() !;
            }

            options = PredefinedFormatSpecifiers.GetValueNodeEvaluationOptions(formatSpecifiers, options);
            var  nodeInfo  = new DbgDotNetValueNodeInfo(value, expression);
            bool addParens = isRootExpression && NeedsParentheses(expression);
            DbgDotNetValueNodeProviderResult info;
            bool useProvider        = false;
            var  specialViewOptions = (options & ~(DbgValueNodeEvaluationOptions.ResultsView | DbgValueNodeEvaluationOptions.DynamicView));

            if ((options & DbgValueNodeEvaluationOptions.ResultsView) != 0)
            {
                info        = valueNodeProviderFactory.CreateResultsView(evalInfo, addParens, expectedType, nodeInfo, specialViewOptions);
                useProvider = !(info.ErrorMessage is null);
            }
            else if ((options & DbgValueNodeEvaluationOptions.DynamicView) != 0)
            {
                info        = valueNodeProviderFactory.CreateDynamicView(evalInfo, addParens, expectedType, nodeInfo, specialViewOptions);
                useProvider = true;
            }
            else
            {
                info = valueNodeProviderFactory.Create(evalInfo, addParens, expectedType, nodeInfo, options);
            }
            if (useProvider)
            {
                if (!(info.ErrorMessage is null))
                {
                    return(new DbgDotNetValueNodeImpl(this, info.Provider, name, nodeInfo, expression, PredefinedDbgValueNodeImageNames.Error, true, false, null, null, info.ErrorMessage, new DbgDotNetText(new DbgDotNetTextPart(DbgTextColor.Error, info.ErrorMessage)), formatSpecifiers, columnFormatter));
                }
                Debug2.Assert(!(info.Provider is null));
                return(new DbgDotNetValueNodeImpl(this, info.Provider, name, nodeInfo, expression, info.Provider?.ImageName ?? imageName, true, false, null, null, info.ErrorMessage, info.Provider?.ValueText ?? default, formatSpecifiers, columnFormatter));
            }
            return(new DbgDotNetValueNodeImpl(this, info.Provider, name, nodeInfo, expression, imageName, isReadOnly, causesSideEffects, expectedType, value.Type, info.ErrorMessage, default, formatSpecifiers, columnFormatter));
Beispiel #5
0
 /// <summary>
 /// Creates a successful compiled expression with no error
 /// </summary>
 /// <param name="typeName">Name of type that contains the method to evaluate</param>
 /// <param name="methodName">Name of the method to evaluate</param>
 /// <param name="expression">Original expression</param>
 /// <param name="name">Display name shown in the UI</param>
 /// <param name="flags">Evaluation result flags</param>
 /// <param name="imageName">Image, see <see cref="PredefinedDbgValueNodeImageNames"/></param>
 /// <param name="customTypeInfo">Optional custom type info known by the language expression compiler and the language value formatter</param>
 /// <param name="resultFlags">Result flags</param>
 /// <param name="index">Parameter/local index or -1 if unknown</param>
 /// <returns></returns>
 public static DbgDotNetCompiledExpressionResult Create(string typeName, string methodName, string expression, DbgDotNetText name, DbgEvaluationResultFlags flags, string imageName, DbgDotNetCustomTypeInfo customTypeInfo = null, DbgDotNetCompiledExpressionResultFlags resultFlags = DbgDotNetCompiledExpressionResultFlags.None, int index = -1)
 {
     if (name.Parts == null)
     {
         throw new ArgumentException();
     }
     return(new DbgDotNetCompiledExpressionResult {
         TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName)),
         MethodName = methodName ?? throw new ArgumentNullException(nameof(methodName)),
         Expression = expression ?? throw new ArgumentNullException(nameof(expression)),
         Name = name,
         Flags = flags,
         ImageName = imageName ?? throw new ArgumentNullException(nameof(imageName)),
         CustomTypeInfo = customTypeInfo,
         Index = index,
         ResultFlags = resultFlags,
     });
 public DbgDotNetValueNodeImpl(LanguageValueNodeFactory valueNodeFactory, DbgDotNetValueNodeProvider childNodeProvider, DbgDotNetText name, DbgDotNetValueNodeInfo nodeInfo, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType, DmdType actualType, string errorMessage, DbgDotNetText valueText)
 {
     if (name.Parts == null)
     {
         throw new ArgumentException();
     }
     this.valueNodeFactory  = valueNodeFactory ?? throw new ArgumentNullException(nameof(valueNodeFactory));
     this.childNodeProvider = childNodeProvider;
     this.nodeInfo          = nodeInfo;
     Name              = name;
     Value             = nodeInfo?.DisplayValue;
     Expression        = expression ?? throw new ArgumentNullException(nameof(expression));
     ImageName         = imageName ?? throw new ArgumentNullException(nameof(imageName));
     IsReadOnly        = isReadOnly;
     CausesSideEffects = causesSideEffects;
     ExpectedType      = expectedType;
     ActualType        = actualType;
     ErrorMessage      = errorMessage;
     this.valueText    = valueText;
 }
Beispiel #7
0
 public DbgDotNetValueNodeImpl(LanguageValueNodeFactory valueNodeFactory, DbgDotNetValueNodeProvider?childNodeProvider, DbgDotNetText name, DbgDotNetValueNodeInfo?nodeInfo, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType?expectedType, DmdType?actualType, string?errorMessage, DbgDotNetText valueText, ReadOnlyCollection <string>?formatSpecifiers, ColumnFormatter?columnFormatter)
 {
     if (name.Parts is null && columnFormatter is null)
     {
         throw new ArgumentException();
     }
     this.valueNodeFactory  = valueNodeFactory ?? throw new ArgumentNullException(nameof(valueNodeFactory));
     this.childNodeProvider = childNodeProvider;
     this.nodeInfo          = nodeInfo;
     Name                  = name;
     Value                 = nodeInfo?.DisplayValue;
     Expression            = expression ?? throw new ArgumentNullException(nameof(expression));
     ImageName             = imageName ?? throw new ArgumentNullException(nameof(imageName));
     IsReadOnly            = isReadOnly;
     CausesSideEffects     = causesSideEffects;
     ExpectedType          = expectedType;
     ActualType            = actualType;
     ErrorMessage          = errorMessage;
     this.valueText        = valueText;
     this.formatSpecifiers = formatSpecifiers;
     this.columnFormatter  = columnFormatter;
 }
Beispiel #8
0
        public override DbgDotNetValueNode[] GetChildren(LanguageValueNodeFactory valueNodeFactory, DbgEvaluationContext context, DbgStackFrame frame, ulong index, int count, DbgValueNodeEvaluationOptions options, CancellationToken cancellationToken)
        {
            var runtime      = context.Runtime.GetDotNetRuntime();
            var res          = count == 0 ? Array.Empty <DbgDotNetValueNode>() : new DbgDotNetValueNode[count];
            var valueResults = new List <DbgDotNetValueResult>();
            DbgDotNetValueResult valueResult = default;

            try {
                for (int i = 0; i < res.Length; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    ref var      info         = ref tupleFields[(int)index + i];
                    var          castType     = NeedCast(slotType, nodeInfo.Value.Type) ? nodeInfo.Value.Type : null;
                    var          expression   = valueNodeFactory.GetFieldExpression(nodeInfo.Expression, info.DefaultName, castType, addParens);
                    const string imageName    = PredefinedDbgValueNodeImageNames.FieldPublic;
                    const bool   isReadOnly   = false;
                    var          expectedType = info.Fields[info.Fields.Length - 1].FieldType;

                    var    objValue         = nodeInfo.Value;
                    string errorMessage     = null;
                    bool   valueIsException = false;
                    for (int j = 0; j < info.Fields.Length; j++)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        valueResult = runtime.LoadField(context, frame, objValue, info.Fields[j], cancellationToken);
                        objValue    = valueResult.Value;
                        if (valueResult.HasError)
                        {
                            valueResults.Add(valueResult);
                            errorMessage = valueResult.ErrorMessage;
                            valueResult  = default;
                            break;
                        }
                        if (valueResult.ValueIsException)
                        {
                            valueIsException = true;
                            valueResult      = default;
                            break;
                        }
                        if (j + 1 != info.Fields.Length)
                        {
                            valueResults.Add(valueResult);
                        }
                        valueResult = default;
                    }

                    var name = new DbgDotNetText(new DbgDotNetTextPart(BoxedTextColor.InstanceField, info.DefaultName));
                    DbgDotNetValueNode newNode;
                    if (errorMessage != null)
                    {
                        newNode = valueNodeFactory.CreateError(context, frame, name, errorMessage, expression, false, cancellationToken);
                    }
                    else if (valueIsException)
                    {
                        newNode = valueNodeFactory.Create(context, frame, name, objValue, options, expression, PredefinedDbgValueNodeImageNames.Error, true, false, expectedType, false, cancellationToken);
                    }
                    else
                    {
                        newNode = valueNodeFactory.Create(context, frame, name, objValue, options, expression, imageName, isReadOnly, false, expectedType, false, cancellationToken);
                    }

                    foreach (var vr in valueResults)
                    {
                        vr.Value?.Dispose();
                    }
                    valueResults.Clear();
                    res[i] = newNode;
                }
            }
 public abstract DbgEngineValueNode Create(DbgEvaluationContext context, DbgStackFrame frame, DbgDotNetText name, DbgDotNetValue value, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType, CancellationToken cancellationToken);
        public override DbgDotNetValueNode[] GetChildren(LanguageValueNodeFactory valueNodeFactory, DbgEvaluationInfo evalInfo, ulong index, int count, DbgValueNodeEvaluationOptions options, ReadOnlyCollection <string>?formatSpecifiers)
        {
            var res = count == 0 ? Array.Empty <DbgDotNetValueNode>() : new DbgDotNetValueNode[count];
            DbgDotNetValueResult newValue = default;

            try {
                var output      = ObjectCache.AllocDotNetTextOutput();
                var elementType = valueInfo.Value.Type.GetElementType() !;
                var castType    = NeedCast(slotType, valueInfo.Value.Type) ? valueInfo.Value.Type : null;
                for (int i = 0; i < res.Length; i++)
                {
                    evalInfo.CancellationToken.ThrowIfCancellationRequested();

                    string expression;
                    uint   arrayIndex = (uint)index + (uint)i;
                    newValue = valueInfo.Value.GetArrayElementAt(arrayIndex);

                    if (dimensionInfos.Length == 1)
                    {
                        int baseIndex = (int)arrayIndex + dimensionInfos[0].BaseIndex;
                        expression = valueNodeFactory.GetExpression(valueInfo.Expression, baseIndex, castType, addParens);
                        owner.FormatArrayName(output, baseIndex);
                    }
                    else
                    {
                        uint indexLeft = arrayIndex;
                        Debug2.Assert(indexes is not null);
                        for (int j = dimensionInfos.Length - 1; j >= 0; j--)
                        {
                            indexes[j] = (int)(indexLeft % dimensionInfos[j].Length) + dimensionInfos[j].BaseIndex;
                            indexLeft  = indexLeft / dimensionInfos[j].Length;
                        }
                        expression = valueNodeFactory.GetExpression(valueInfo.Expression, indexes, castType, addParens);
                        owner.FormatArrayName(output, indexes);
                    }

                    var name = output.CreateAndReset();
                    DbgDotNetValueNode?newNode;
                    if (newValue.HasError)
                    {
                        newNode = valueNodeFactory.CreateError(evalInfo, name, newValue.ErrorMessage !, expression, false);
                    }
                    else
                    {
                        newNode = null;
                        if (CSharpDynamicPropertyHelper.IsCSharpDynamicProperty(newValue.Value !.Type))
                        {
                            var info = CSharpDynamicPropertyHelper.GetRealValue(evalInfo, newValue.Value);
                            if (info.name is not null)
                            {
                                newValue.Value.Dispose();
                                name       = new DbgDotNetText(new DbgDotNetTextPart(DbgTextColor.DebugViewPropertyName, info.name));
                                expression = valueNodeFactory.GetFieldExpression(expression, info.valueField.Name, null, false);
                                newNode    = valueNodeFactory.Create(evalInfo, name, info.value, formatSpecifiers, options, expression, PredefinedDbgValueNodeImageNames.DynamicViewElement, true, false, info.valueField.FieldType, false);
                            }
                        }
                        if (newNode is null)
                        {
                            newNode = valueNodeFactory.Create(evalInfo, name, newValue.Value, formatSpecifiers, options, expression, PredefinedDbgValueNodeImageNames.ArrayElement, false, false, elementType, false);
                        }
                    }
                    newValue = default;
                    res[i]   = newNode;
                }
                ObjectCache.Free(ref output);
            }
            catch {
                evalInfo.Context.Process.DbgManager.Close(res.Where(a => a is not null));
                newValue.Value?.Dispose();
                throw;
            }
            return(res);
        }
 internal DbgDotNetValueNode Create(DbgEvaluationInfo evalInfo, DbgDotNetText name, DbgDotNetValueNodeProvider provider, ReadOnlyCollection <string>?formatSpecifiers, DbgValueNodeEvaluationOptions options, string expression, string imageName, DbgDotNetText valueText) =>
 new DbgDotNetValueNodeImpl(this, provider, name, null, expression, imageName, true, false, null, null, null, valueText, formatSpecifiers, null);
 internal DbgDotNetValueNode Create(DbgDotNetValueNodeProvider provider, DbgDotNetText name, DbgDotNetValueNodeInfo nodeInfo, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType, DmdType actualType, string?errorMessage, DbgDotNetText valueText, ReadOnlyCollection <string>?formatSpecifiers) =>
 new DbgDotNetValueNodeImpl(this, provider, name, nodeInfo, expression, imageName, isReadOnly, causesSideEffects, expectedType, actualType, errorMessage, valueText, formatSpecifiers, null);
 /// <summary>
 /// Creates an error value node
 /// </summary>
 /// <param name="evalInfo">Evaluation info</param>
 /// <param name="name">Name</param>
 /// <param name="errorMessage">Error message</param>
 /// <param name="expression">Expression</param>
 /// <param name="causesSideEffects">true if the expression causes side effects</param>
 /// <returns></returns>
 public abstract DbgDotNetValueNode CreateError(DbgEvaluationInfo evalInfo, DbgDotNetText name, string errorMessage, string expression, bool causesSideEffects);
 public abstract DbgEngineValueNode CreateError(DbgEvaluationContext context, DbgStackFrame frame, DbgDotNetText name, string errorMessage, string expression, bool causesSideEffects, CancellationToken cancellationToken);
 public override DbgEngineValueNode Create(DbgEvaluationContext context, DbgStackFrame frame, DbgDotNetText name, DbgDotNetValue value, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType, CancellationToken cancellationToken) =>
 new DbgEngineValueNodeImpl(this, factory.Create(context, frame, name, value, options, expression, imageName, isReadOnly, causesSideEffects, expectedType, cancellationToken));
 /// <summary>
 /// Creates a value node
 /// </summary>
 /// <param name="evalInfo">Evaluation info</param>
 /// <param name="name">Name</param>
 /// <param name="value">Value</param>
 /// <param name="formatSpecifiers">Format specifiers or null</param>
 /// <param name="options">Options</param>
 /// <param name="expression">Expression</param>
 /// <param name="imageName">Image name, see <see cref="PredefinedDbgValueNodeImageNames"/></param>
 /// <param name="isReadOnly">true if it's a read-only value</param>
 /// <param name="causesSideEffects">true if the expression causes side effects</param>
 /// <param name="expectedType">Expected type</param>
 /// <returns></returns>
 public abstract DbgDotNetValueNode Create(DbgEvaluationInfo evalInfo, DbgDotNetText name, DbgDotNetValue value, ReadOnlyCollection <string> formatSpecifiers, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType);
 public override DbgEngineValueNode CreateError(DbgEvaluationContext context, DbgStackFrame frame, DbgDotNetText name, string errorMessage, string expression, bool causesSideEffects, CancellationToken cancellationToken) =>
 new DbgEngineValueNodeImpl(this, factory.CreateError(context, frame, name, errorMessage, expression, causesSideEffects, cancellationToken));
Beispiel #18
0
 public StaticMembersValueNodeProvider(DbgDotNetValueNodeProviderFactory valueNodeProviderFactory, LanguageValueNodeFactory valueNodeFactory, DbgDotNetText name, string expression, MemberValueNodeInfoCollection membersCollection, DbgValueNodeEvaluationOptions evalOptions)
     : base(valueNodeFactory, name, expression, membersCollection, evalOptions)
 {
     this.valueNodeProviderFactory = valueNodeProviderFactory;
 }
 public InstanceMembersValueNodeProvider(LanguageValueNodeFactory valueNodeFactory, DbgDotNetText name, string expression, bool addParens, DmdType slotType, DbgDotNetValue value, MemberValueNodeInfoCollection membersCollection, DbgValueNodeEvaluationOptions evalOptions, string imageName)
     : base(valueNodeFactory, name, expression, membersCollection, evalOptions)
 {
     this.addParens = addParens;
     this.slotType  = slotType;
     this.value     = value;
     this.imageName = imageName;
 }
Beispiel #20
0
 public override DbgEngineValueNode CreateError(DbgEvaluationInfo evalInfo, DbgDotNetText name, string errorMessage, string expression, bool causesSideEffects) =>
 new DbgEngineValueNodeImpl(this, factory.CreateError(evalInfo, name, errorMessage, expression, causesSideEffects));
Beispiel #21
0
 public override DbgEngineValueNode Create(DbgEvaluationInfo evalInfo, DbgDotNetText name, DbgDotNetValue value, ReadOnlyCollection <string> formatSpecifiers, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType) =>
 new DbgEngineValueNodeImpl(this, factory.Create(evalInfo, name, value, formatSpecifiers, options, expression, imageName, isReadOnly, causesSideEffects, expectedType));
Beispiel #22
0
 DebugViewNoResultsValueNode(string expression, string emptyMessage)
 {
     Expression    = expression;
     noResultsName = new DbgDotNetText(new DbgDotNetTextPart(BoxedTextColor.Text, emptyMessage));
 }
Beispiel #23
0
 internal DbgDotNetValueNode Create(DbgEvaluationContext context, DbgDotNetText name, DbgDotNetValueNodeProvider provider, DbgValueNodeEvaluationOptions options, string expression, string imageName, DbgDotNetText valueText) =>