Esempio n. 1
0
        public static DkmEvaluationResult DefaultEval(string text, DkmVisualizedExpression expression, bool raw_format)
        {
            if (raw_format && text.Length > 0)
            {
                // Ensure we have the format specifier for raw format, to prevent the evaluator just calling back again to us.
                text = text.TrimEnd(new char[] { ' ' });
                if (text.Last() == ',')
                {
                    text += '!';
                }
                else
                {
                    text += ",!";
                }
            }

            var LangExpr = DkmLanguageExpression.Create(CppLanguage, DkmEvaluationFlags.None, text, null);

            DkmEvaluationResult result;

            try
            {
                expression.EvaluateExpressionCallback(expression.InspectionContext, LangExpr, expression.StackFrame, out result);
            }
            catch (Exception e)
            {
                result = null;
            }
            return(result);
        }
Esempio n. 2
0
		public static DkmEvaluationResult DefaultEval(string text, DkmVisualizedExpression expression, bool raw_format)
		{
			if (raw_format && text.Length > 0)
			{
				// Ensure we have the format specifier for raw format, to prevent the evaluator just calling back again to us.
				int comma = text.IndexOf(',');
				if (comma == -1)
				{
					text += ",!";
				}
				else
				{
					int raw = text.IndexOf('!', comma + 1);
					if (raw == -1)
					{
						text += "!";
					}
				}
			}

			var LangExpr = DkmLanguageExpression.Create(CppLanguage, DkmEvaluationFlags.None, text, null);

			DkmEvaluationResult result;
			try
			{
				expression.EvaluateExpressionCallback(expression.InspectionContext, LangExpr, expression.StackFrame, out result);
			}
			catch(Exception e)
			{
				result = null;
			}
			return result;
		}
Esempio n. 3
0
        public static DkmEvaluationResult DefaultEval(string text, DkmVisualizedExpression expression, bool raw_format)
        {
            if (raw_format && text.Length > 0)
            {
                // Ensure we have the format specifier for raw format, to prevent the evaluator just calling back again to us.
                int comma = text.IndexOf(',');
                if (comma == -1)
                {
                    text += ",!";
                }
                else
                {
                    int raw = text.IndexOf('!', comma + 1);
                    if (raw == -1)
                    {
                        text += "!";
                    }
                }
            }

            var LangExpr = DkmLanguageExpression.Create(CppLanguage, DkmEvaluationFlags.None, text, null);

            DkmEvaluationResult result;

            try
            {
                expression.EvaluateExpressionCallback(expression.InspectionContext, LangExpr, expression.StackFrame, out result);
            }
            catch (Exception e)
            {
                result = null;
            }
            return(result);
        }
