示例#1
0
        unsafe EvalArgumentResult ConvertSZArray(void *array, int length, int elementSize, DmdType elementType, out DmdType type)
        {
            type = elementType.MakeArrayType();
            var corElementType = GetType(elementType);
            var res            = dnEval.CreateSZArray(corElementType, length, out int hr);

            if (res is null || !res.Value.NormalResult)
            {
                return(EvalArgumentResult.Create(res, hr));
            }
            if (!IsInitialized(array, length * elementSize))
            {
                return(EvalArgumentResult.Create(res, hr));
            }

            bool error = true;

            try {
                Debug.Assert(length > 0);
                CorValue?arrayValue = res.Value.ResultOrException !;
                if (arrayValue.IsReference)
                {
                    arrayValue = arrayValue.GetDereferencedValue(out hr);
                    if (!(arrayValue is null))
                    {
                        return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr)));
                    }
                }
                Debug.Assert(arrayValue?.IsArray == true);
                if (arrayValue?.IsArray != true)
                {
                    return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                }
                var addr = DbgDotNetValueImpl.GetArrayAddress(arrayValue);
                if (addr is null)
                {
                    return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                }

                if (!(appDomain.Process is CorProcess process))
                {
                    return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                }
                hr = process.WriteMemory(addr.Value.Address, array, length * elementSize, out int sizeWritten);
                if (hr < 0 || sizeWritten != length * elementSize)
                {
                    return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                }

                var eaRes = new EvalArgumentResult(AddValue(type, res.Value.ResultOrException));
                error = false;
                return(eaRes);
            }
            finally {
                if (error)
                {
                    engine.DisposeHandle_CorDebug(res.Value.ResultOrException);
                }
            }
        }
示例#2
0
        DbgDotNetValueResult?Box_CorDebug(DbgEvaluationInfo evalInfo)
        {
            engine.VerifyCorDebugThread();
            evalInfo.CancellationToken.ThrowIfCancellationRequested();
            var corValue = TryGetCorValue();

            if (corValue == null)
            {
                return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.InternalError));
            }
            if (!ILDbgEngineStackFrame.TryGetEngineStackFrame(evalInfo.Frame, out var ilFrame))
            {
                return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.InternalError));
            }
            // Even if it's boxed, box the unboxed value. This code path should only be called if
            // the compiler thinks it's an unboxed value, so we must make a new boxed value.
            if (corValue.IsReference)
            {
                corValue = corValue.GetDereferencedValue(out int hr);
                if (corValue == null)
                {
                    return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.GetErrorMessage(hr)));
                }
            }
            if (corValue.IsBox)
            {
                corValue = corValue.GetBoxedValue(out int hr);
                if (corValue == null)
                {
                    return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.GetErrorMessage(hr)));
                }
            }
            return(engine.Box_CorDebug(evalInfo, ilFrame.GetCorAppDomain(), corValue, Type));
        }
示例#3
0
        DbgDotNetValueResult Dereference_CorDebug()
        {
            Debug.Assert((Type.IsByRef && !IsNullByRef) || (Type.IsPointer && !IsNull));
            engine.VerifyCorDebugThread();
            int hr = -1;
            var dereferencedValue = TryGetCorValue()?.GetDereferencedValue(out hr);

            // We sometimes get 0x80131C49 = CORDBG_E_READVIRTUAL_FAILURE
            if (dereferencedValue is null)
            {
                return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.GetErrorMessage(hr)));
            }
            return(DbgDotNetValueResult.Create(engine.CreateDotNetValue_CorDebug(dereferencedValue, Type.AppDomain, tryCreateStrongHandle: true)));
        }
示例#4
0
 internal static EvalArgumentResult Create(EvalResult?res, int hr)
 {
     if (res is null || res.Value.WasException)
     {
         return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr)));
     }
     if (res.Value.WasCustomNotification)
     {
         return(new EvalArgumentResult(CordbgErrorHelper.FuncEvalRequiresAllThreadsToRun));
     }
     if (res.Value.WasCancelled)
     {
         return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.FuncEvalTimedOut));
     }
     return(new EvalArgumentResult(res.Value.ResultOrException !));
 }
示例#5
0
        DbgDotNetValueResult GetArrayElementAt_CorDebug(uint index)
        {
            Debug.Assert(Type.IsArray);
            engine.VerifyCorDebugThread();
            var corValue = TryGetCorValue();

            if (corValue == null || corValue.IsNull)
            {
                return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.InternalError));
            }
            using (var obj = new ArrayObjectValue(engine, corValue)) {
                int hr        = -1;
                var elemValue = obj.Value?.GetElementAtPosition(index, out hr);
                if (elemValue == null)
                {
                    return(DbgDotNetValueResult.CreateError(CordbgErrorHelper.GetErrorMessage(hr)));
                }
                return(DbgDotNetValueResult.Create(engine.CreateDotNetValue_CorDebug(elemValue, Type.AppDomain, tryCreateStrongHandle: true)));
            }
        }
示例#6
0
        EvalArgumentResult ConvertSZArray(string[] array, out DmdType type)
        {
            var elementType = reflectionAppDomain.System_String;

            type = elementType.MakeArrayType();
            var corElementType = GetType(elementType);
            var res            = dnEval.CreateSZArray(corElementType, array.Length, out int hr);

            if (res is null || !res.Value.NormalResult)
            {
                return(EvalArgumentResult.Create(res, hr));
            }
            if (!IsInitialized(array))
            {
                return(EvalArgumentResult.Create(res, hr));
            }
            Debug.Assert(array.Length > 0);

            CorValue?elem  = null;
            bool     error = true;

            try {
                var arrayValue = res.Value.ResultOrException !;
                for (int i = 0; i < array.Length; i++)
                {
                    var s = array[i];
                    if (s is null)
                    {
                        continue;
                    }

                    var stringValueRes = Convert(s, elementType, out var type2);
                    if (!(stringValueRes.ErrorMessage is null))
                    {
                        return(stringValueRes);
                    }
                    if (!stringValueRes.CorValue !.IsReference)
                    {
                        return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                    }

                    CorValue?av = arrayValue;
                    if (av.IsReference)
                    {
                        av = av.GetDereferencedValue(out hr);
                        if (av is null)
                        {
                            return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr)));
                        }
                    }
                    if (av?.IsArray != true)
                    {
                        return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError));
                    }

                    Debug2.Assert(elem is null);
                    elem = av.GetElementAtPosition(i, out hr);
                    if (elem is null)
                    {
                        return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr)));
                    }

                    hr = elem.SetReferenceAddress(stringValueRes.CorValue.ReferenceAddress);
                    if (hr != 0)
                    {
                        return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr)));
                    }

                    engine.DisposeHandle_CorDebug(elem);
                    elem = null;
                }

                var eaRes = new EvalArgumentResult(AddValue(type, res.Value.ResultOrException !));
                error = false;
                return(eaRes);
            }
            finally {
                if (error)
                {
                    engine.DisposeHandle_CorDebug(res.Value.ResultOrException);
                }
                engine.DisposeHandle_CorDebug(elem);
            }
        }