Example #1
0
        private static void HighLevelDebugFuncEvalHelper()
        {
            uint parameterBufferSize = RuntimeAugments.RhpGetFuncEvalParameterBufferSize();

            IntPtr writeParameterCommandPointer;
            IntPtr debuggerBufferPointer;

            unsafe
            {
                byte *debuggerBufferRawPointer = stackalloc byte[(int)parameterBufferSize];
                debuggerBufferPointer = new IntPtr(debuggerBufferRawPointer);

                WriteParameterCommand writeParameterCommand = new WriteParameterCommand
                {
                    commandCode   = 1,
                    bufferAddress = debuggerBufferPointer.ToInt64()
                };

                writeParameterCommandPointer = new IntPtr(&writeParameterCommand);

                RuntimeAugments.RhpSendCustomEventToDebugger(writeParameterCommandPointer, Unsafe.SizeOf <WriteParameterCommand>());

                // .. debugger magic ... the debuggerBuffer will be filled with parameter data

                TypesAndValues typesAndValues = new TypesAndValues();

                uint  trash;
                uint  parameterCount;
                uint  parameterValue;
                uint  eeTypeCount;
                ulong eeType;
                uint  offset = 0;

                NativeReader reader = new NativeReader(debuggerBufferRawPointer, parameterBufferSize);
                offset = reader.DecodeUnsigned(offset, out trash); // The VertexSequence always generate a length, I don't really need it.
                offset = reader.DecodeUnsigned(offset, out parameterCount);

                typesAndValues.parameterValues = new int[parameterCount];
                for (int i = 0; i < parameterCount; i++)
                {
                    offset = reader.DecodeUnsigned(offset, out parameterValue);
                    typesAndValues.parameterValues[i] = (int)parameterValue;
                }
                offset = reader.DecodeUnsigned(offset, out eeTypeCount);
                for (int i = 0; i < eeTypeCount; i++)
                {
                    // TODO: Stuff these eeType values into the external reference table
                    offset = reader.DecodeUnsignedLong(offset, out eeType);
                }

                TypeSystemContext typeSystemContext = TypeSystemContextFactory.Create();
                bool       hasThis;
                TypeDesc[] parameters;
                bool[]     parametersWithGenericDependentLayout;
                bool       result = TypeLoaderEnvironment.Instance.GetCallingConverterDataFromMethodSignature_NativeLayout_Debugger(typeSystemContext, RuntimeSignature.CreateFromNativeLayoutSignatureForDebugger(offset), Instantiation.Empty, Instantiation.Empty, out hasThis, out parameters, out parametersWithGenericDependentLayout, reader);

                typesAndValues.types = new RuntimeTypeHandle[parameters.Length];

                bool needToDynamicallyLoadTypes = false;
                for (int i = 0; i < typesAndValues.types.Length; i++)
                {
                    if (!parameters[i].RetrieveRuntimeTypeHandleIfPossible())
                    {
                        needToDynamicallyLoadTypes = true;
                        break;
                    }

                    typesAndValues.types[i] = parameters[i].GetRuntimeTypeHandle();
                }

                if (needToDynamicallyLoadTypes)
                {
                    TypeLoaderEnvironment.Instance.RunUnderTypeLoaderLock(() =>
                    {
                        typeSystemContext.FlushTypeBuilderStates();

                        GenericDictionaryCell[] cells = new GenericDictionaryCell[parameters.Length];
                        for (int i = 0; i < cells.Length; i++)
                        {
                            cells[i] = GenericDictionaryCell.CreateTypeHandleCell(parameters[i]);
                        }
                        IntPtr[] eetypePointers;
                        TypeBuilder.ResolveMultipleCells(cells, out eetypePointers);

                        for (int i = 0; i < parameters.Length; i++)
                        {
                            typesAndValues.types[i] = ((EEType *)eetypePointers[i])->ToRuntimeTypeHandle();
                        }
                    });
                }

                TypeSystemContextFactory.Recycle(typeSystemContext);

                LocalVariableType[] argumentTypes = new LocalVariableType[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    // TODO: What these false really means? Need to make sure our format contains those information
                    argumentTypes[i] = new LocalVariableType(typesAndValues.types[i], false, false);
                }

                LocalVariableSet.SetupArbitraryLocalVariableSet <TypesAndValues>(HighLevelDebugFuncEvalHelperWithVariables, ref typesAndValues, argumentTypes);
            }
        }