Esempio n. 4
0
        public static DkmEvaluationResult Evaluate(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            using (DkmLanguageExpression vexpr = DkmLanguageExpression.Create(CppLanguage, flags, text, data))
            {
                DkmEvaluationResult result = null;
                expr.EvaluateExpressionCallback(expr.InspectionContext, vexpr, expr.StackFrame, out result);

                return(result);
            }
        }
        public static DkmEvaluationResult Evaluate(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            using (DkmLanguageExpression vexpr = DkmLanguageExpression.Create(CppLanguage, flags, text, data))
              {
            DkmEvaluationResult result = null;
            expr.EvaluateExpressionCallback(expr.InspectionContext, vexpr, expr.StackFrame, out result);

            return result;
              }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns child elements of previous evaluation.
        /// </summary>
        public void GetItems(DkmVisualizedExpression visualizedExpression, DkmEvaluationResultEnumContext enumContext, int startIndex, int count, out DkmChildVisualizedExpression[] items)
        {
            // Check if we want to use passthrough visualizer
            PassThroughVisualizer passThroughVisualizer = enumContext.GetDataItem <PassThroughVisualizer>();

            if (passThroughVisualizer != null)
            {
                passThroughVisualizer.GetItems(visualizedExpression, enumContext, startIndex, count, out items);
                return;
            }

            // Execute our regular visualizer
            VSCustomVisualizerEvaluator evaluator = visualizedExpression.GetDataItem <VSCustomVisualizerEvaluator>();

            IResultVisualizer[] itemsAsResults = evaluator.ResultVisualizer.Children.Skip(startIndex).Take(count).ToArray();

            items = new DkmChildVisualizedExpression[itemsAsResults.Length];
            for (int i = 0; i < items.Length; i++)
            {
                IResultVisualizer           item = itemsAsResults[i];
                DkmEvaluationResultCategory category;

                switch (item.DataType)
                {
                case CompletionDataType.Class:
                    category = DkmEvaluationResultCategory.Class;
                    break;

                case CompletionDataType.Property:
                case CompletionDataType.StaticProperty:
                    category = DkmEvaluationResultCategory.Property;
                    break;

                case CompletionDataType.Event:
                    category = DkmEvaluationResultCategory.Event;
                    break;

                case CompletionDataType.Method:
                    category = DkmEvaluationResultCategory.Method;
                    break;

                case CompletionDataType.Enum:
                case CompletionDataType.EnumValue:
                case CompletionDataType.Keyword:
                case CompletionDataType.Namespace:
                case CompletionDataType.StaticClass:
                case CompletionDataType.StaticEvent:
                case CompletionDataType.StaticMethod:
                case CompletionDataType.StaticVariable:
                case CompletionDataType.Unknown:
                case CompletionDataType.Variable:
                default:
                    category = DkmEvaluationResultCategory.Data;
                    break;
                }

                DkmExpressionValueHome valueHome = visualizedExpression.ValueHome;
                ulong  address  = 0;
                string fullName = string.Empty;
                string typeName = null;

                try
                {
                    if (item.Value is Variable variable)
                    {
                        address   = variable.GetPointerAddress();
                        typeName  = variable.GetCodeType().Name;
                        fullName  = $"*(({typeName}*)0x{address:X})";
                        valueHome = DkmPointerValueHome.Create(address);
                    }
                }
                catch
                {
                }

                DkmEvaluationResult result;
                DkmDataItem         dataItem = null;

                if (item.ShouldForceDefaultVisualizer && !string.IsNullOrEmpty(fullName))
                {
                    using (DkmLanguageExpression languageExpression = DkmLanguageExpression.Create(visualizedExpression.InspectionContext.Language, DkmEvaluationFlags.TreatAsExpression, fullName, null))
                    {
                        visualizedExpression.EvaluateExpressionCallback(visualizedExpression.InspectionContext, languageExpression, visualizedExpression.StackFrame, out result);
                    }

                    if (result is DkmSuccessEvaluationResult successResult)
                    {
                        dataItem = new PassThroughVisualizer(successResult);
                        result   = DkmSuccessEvaluationResult.Create(
                            successResult.InspectionContext,
                            successResult.StackFrame,
                            item.Name, // Name - Left column
                            successResult.FullName,
                            successResult.Flags,
                            successResult.Value, // Value - Middle column
                            successResult.EditableValue,
                            successResult.Type,  // Type - Right column
                            category,
                            successResult.Access,
                            successResult.StorageType,
                            successResult.TypeModifierFlags,
                            successResult.Address,
                            successResult.CustomUIVisualizers,
                            successResult.ExternalModules,
                            successResult.RefreshButtonText,
                            dataItem);
                    }
                }
                else
                {
                    result = DkmSuccessEvaluationResult.Create(
                        visualizedExpression.InspectionContext,
                        visualizedExpression.StackFrame,
                        item.Name,        // Name - Left column
                        fullName,         // FullName - What is being copied when "Add to watch"
                        DkmEvaluationResultFlags.ReadOnly | (item.IsExpandable ? DkmEvaluationResultFlags.Expandable : DkmEvaluationResultFlags.None),
                        item.ValueString, // Value - Middle column
                        "",
                        item.Type ?? "",  // Type - Right column
                        category,
                        DkmEvaluationResultAccessType.None,
                        DkmEvaluationResultStorageType.None,
                        DkmEvaluationResultTypeModifierFlags.None,
                        null,
                        VSUIVisualizerService.GetUIVisualizers(item),
                        null,
                        null);
                    dataItem = new VSCustomVisualizerEvaluator(result, item);
                }
                items[i] = DkmChildVisualizedExpression.Create(
                    visualizedExpression.InspectionContext,
                    visualizedExpression.VisualizerId,
                    visualizedExpression.SourceId,
                    visualizedExpression.StackFrame,
                    valueHome,
                    result,
                    visualizedExpression,
                    (uint)(startIndex + i),
                    dataItem);
            }
        }