internal static DkmEvaluationResult EvaluateDataAtLuaValue(DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, string name, string fullName, LuaValueDataBase luaValue, DkmEvaluationResultFlags flags, DkmEvaluationResultAccessType access, DkmEvaluationResultStorageType storage)
        {
            var process = stackFrame.Process;

            if (luaValue == null)
            {
                return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, name, fullName, "Null pointer access", DkmEvaluationResultFlags.Invalid, null));
            }

            string value = EvaluateValueAtLuaValue(process, luaValue, inspectionContext.Radix, out string editableValue, ref flags, out DkmDataAddress dataAddress, out string type);

            if (value == null)
            {
                return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, name, fullName, "Failed to read value", DkmEvaluationResultFlags.Invalid, null));
            }

            DkmEvaluationResultCategory          category      = DkmEvaluationResultCategory.Data;
            DkmEvaluationResultTypeModifierFlags typeModifiers = DkmEvaluationResultTypeModifierFlags.None;

            var dataItem = new LuaEvaluationDataItem
            {
                address      = luaValue.originalAddress,
                type         = type,
                fullName     = fullName,
                luaValueData = luaValue
            };

            return(DkmSuccessEvaluationResult.Create(inspectionContext, stackFrame, name, fullName, flags, value, editableValue, type, category, access, storage, typeModifiers, dataAddress, null, null, dataItem));
        }
Beispiel #2
0
        private bool TryGetRegisteredVisualizer(DkmVisualizedExpression expression, out BasicVisualizer visualizer, out DkmFailedEvaluationResult failureResult)
        {
            visualizer    = null;
            failureResult = null;

            if (VisualizerRegistrar.TryCreateVisualizer(expression, out visualizer))
            {
                return(true);
            }

            string name     = null;
            string fullName = null;

            Utility.GetExpressionName(expression, out name, out fullName);

            DkmFailedEvaluationResult failure = DkmFailedEvaluationResult.Create(
                expression.InspectionContext,
                expression.StackFrame,
                name,
                fullName,
                String.Format("No formatter is registered for VisualizerId {0}",
                              expression.VisualizerId),
                DkmEvaluationResultFlags.Invalid,
                null);

            failureResult = failure;
            return(false);
        }
Beispiel #3
0
        private static DkmEvaluationResult CreateEvaluationResult(
            DkmInspectionContext inspectionContext,
            DkmClrValue value,
            string name,
            string typeName,
            string display,
            EvalResultDataItem dataItem)
        {
            if (value.IsError())
            {
                // Evaluation failed
                return(DkmFailedEvaluationResult.Create(
                           InspectionContext: inspectionContext,
                           StackFrame: value.StackFrame,
                           Name: name,
                           FullName: dataItem.FullName,
                           ErrorMessage: display,
                           Flags: dataItem.Flags,
                           Type: typeName,
                           DataItem: dataItem));
            }
            else
            {
                ReadOnlyCollection <DkmCustomUIVisualizerInfo> customUIVisualizers = null;

                if (!value.IsNull)
                {
                    DkmCustomUIVisualizerInfo[] customUIVisualizerInfo = value.Type.GetDebuggerCustomUIVisualizerInfo();
                    if (customUIVisualizerInfo != null)
                    {
                        customUIVisualizers = new ReadOnlyCollection <DkmCustomUIVisualizerInfo>(customUIVisualizerInfo);
                    }
                }

                // If the EvalResultData item doesn't specify a particular category, we'll just propagate DkmClrValue.Category,
                // which typically appears to be set to the default value ("Other").
                var category = (dataItem.Category != DkmEvaluationResultCategory.Other) ? dataItem.Category : value.Category;

                // Valid value
                return(DkmSuccessEvaluationResult.Create(
                           InspectionContext: inspectionContext,
                           StackFrame: value.StackFrame,
                           Name: name,
                           FullName: dataItem.FullName,
                           Flags: dataItem.Flags,
                           Value: display,
                           EditableValue: dataItem.EditableValue,
                           Type: typeName,
                           Category: category,
                           Access: value.Access,
                           StorageType: value.StorageType,
                           TypeModifierFlags: value.TypeModifierFlags,
                           Address: value.Address,
                           CustomUIVisualizers: customUIVisualizers,
                           ExternalModules: null,
                           DataItem: dataItem));
            }
        }