Example #2
0
        private unsafe static void RegularFuncEval(byte *parameterBuffer, uint parameterBufferSize)
        {
            TypesAndValues typesAndValues = new TypesAndValues();

            uint  trash;
            uint  parameterCount;
            uint  parameterValueSize;
            uint  eeTypeCount;
            ulong eeType;
            uint  offset = 0;

            NativeReader reader = new NativeReader(parameterBuffer, parameterBufferSize);

            offset = reader.DecodeUnsigned(offset, out trash); // The VertexSequence always generate a length, I don't really need it.
            offset = reader.DecodeUnsigned(offset, out parameterCount);

            typesAndValues.parameterValues = new byte[parameterCount][];
            for (int i = 0; i < parameterCount; i++)
            {
                offset = reader.DecodeUnsigned(offset, out parameterValueSize);
                byte[] parameterValue = new byte[parameterValueSize];
                for (int j = 0; j < parameterValueSize; j++)
                {
                    uint parameterByte;
                    offset            = reader.DecodeUnsigned(offset, out parameterByte);
                    parameterValue[j] = (byte)parameterByte;
                }
                typesAndValues.parameterValues[i] = parameterValue;
            }
            offset = reader.DecodeUnsigned(offset, out eeTypeCount);
            ulong[] debuggerPreparedExternalReferences = new ulong[eeTypeCount];
            for (int i = 0; i < eeTypeCount; i++)
            {
                offset = reader.DecodeUnsignedLong(offset, out eeType);
                debuggerPreparedExternalReferences[i] = eeType;
            }

            TypeSystemContext typeSystemContext = TypeSystemContextFactory.Create();
            bool hasThis;

            TypeDesc[] parameters;
            bool[]     parametersWithGenericDependentLayout;
            bool       result = TypeLoaderEnvironment.Instance.GetCallingConverterDataFromMethodSignature_NativeLayout_Debugger(typeSystemContext, RuntimeSignature.CreateFromNativeLayoutSignatureForDebugger(offset), Instantiation.Empty, Instantiation.Empty, out hasThis, out parameters, out parametersWithGenericDependentLayout, reader, debuggerPreparedExternalReferences);

            typesAndValues.types = new RuntimeTypeHandle[parameters.Length];

            bool needToDynamicallyLoadTypes = false;

            for (int i = 0; i < typesAndValues.types.Length; i++)
            {
                if (!parameters[i].RetrieveRuntimeTypeHandleIfPossible())
                {
                    needToDynamicallyLoadTypes = true;
                    break;
                }

                typesAndValues.types[i] = parameters[i].GetRuntimeTypeHandle();
            }

            if (needToDynamicallyLoadTypes)
            {
                TypeLoaderEnvironment.Instance.RunUnderTypeLoaderLock(() =>
                {
                    typeSystemContext.FlushTypeBuilderStates();

                    GenericDictionaryCell[] cells = new GenericDictionaryCell[parameters.Length];
                    for (int i = 0; i < cells.Length; i++)
                    {
                        cells[i] = GenericDictionaryCell.CreateTypeHandleCell(parameters[i]);
                    }
                    IntPtr[] eetypePointers;
                    TypeBuilder.ResolveMultipleCells(cells, out eetypePointers);

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        typesAndValues.types[i] = ((EEType *)eetypePointers[i])->ToRuntimeTypeHandle();
                    }
                });
            }

            TypeSystemContextFactory.Recycle(typeSystemContext);

            LocalVariableType[] argumentTypes = new LocalVariableType[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                // TODO, FuncEval, what these false really means? Need to make sure our format contains those information
                argumentTypes[i] = new LocalVariableType(typesAndValues.types[i], false, false);
            }

            LocalVariableSet.SetupArbitraryLocalVariableSet <TypesAndValues>(HighLevelDebugFuncEvalHelperWithVariables, ref typesAndValues, argumentTypes);
        }
Example #3
0
 public override GenericDictionaryCell GetDictionaryCell()
 {
     return(GenericDictionaryCell.CreateTypeHandleCell(Type));
 }