Пример #1
0
        string?StoreSimpleValue_CorDebug(DnThread dnThread, CorValue targetValue, DmdType targetType, object?sourceValue)
        {
            if (targetType.IsByRef)
            {
                return(CordbgErrorHelper.InternalError);
            }
            int hr;

            if (targetType.IsPointer || targetType.IsFunctionPointer)
            {
                var sourceValueBytes = TryGetValueBytes(sourceValue);
                Debug2.Assert(!(sourceValueBytes is null));
                if (sourceValueBytes is null || targetValue.Size != (uint)sourceValueBytes.Length)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                ulong address = targetValue.Address;
                if (address == 0)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                hr = dnThread.Process.CorProcess.WriteMemory(address, sourceValueBytes, 0, sourceValueBytes.Length, out var sizeWritten);
                if (hr < 0)
                {
                    return(CordbgErrorHelper.GetErrorMessage(hr));
                }
                return(null);
            }
            else if (!targetType.IsValueType)
            {
                if (!(sourceValue is null))
                {
                    return(CordbgErrorHelper.InternalError);
                }
                hr = targetValue.SetReferenceAddress(0);
                if (hr != 0)
                {
                    return(CordbgErrorHelper.GetErrorMessage(hr));
                }
                return(null);
            }
            else
            {
                if (targetValue.IsReference)
                {
                    if (!(targetValue.GetDereferencedValue(out hr) is CorValue derefValue))
                    {
                        return(CordbgErrorHelper.GetErrorMessage(hr));
                    }
                    targetValue = derefValue;
                }
                if (targetValue.IsBox)
                {
                    return(CordbgErrorHelper.InternalError);
                }

                if (!targetValue.IsGeneric || sourceValue is null)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                var sourceValueBytes = TryGetValueBytes(sourceValue);
                Debug2.Assert(!(sourceValueBytes is null));
                if (sourceValueBytes is null || targetValue.Size != (uint)sourceValueBytes.Length)
                {
                    return(CordbgErrorHelper.InternalError);
                }
                hr = targetValue.WriteGenericValue(sourceValueBytes, dnThread.Process.CorProcess);
                if (hr < 0)
                {
                    return(CordbgErrorHelper.GetErrorMessage(hr));
                }
                return(null);
            }
        }
Пример #2
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);
            }
        }