Beispiel #4
0
        void IDkmCustomVisualizer.EvaluateVisualizedExpression(DkmVisualizedExpression expression, out DkmEvaluationResult resultObject)
        {
            BasicVisualizer           visualizer    = null;
            DkmFailedEvaluationResult failureResult = null;

            if (!TryGetRegisteredVisualizer(expression, out visualizer, out failureResult))
            {
                resultObject = failureResult;
                return;
            }

            DkmEvaluationResult evalResult     = visualizer.EvaluationResult;
            EvaluationDataItem  resultDataItem = new EvaluationDataItem(expression, evalResult);

            expression.SetDataItem(DkmDataCreationDisposition.CreateAlways, resultDataItem);

            string name     = null;
            string fullName = null;

            Utility.GetExpressionName(expression, out name, out fullName);

            if (evalResult.TagValue == DkmEvaluationResult.Tag.SuccessResult)
            {
                DkmSuccessEvaluationResult successResult = (DkmSuccessEvaluationResult)evalResult;
                resultObject = DkmSuccessEvaluationResult.Create(
                    successResult.InspectionContext,
                    successResult.StackFrame,
                    name,
                    successResult.FullName,
                    successResult.Flags,
                    successResult.Value,
                    successResult.EditableValue,
                    successResult.Type,
                    successResult.Category,
                    successResult.Access,
                    successResult.StorageType,
                    successResult.TypeModifierFlags,
                    successResult.Address,
                    successResult.CustomUIVisualizers,
                    successResult.ExternalModules,
                    resultDataItem);
            }
            else
            {
                DkmFailedEvaluationResult failResult = (DkmFailedEvaluationResult)evalResult;

                resultObject = DkmFailedEvaluationResult.Create(
                    failResult.InspectionContext,
                    failResult.StackFrame,
                    name,
                    fullName,
                    failResult.ErrorMessage,
                    failResult.Flags,
                    null);
                return;
            }
        }
        internal static DkmEvaluationResult GetLuaFunctionChildAtIndex(DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, string fullName, LuaClosureData value, int index)
        {
            var process = stackFrame.Process;

            var processData = DebugHelpers.GetOrCreateDataItem <LuaLocalProcessData>(process);

            if (index == 0)
            {
                if (value == null)
                {
                    return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, "[function]", $"{fullName}.!function", "null", DkmEvaluationResultFlags.Invalid, null));
                }

                var functionData = value.ReadFunction(process);

                if (functionData == null)
                {
                    return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, "[function]", $"{fullName}.!function", "[internal error: failed to read Proto]", DkmEvaluationResultFlags.Invalid, null));
                }

                string source = functionData.ReadSource(process);

                if (source == null)
                {
                    return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, "[function]", $"{fullName}.!function", "[internal error: failed to read source]", DkmEvaluationResultFlags.Invalid, null));
                }

                int line = functionData.definitionStartLine_opt;

                DkmEvaluationResultCategory          category      = DkmEvaluationResultCategory.Method;
                DkmEvaluationResultTypeModifierFlags typeModifiers = DkmEvaluationResultTypeModifierFlags.None;
                DkmEvaluationResultAccessType        access        = DkmEvaluationResultAccessType.Public;
                DkmEvaluationResultStorageType       storage       = DkmEvaluationResultStorageType.Global;

                LuaAddressEntityData entityData = new LuaAddressEntityData
                {
                    source = source,
                    line   = line,

                    functionAddress            = 0,
                    functionInstructionPointer = 0,
                };

                var entityDataBytes = entityData.Encode();

                DkmInstructionAddress instructionAddress = DkmCustomInstructionAddress.Create(processData.runtimeInstance, processData.moduleInstance, entityDataBytes, (ulong)((line << 16) + 0), null, null);

                DkmDataAddress dataAddress = DkmDataAddress.Create(processData.runtimeInstance, value.functionAddress, instructionAddress);

                return(DkmSuccessEvaluationResult.Create(inspectionContext, stackFrame, "[function]", $"{fullName}.!function", DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.Address, $"{source}:{line}", null, "Proto*", category, access, storage, typeModifiers, dataAddress, null, null, null));
            }

            Debug.Assert(false, "Invalid child index");

            return(null);
        }
