Пример #1
0
        private MDbgValue[] InternalGetFields()
        {
            var al = new ArrayList();

            //dereference && (unbox);
            CorDebug.CorValue value = Dereference(CorValue);
            if (value == null)
            {
                throw new MDbgValueException("null value");
            }
            Unbox(ref value);
            CorDebug.CorObjectValue ov = value.CastToObjectValue();

            CorDebug.CorType cType = ov.ExactType;

            CorDebug.CorFrame cFrame = null;
            if (Process.Threads.HaveActive)
            {
                // we need a current frame to display thread local static values
                if (Process.Threads.Active.HaveCurrentFrame)
                {
                    cFrame = Process.Threads.Active.CurrentFrame.CorFrame;
                }
            }


            MDbgModule classModule;

            // initialization
            CorDebug.CorClass corClass = ov.Class;
            classModule = Process.Modules.Lookup(corClass.Module);

            // iteration through class hierarchy
            do
            {
                Type classType;
                //int parentToken;

                classType = classModule.Importer.GetType(corClass.Token);
                //classModule.Importer.GetTypeNameFromDef(classToken,out parentToken);

                foreach (MetadataFieldInfo fi in classType.GetFields())
                {
                    CorValue fieldValue = null;
                    try
                    {
                        if (fi.IsLiteral)
                        {
                            fieldValue = null;
                            // for now we just hide the constant fields.
                            continue;
                        }
                        else if (fi.IsStatic)
                        {
                            fieldValue = cType.GetStaticFieldValue(fi.MetadataToken, cFrame);
                        }
                        else // we are asuming normal field value
                             // GetFieldValueForTYpe Supersedes GetFieldValue
                             // Will replace when all issues are resolved.
                             //fieldValue = ov.GetFieldValueForType(cType, (uint)fi.Token);
                        {
                            fieldValue = ov.GetFieldValue(corClass, fi.MetadataToken);
                        }
                    }
                    catch (COMException)
                    {
                        // we won't report any problems.
                    }
                    al.Add(new MDbgValue(Process, fi.Name, fieldValue));
                }
                cType = cType.Base;
                if (cType == null)
                {
                    break;
                }
                corClass    = cType.Class;
                classModule = Process.Modules.Lookup(corClass.Module);
            } while (true);

            return((MDbgValue[])al.ToArray(typeof(MDbgValue)));
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////////////////
        //
        // Implementation Part
        //
        //////////////////////////////////////////////////////////////////////////////////

        private string InternalGetValue(int indentLevel, int expandDepth, bool canDoFunceval)
        {
            Debug.Assert(expandDepth >= 0);

            CorDebug.CorValue value = CorValue;
            if (value == null)
            {
                return("<N/A>");
            }

            // Record the memory addresses if displaying them is enabled
            string prefix = String.Empty;

            if (m_process.m_engine.Options.ShowAddresses)
            {
                string ptrStr = MakePtrString(value);
                if (!String.IsNullOrEmpty(ptrStr))
                {
                    prefix = "(" + ptrStr + ") ";
                }
            }

            try
            {
                value = Dereference(value);
            }
            catch (COMException ce)
            {
                if (ce.ErrorCode == (int)CorDebug.HResult.CORDBG_E_BAD_REFERENCE_VALUE)
                {
                    return(prefix + "<invalid reference value>");
                }
                throw;
            }

            if (value == null)
            {
                return(prefix + "<null>");
            }

            Unbox(ref value);

            switch (value.Type)
            {
            case CorElementType.ELEMENT_TYPE_BOOLEAN:
            case CorElementType.ELEMENT_TYPE_I1:
            case CorElementType.ELEMENT_TYPE_U1:
            case CorElementType.ELEMENT_TYPE_I2:
            case CorElementType.ELEMENT_TYPE_U2:
            case CorElementType.ELEMENT_TYPE_I4:
            case CorElementType.ELEMENT_TYPE_U4:
            case CorElementType.ELEMENT_TYPE_I:
            case CorElementType.ELEMENT_TYPE_U:
            case CorElementType.ELEMENT_TYPE_I8:
            case CorElementType.ELEMENT_TYPE_U8:
            case CorElementType.ELEMENT_TYPE_R4:
            case CorElementType.ELEMENT_TYPE_R8:
            case CorElementType.ELEMENT_TYPE_CHAR:
            {
                object v = value.CastToGenericValue().GetValue();
                string result;

                var vFormattable = v as IFormattable;
                if (vFormattable != null)
                {
                    result = vFormattable.ToString(null, CultureInfo.CurrentUICulture);
                }
                else
                {
                    result = v.ToString();
                }

                // let's put quotes around char values
                if (value.Type == CorElementType.ELEMENT_TYPE_CHAR)
                {
                    result = "'" + result + "'";
                }

                return(prefix + result);
            }

            case CorElementType.ELEMENT_TYPE_CLASS:
            case CorElementType.ELEMENT_TYPE_VALUETYPE:
                CorDebug.CorObjectValue ov = value.CastToObjectValue();
                return(prefix + PrintObject(indentLevel, ov, expandDepth, canDoFunceval));

            case CorElementType.ELEMENT_TYPE_STRING:
                CorDebug.CorStringValue sv = value.CastToStringValue();
                return(prefix + '"' + sv.String + '"');

            case CorElementType.ELEMENT_TYPE_SZARRAY:
            case CorElementType.ELEMENT_TYPE_ARRAY:
                CorDebug.CorArrayValue av = value.CastToArrayValue();
                return(prefix + PrintArray(indentLevel, av, expandDepth, canDoFunceval));

            case CorElementType.ELEMENT_TYPE_PTR:
                return(prefix + "<non-null pointer>");

            case CorElementType.ELEMENT_TYPE_BYREF:
            case CorElementType.ELEMENT_TYPE_TYPEDBYREF:
            case CorElementType.ELEMENT_TYPE_OBJECT:
            default:
                return(prefix + "<printing value of type: " + value.Type + " not implemented>");
            }
        }