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); } }
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); } }
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 == 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 == null) { continue; } var stringValueRes = Convert(s, elementType, out var type2); if (stringValueRes.ErrorMessage != null) { return(stringValueRes); } if (!stringValueRes.CorValue.IsReference) { return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError)); } var av = arrayValue; if (av.IsReference) { av = av.GetDereferencedValue(out hr); if (av == null) { return(new EvalArgumentResult(CordbgErrorHelper.GetErrorMessage(hr))); } } if (av?.IsArray != true) { return(new EvalArgumentResult(PredefinedEvaluationErrorMessages.InternalDebuggerError)); } Debug.Assert(elem == null); elem = av.GetElementAtPosition(i, out hr); if (elem == 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); } }