Beispiel #6
0
        // In VS 2015+, the injection of the child [Python view] node is handled in the PythonDkm.natvis, and the visualizer is only responsible
        // for producing a DkmEvaluationResult for that node.

        public void EvaluateVisualizedExpression(DkmVisualizedExpression visualizedExpression, out DkmEvaluationResult resultObject)
        {
            resultObject = GetPythonView(visualizedExpression);
            if (resultObject == null)
            {
                resultObject = DkmFailedEvaluationResult.Create(
                    visualizedExpression.InspectionContext, visualizedExpression.StackFrame, "[Python view]",
                    null, "Python view is unavailable for this object", DkmEvaluationResultFlags.Invalid, null);
            }
        }
        // In VS 2015+, the injection of the child [Python view] node is handled in the PythonDkm.natvis, and the visualizer is only responsible
        // for producing a DkmEvaluationResult for that node.

        public void EvaluateVisualizedExpression(DkmVisualizedExpression visualizedExpression, out DkmEvaluationResult resultObject)
        {
            resultObject = GetPythonView(visualizedExpression);
            if (resultObject == null)
            {
                resultObject = DkmFailedEvaluationResult.Create(
                    // TODO: Localization - [Python view] also appears in .natvis file, leave as-is for now
                    visualizedExpression.InspectionContext, visualizedExpression.StackFrame, "[Python view]",
                    null, Strings.DebugPythonViewNotAvailableForObject, DkmEvaluationResultFlags.Invalid, null);
            }
        }
 void OnVisualizerMatchFailed(DkmVisualizedExpression expression, out DkmEvaluationResult result)
 {
     result = DkmFailedEvaluationResult.Create(
         expression.InspectionContext,
         expression.StackFrame,
         Utility.GetExpressionName(expression),
         Utility.GetExpressionFullName(expression),
         String.Format("UE4PropVis: No visualizer is registered for VisualizerId {0}", expression.VisualizerId),
         DkmEvaluationResultFlags.Invalid,
         null
         );
 }
Beispiel #9
0
 private static DkmEvaluationResult CreateEvaluationResultFromException(Exception e, EvalResultDataItem dataItem, DkmInspectionContext inspectionContext)
 {
     return(DkmFailedEvaluationResult.Create(
                inspectionContext,
                dataItem.Value.StackFrame,
                Name: dataItem.Name,
                FullName: null,
                ErrorMessage: e.Message,
                Flags: DkmEvaluationResultFlags.None,
                Type: null,
                DataItem: null));
 }
Beispiel #10
0
            internal override void GetRows(
                ResultProvider resultProvider,
                ArrayBuilder <DkmEvaluationResult> rows,
                DkmInspectionContext inspectionContext,
                EvalResultDataItem parent,
                DkmClrValue value,
                int startIndex,
                int count,
                bool visitAll,
                ref int index)
            {
                var memberValue = GetMemberValue(value, _member);

                if (memberValue.IsError())
                {
                    if (InRange(startIndex, count, index))
                    {
                        var row = DkmFailedEvaluationResult.Create(
                            InspectionContext: value.InspectionContext,
                            StackFrame: value.StackFrame,
                            Name: Resources.ErrorName,
                            FullName: null,
                            ErrorMessage: (string)memberValue.HostObjectValue,
                            Flags: DkmEvaluationResultFlags.None,
                            Type: null,
                            DataItem: null);
                        rows.Add(row);
                    }
                    index++;
                }
                else
                {
                    parent = CreateMemberDataItem(
                        resultProvider,
                        inspectionContext,
                        _member,
                        memberValue,
                        parent,
                        ExpansionFlags.IncludeBaseMembers | ExpansionFlags.IncludeResultsView);
                    var expansion = parent.Expansion;
                    if (expansion != null)
                    {
                        expansion.GetRows(resultProvider, rows, inspectionContext, parent, parent.Value, startIndex, count, visitAll, ref index);
                    }
                }
            }
