Пример #1
0
        string?StoreValue_CorDebug(DnEval dnEval, List <CorValue> createdValues, CorAppDomain appDomain, DnThread dnThread, CorValue targetValue, DmdType targetType, CorValue sourceValue, DmdType sourceType)
        {
            if (targetType.IsByRef)
            {
                return(CordbgErrorHelper.InternalError);
            }
            int hr;

            if (!targetType.IsValueType)
            {
                if (!targetValue.IsReference)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                if (!sourceValue.IsReference)
                {
                    var boxedSourceValue = BoxIfNeeded(dnEval, appDomain, createdValues, sourceValue, targetType, sourceType);
                    if (!boxedSourceValue.IsReference)
                    {
                        return(CordbgErrorHelper.InternalError);
                    }
                    sourceValue = boxedSourceValue;
                }
                if (!sourceValue.IsNull && sourceType.IsValueType)
                {
                    var sourceDerefVal = sourceValue.GetDereferencedValue(out hr);
                    if (sourceDerefVal is null)
                    {
                        return(CordbgErrorHelper.GetErrorMessage(hr));
                    }
                    if (!sourceDerefVal.IsBox)
                    {
                        return(CordbgErrorHelper.InternalError);
                    }
                }
                hr = targetValue.SetReferenceAddress(sourceValue.ReferenceAddress);
                if (hr != 0)
                {
                    return(CordbgErrorHelper.GetErrorMessage(hr));
                }
                return(null);
            }
            else
            {
                if (!sourceType.IsValueType)
                {
                    return(CordbgErrorHelper.InternalError);
                }

                if (targetValue.IsReference)
                {
                    if (!(targetValue.GetDereferencedValue(out hr) is CorValue derefValue))
                    {
                        return(CordbgErrorHelper.GetErrorMessage(hr));
                    }
                    targetValue = derefValue;
                }
                if (targetValue.IsBox)
                {
                    return(CordbgErrorHelper.InternalError);
                }

                if (sourceValue.IsReference)
                {
                    if (!(sourceValue.GetDereferencedValue(out hr) is CorValue derefValue))
                    {
                        return(CordbgErrorHelper.GetErrorMessage(hr));
                    }
                    sourceValue = derefValue;
                }
                if (sourceValue.IsBox)
                {
                    if (!(sourceValue.GetBoxedValue(out hr) is CorValue unboxedValue))
                    {
                        return(CordbgErrorHelper.GetErrorMessage(hr));
                    }
                    sourceValue = unboxedValue;
                }

                if (!targetValue.IsGeneric || !sourceValue.IsGeneric)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                if (targetValue.Size != sourceValue.Size)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                hr = targetValue.WriteGenericValue(sourceValue.ReadGenericValue(), dnThread.Process.CorProcess);
                if (hr < 0)
                {
                    return(CordbgErrorHelper.GetErrorMessage(hr));
                }
                return(null);
            }
        }