Beispiel #11
0
 internal static DkmEvaluationResult EvalFailedResult(
     string name,
     string message,
     string type     = null,
     string fullName = null,
     DkmEvaluationResultFlags flags = DkmEvaluationResultFlags.None)
 {
     return(DkmFailedEvaluationResult.Create(
                null,
                null,
                name,
                fullName,
                message,
                flags,
                type,
                null));
 }
        internal static DkmEvaluationResult CreateResultsOnly(
            string name,
            DkmClrType declaredType,
            DkmClrValue value,
            EvalResultDataItem parent,
            Formatter formatter)
        {
            string errorMessage;

            if (value.IsError())
            {
                errorMessage = (string)value.HostObjectValue;
            }
            else if (value.HasExceptionThrown(parent))
            {
                errorMessage = value.GetExceptionMessage(name, formatter);
            }
            else
            {
                var enumerableType = GetEnumerableType(value);
                if (enumerableType != null)
                {
                    var expansion = CreateExpansion(value, enumerableType, formatter);
                    if (expansion != null)
                    {
                        return(expansion.CreateEvaluationResult(name, parent, formatter));
                    }
                    errorMessage = Resources.ResultsViewNoSystemCore;
                }
                else
                {
                    errorMessage = Resources.ResultsViewNotEnumerable;
                }
            }

            Debug.Assert(errorMessage != null);
            return(DkmFailedEvaluationResult.Create(
                       InspectionContext: value.InspectionContext,
                       StackFrame: value.StackFrame,
                       Name: name,
                       FullName: null,
                       ErrorMessage: errorMessage,
                       Flags: DkmEvaluationResultFlags.None,
                       Type: null,
                       DataItem: null));
        }
        internal static DkmEvaluationResult EvaluateCppExpression(DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, string name, string expression)
        {
            DkmEvaluationResult result = ExecuteRawExpression(expression, inspectionContext.InspectionSession, inspectionContext.Thread, stackFrame, inspectionContext.Thread.Process.GetNativeRuntimeInstance(), DkmEvaluationFlags.TreatAsExpression);

            if (result is DkmSuccessEvaluationResult success)
            {
                var renamedResult = DkmSuccessEvaluationResult.Create(success.InspectionContext, success.StackFrame, name, success.FullName, success.Flags, success.Value, success.EditableValue, success.Type, success.Category, success.Access, success.StorageType, success.TypeModifierFlags, success.Address, success.CustomUIVisualizers, success.ExternalModules, success.RefreshButtonText, null);

                result.Close();

                return(renamedResult);
            }
            else if (result is DkmFailedEvaluationResult faliure)
            {
                var renamedResult = DkmFailedEvaluationResult.Create(faliure.InspectionContext, faliure.StackFrame, name, faliure.FullName, faliure.ErrorMessage, faliure.Flags, faliure.Type, faliure.Category, null);

                result.Close();

                return(renamedResult);
            }

            return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, name, expression, "Aborted", DkmEvaluationResultFlags.Invalid, "(void*)", null));
        }
Beispiel #14
0
        private void CreateEvaluationResultAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine <DkmEvaluationResult> completionRoutine)
        {
            switch (dataItem.Kind)
            {
            case ExpansionKind.Error:
                completionRoutine(DkmFailedEvaluationResult.Create(
                                      inspectionContext,
                                      StackFrame: stackFrame,
                                      Name: dataItem.Name,
                                      FullName: dataItem.FullName,
                                      ErrorMessage: dataItem.DisplayValue,
                                      Flags: DkmEvaluationResultFlags.None,
                                      Type: null,
                                      DataItem: null));
                break;

            case ExpansionKind.NonPublicMembers:
            case ExpansionKind.StaticMembers:
                completionRoutine(CreateEvaluationResult(
                                      inspectionContext,
                                      dataItem.Value,
                                      dataItem.Name,
                                      typeName: string.Empty,
                                      display: null,
                                      dataItem: dataItem));
                break;

            case ExpansionKind.RawView:
                completionRoutine(CreateEvaluationResult(
                                      inspectionContext,
                                      dataItem.Value,
                                      Resources.RawView,
                                      typeName: string.Empty,
                                      display: null,
                                      dataItem: dataItem));
                break;

            case ExpansionKind.ResultsView:
                completionRoutine(CreateEvaluationResult(
                                      inspectionContext,
                                      dataItem.Value,
                                      dataItem.Name,
                                      typeName: string.Empty,
                                      display: Resources.ResultsViewValueWarning,
                                      dataItem: dataItem));
                break;

            case ExpansionKind.TypeVariables:
                var value = dataItem.Value;
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      dataItem.Name,
                                      dataItem.FullName,
                                      dataItem.Flags,
                                      dataItem.DisplayValue,
                                      EditableValue: null,
                                      Type: dataItem.DisplayValue,
                                      Category: dataItem.Category,
                                      Access: value.Access,
                                      StorageType: value.StorageType,
                                      TypeModifierFlags: value.TypeModifierFlags,
                                      Address: value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: dataItem));
                break;

            default:
                Debug.Assert((dataItem.Kind == ExpansionKind.Default) || (dataItem.Kind == ExpansionKind.PointerDereference));
                // This call will evaluate DebuggerDisplayAttributes.
                GetResultAndContinue(
                    dataItem,
                    workList,
                    declaredType: DkmClrType.Create(dataItem.Value.Type.AppDomain, dataItem.DeclaredType),
                    inspectionContext: inspectionContext,
                    parent: dataItem.Parent,
                    completionRoutine: completionRoutine);
                break;
            }
        }
Beispiel #15
0
        private void CreateEvaluationResultAndContinue(EvalResult result, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine <DkmEvaluationResult> completionRoutine)
        {
            switch (result.Kind)
            {
            case ExpansionKind.Error:
                completionRoutine(DkmFailedEvaluationResult.Create(
                                      inspectionContext,
                                      StackFrame: stackFrame,
                                      Name: result.Name,
                                      FullName: result.FullName,
                                      ErrorMessage: result.DisplayValue,
                                      Flags: DkmEvaluationResultFlags.None,
                                      Type: null,
                                      DataItem: null));
                break;

            case ExpansionKind.NativeView:
            {
                var value    = result.Value;
                var name     = Resources.NativeView;
                var fullName = result.FullName;
                var display  = result.Name;
                DkmEvaluationResult evalResult;
                if (value.IsError())
                {
                    evalResult = DkmFailedEvaluationResult.Create(
                        inspectionContext,
                        stackFrame,
                        Name: name,
                        FullName: fullName,
                        ErrorMessage: display,
                        Flags: result.Flags,
                        Type: null,
                        DataItem: result.ToDataItem());
                }
                else
                {
                    // For Native View, create a DkmIntermediateEvaluationResult.
                    // This will allow the C++ EE to take over expansion.
                    var process = inspectionContext.RuntimeInstance.Process;
                    var cpp     = process.EngineSettings.GetLanguage(new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp));
                    evalResult = DkmIntermediateEvaluationResult.Create(
                        inspectionContext,
                        stackFrame,
                        Name: name,
                        FullName: fullName,
                        Expression: display,
                        IntermediateLanguage: cpp,
                        TargetRuntime: process.GetNativeRuntimeInstance(),
                        DataItem: result.ToDataItem());
                }
                completionRoutine(evalResult);
            }
            break;

            case ExpansionKind.NonPublicMembers:
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      Name: Resources.NonPublicMembers,
                                      FullName: result.FullName,
                                      Flags: result.Flags,
                                      Value: null,
                                      EditableValue: null,
                                      Type: string.Empty,
                                      Category: DkmEvaluationResultCategory.Data,
                                      Access: DkmEvaluationResultAccessType.None,
                                      StorageType: DkmEvaluationResultStorageType.None,
                                      TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                                      Address: result.Value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: result.ToDataItem()));
                break;

            case ExpansionKind.StaticMembers:
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      Name: StaticMembersString,
                                      FullName: result.FullName,
                                      Flags: result.Flags,
                                      Value: null,
                                      EditableValue: null,
                                      Type: string.Empty,
                                      Category: DkmEvaluationResultCategory.Class,
                                      Access: DkmEvaluationResultAccessType.None,
                                      StorageType: DkmEvaluationResultStorageType.None,
                                      TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                                      Address: result.Value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: result.ToDataItem()));
                break;

            case ExpansionKind.RawView:
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      Name: Resources.RawView,
                                      FullName: result.FullName,
                                      Flags: result.Flags,
                                      Value: null,
                                      EditableValue: result.EditableValue,
                                      Type: string.Empty,
                                      Category: DkmEvaluationResultCategory.Data,
                                      Access: DkmEvaluationResultAccessType.None,
                                      StorageType: DkmEvaluationResultStorageType.None,
                                      TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                                      Address: result.Value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: result.ToDataItem()));
                break;

            case ExpansionKind.DynamicView:
            case ExpansionKind.ResultsView:
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      result.Name,
                                      result.FullName,
                                      result.Flags,
                                      result.DisplayValue,
                                      EditableValue: null,
                                      Type: string.Empty,
                                      Category: DkmEvaluationResultCategory.Method,
                                      Access: DkmEvaluationResultAccessType.None,
                                      StorageType: DkmEvaluationResultStorageType.None,
                                      TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                                      Address: result.Value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: result.ToDataItem()));
                break;

            case ExpansionKind.TypeVariable:
                completionRoutine(DkmSuccessEvaluationResult.Create(
                                      inspectionContext,
                                      stackFrame,
                                      result.Name,
                                      result.FullName,
                                      result.Flags,
                                      result.DisplayValue,
                                      EditableValue: null,
                                      Type: result.DisplayValue,
                                      Category: DkmEvaluationResultCategory.Data,
                                      Access: DkmEvaluationResultAccessType.None,
                                      StorageType: DkmEvaluationResultStorageType.None,
                                      TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                                      Address: result.Value.Address,
                                      CustomUIVisualizers: null,
                                      ExternalModules: null,
                                      DataItem: result.ToDataItem()));
                break;

            case ExpansionKind.PointerDereference:
            case ExpansionKind.Default:
                // This call will evaluate DebuggerDisplayAttributes.
                GetResultAndContinue(
                    result,
                    workList,
                    declaredType: result.DeclaredTypeAndInfo.ClrType,
                    declaredTypeInfo: result.DeclaredTypeAndInfo.Info,
                    inspectionContext: inspectionContext,
                    useDebuggerDisplay: result.UseDebuggerDisplay,
                    completionRoutine: completionRoutine);
                break;

            default:
                throw ExceptionUtilities.UnexpectedValue(result.Kind);
            }
        }
Beispiel #16
0
        private static DkmEvaluationResult CreateEvaluationResult(
            DkmInspectionContext inspectionContext,
            DkmClrValue value,
            string name,
            string typeName,
            string display,
            EvalResultDataItem dataItem)
        {
            if (value.IsError())
            {
                // Evaluation failed
                return(DkmFailedEvaluationResult.Create(
                           InspectionContext: inspectionContext,
                           StackFrame: value.StackFrame,
                           Name: name,
                           FullName: dataItem.FullName,
                           ErrorMessage: display,
                           Flags: dataItem.Flags,
                           Type: typeName,
                           DataItem: dataItem));
            }
            else if (dataItem.Kind == ExpansionKind.NativeView)
            {
                // For Native View, create a DkmIntermediateEvaluationResult.  This will allow the C++ EE
                // to take over expansion.
                DkmProcess  process = inspectionContext.RuntimeInstance.Process;
                DkmLanguage cpp     = process.EngineSettings.GetLanguage(new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp));
                return(DkmIntermediateEvaluationResult.Create(
                           InspectionContext: inspectionContext,
                           StackFrame: value.StackFrame,
                           Name: Resources.NativeView,
                           FullName: dataItem.FullName,
                           Expression: dataItem.Name,
                           IntermediateLanguage: cpp,
                           TargetRuntime: process.GetNativeRuntimeInstance(),
                           DataItem: dataItem));
            }
            else
            {
                ReadOnlyCollection <DkmCustomUIVisualizerInfo> customUIVisualizers = null;

                if (!value.IsNull)
                {
                    DkmCustomUIVisualizerInfo[] customUIVisualizerInfo = value.Type.GetDebuggerCustomUIVisualizerInfo();
                    if (customUIVisualizerInfo != null)
                    {
                        customUIVisualizers = new ReadOnlyCollection <DkmCustomUIVisualizerInfo>(customUIVisualizerInfo);
                    }
                }

                // If the EvalResultData item doesn't specify a particular category, we'll just propagate DkmClrValue.Category,
                // which typically appears to be set to the default value ("Other").
                var category = (dataItem.Category != DkmEvaluationResultCategory.Other) ? dataItem.Category : value.Category;

                // Valid value
                return(DkmSuccessEvaluationResult.Create(
                           InspectionContext: inspectionContext,
                           StackFrame: value.StackFrame,
                           Name: name,
                           FullName: dataItem.FullName,
                           Flags: dataItem.Flags,
                           Value: display,
                           EditableValue: dataItem.EditableValue,
                           Type: typeName,
                           Category: category,
                           Access: value.Access,
                           StorageType: value.StorageType,
                           TypeModifierFlags: value.TypeModifierFlags,
                           Address: value.Address,
                           CustomUIVisualizers: customUIVisualizers,
                           ExternalModules: null,
                           DataItem: dataItem));
            }
        }
        internal static DkmEvaluationResult GetTableChildAtIndex(DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, string fullName, LuaTableData value, int index)
        {
            if (value == null)
            {
                return(DkmFailedEvaluationResult.Create(inspectionContext, stackFrame, $"[{index + 1}]", $"{fullName}[{index + 1}]", "Table data is missing", DkmEvaluationResultFlags.Invalid, null));
            }

            var process = stackFrame.Process;

            var arrayElementCount = value.GetArrayElementCount(process);

            if (index < arrayElementCount)
            {
                var arrayElements = value.GetArrayElements(process);

                var element = arrayElements[index];

                return(EvaluateDataAtLuaValue(inspectionContext, stackFrame, $"[{index + 1}]", $"{fullName}[{index + 1}]", element, DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None));
            }

            index = index - arrayElementCount;

            var nodeElementCount = value.GetNodeElementCount(process);

            if (index < nodeElementCount)
            {
                var lazyNodeElements = value.GetNodeLazyElements(process);

                var node = lazyNodeElements[index];

                var nodeKey = node.LoadKey(process, value.batchNodeElementData);

                DkmEvaluationResultFlags flags = DkmEvaluationResultFlags.None;
                string name = EvaluateValueAtLuaValue(process, nodeKey, 10, out _, ref flags, out _, out _);

                var keyString = nodeKey as LuaValueDataString;

                if (keyString != null)
                {
                    name = keyString.value;
                }

                if (name == null || name.Length == 0)
                {
                    name = "%error-name%";
                }

                // Check if name is an identifier
                bool isIdentifierName = false;

                if (char.IsLetter(name[0]) || name[0] == '_')
                {
                    int pos = 1;

                    while (pos < name.Length && (char.IsLetterOrDigit(name[pos]) || name[pos] == '_'))
                    {
                        pos++;
                    }

                    isIdentifierName = pos == name.Length;
                }

                if (isIdentifierName)
                {
                    return(EvaluateDataAtLuaValue(inspectionContext, stackFrame, name, $"{fullName}.{name}", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None));
                }

                return(EvaluateDataAtLuaValue(inspectionContext, stackFrame, $"\"{name}\"", $"{fullName}[\"{name}\"]", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None));
            }

            index = index - nodeElementCount;

            if (index == 0 && value.HasMetaTable())
            {
                var metaTableValue = new LuaValueDataTable
                {
                    baseType        = LuaBaseType.Table,
                    extendedType    = LuaExtendedType.Table,
                    evaluationFlags = DkmEvaluationResultFlags.ReadOnly,
                    originalAddress = 0, // Not available as TValue
                    value           = value.GetMetaTable(process),
                    targetAddress   = value.metaTableDataAddress
                };

                return(EvaluateDataAtLuaValue(inspectionContext, stackFrame, "!metatable", $"{fullName}.!metatable", metaTableValue, DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None));
            }

            Debug.Assert(false, "Invalid child index");

            return(null);
        }
Beispiel #18
0
        public void EvaluateVisualizedExpression(DkmVisualizedExpression visualizedExpression, out DkmEvaluationResult resultObject)
        {
            var rootExpr = visualizedExpression as DkmRootVisualizedExpression;

            if (rootExpr == null)
            {
                Debug.Fail("PythonViewNativeVisualizer.EvaluateVisualizedExpression was given a visualized expression that is not a DkmRootVisualizedExpression.");
                throw new NotSupportedException();
            }

            DkmEvaluationResult       rawResult;
            RawEvaluationResultHolder rawResultHolder;

            using (var rawExpr = DkmLanguageExpression.Create(CppExpressionEvaluator.CppLanguage, DkmEvaluationFlags.ShowValueRaw, rootExpr.FullName + ",!", null)) {
                rootExpr.EvaluateExpressionCallback(rootExpr.InspectionContext, rawExpr, rootExpr.StackFrame, out rawResult);
                rawResultHolder = new RawEvaluationResultHolder {
                    RawResult = rawResult
                };
                rootExpr.SetDataItem(DkmDataCreationDisposition.CreateAlways, rawResultHolder);
            }

            var rawSuccessResult = rawResult as DkmSuccessEvaluationResult;

            if (rawSuccessResult != null)
            {
                resultObject = DkmSuccessEvaluationResult.Create(
                    rawResult.InspectionContext,
                    rawResult.StackFrame,
                    rootExpr.Name,
                    rawSuccessResult.FullName,
                    rawSuccessResult.Flags,
                    rawSuccessResult.Value,
                    rawSuccessResult.EditableValue,
                    rawSuccessResult.Type,
                    rawSuccessResult.Category,
                    rawSuccessResult.Access,
                    rawSuccessResult.StorageType,
                    rawSuccessResult.TypeModifierFlags,
                    rawSuccessResult.Address,
                    rawSuccessResult.CustomUIVisualizers,
                    rawSuccessResult.ExternalModules,
                    rawResultHolder);
                return;
            }

            var rawFailedResult = rawResult as DkmFailedEvaluationResult;

            if (rawFailedResult != null)
            {
                resultObject = DkmFailedEvaluationResult.Create(
                    rawResult.InspectionContext,
                    rawResult.StackFrame,
                    rootExpr.Name,
                    rootExpr.FullName,
                    rawFailedResult.ErrorMessage,
                    rawFailedResult.Flags,
                    rawResultHolder);
                return;
            }

            Debug.Fail("Raw evaluation result was neither DkmSuccessEvaluationResult nor DkmFailedEvaluationResult.");
            throw new NotSupportedException();
        }