Beispiel #1
0
        internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex)
        {
            this.process                = thread.Process;
            this.thread                 = thread;
            this.appDomain              = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()];
            this.corILFrame             = corILFrame;
            this.corILFramePauseSession = process.PauseSession;
            this.corFunction            = corILFrame.GetFunction();
            this.chainIndex             = chainIndex;
            this.frameIndex             = frameIndex;

            MetaDataImport metaData      = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
            int            methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length;
            // Class parameters are first, then the method ones
            List <ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();

            // Remove method parametrs at the end
            corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs);
            List <DebugType> genArgs = new List <DebugType>(corGenArgs.Count);

            foreach (ICorDebugType corGenArg in corGenArgs)
            {
                genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg));
            }

            DebugType debugType = DebugType.CreateFromCorClass(
                this.AppDomain,
                null,
                corFunction.GetClass(),
                genArgs.ToArray()
                );

            this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken());
        }
Beispiel #2
0
        internal Value(AppDomain appDomain, ICorDebugValue corValue)
        {
            if (corValue == null)
            {
                throw new ArgumentNullException("corValue");
            }
            this.appDomain             = appDomain;
            this.corValue              = corValue;
            this.corValue_pauseSession = this.Process.PauseSession;

            this.isNull = corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).IsNull() != 0;

            if (corValue is ICorDebugReferenceValue &&
                ((ICorDebugReferenceValue)corValue).GetValue() == 0 &&
                ((ICorDebugValue2)corValue).GetExactType() == null)
            {
                // We were passed null reference and no metadata description
                // (happens during CreateThread callback for the thread object)
                this.type = appDomain.ObjectType;
            }
            else
            {
                ICorDebugType exactType = ((ICorDebugValue2)this.CorValue).GetExactType();
                this.type = DebugType.CreateFromCorType(appDomain, exactType);
            }
        }
Beispiel #3
0
        public static List <TreeNode> GetDebugInfo(TreeNode parent, AppDomain appDomain, ICorDebugValue corValue)
        {
            List <TreeNode> items = new List <TreeNode>();

            if (corValue is ICorDebugValue)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugValue", "");
                info.AddChild("Address", corValue.GetAddress().ToString("X8"));
                info.AddChild("Type", ((CorElementType)corValue.GetTheType()).ToString());
                info.AddChild("Size", corValue.GetSize().ToString());
                items.Add(info);
            }
            if (corValue is ICorDebugValue2)
            {
                InfoNode        info      = new InfoNode(parent, "ICorDebugValue2", "");
                ICorDebugValue2 corValue2 = (ICorDebugValue2)corValue;
                string          fullname;
                try {
                    fullname = DebugType.CreateFromCorType(appDomain, corValue2.GetExactType()).FullName;
                } catch (DebuggerException e) {
                    fullname = e.Message;
                }
                info.AddChild("ExactType", fullname);
                items.Add(info);
            }
            if (corValue is ICorDebugGenericValue)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugGenericValue", "");
                try {
                    byte[] bytes = ((ICorDebugGenericValue)corValue).GetRawValue();
                    for (int i = 0; i < bytes.Length; i += 8)
                    {
                        string val = "";
                        for (int j = i; j < bytes.Length && j < i + 8; j++)
                        {
                            val += bytes[j].ToString("X2") + " ";
                        }
                        info.AddChild("Value" + i.ToString("X2"), val);
                    }
                } catch (ArgumentException) {
                    info.AddChild("Value", "N/A");
                }
                items.Add(info);
            }
            if (corValue is ICorDebugReferenceValue)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugReferenceValue", "");
                ICorDebugReferenceValue refValue = (ICorDebugReferenceValue)corValue;
                info.AddChild("IsNull", (refValue.IsNull() != 0).ToString());
                if (refValue.IsNull() == 0)
                {
                    info.AddChild("Value", refValue.GetValue().ToString("X8"));
                    if (refValue.Dereference() != null)
                    {
                        info.AddChild("Dereference", "", p => GetDebugInfo(p, appDomain, refValue.Dereference()));
                    }
                    else
                    {
                        info.AddChild("Dereference", "N/A");
                    }
                }
                items.Add(info);
            }
            if (corValue is ICorDebugHeapValue)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugHeapValue", "");
                items.Add(info);
            }
            if (corValue is ICorDebugHeapValue2)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugHeapValue2", "");
                items.Add(info);
            }
            if (corValue is ICorDebugObjectValue)
            {
                InfoNode             info     = new InfoNode(parent, "ICorDebugObjectValue", "");
                ICorDebugObjectValue objValue = (ICorDebugObjectValue)corValue;
                info.AddChild("Class", objValue.GetClass().GetToken().ToString("X8"));
                info.AddChild("IsValueClass", (objValue.IsValueClass() != 0).ToString());
                items.Add(info);
            }
            if (corValue is ICorDebugObjectValue2)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugObjectValue2", "");
                items.Add(info);
            }
            if (corValue is ICorDebugBoxValue)
            {
                InfoNode          info     = new InfoNode(parent, "ICorDebugBoxValue", "");
                ICorDebugBoxValue boxValue = (ICorDebugBoxValue)corValue;
                info.AddChild("Object", "", p => GetDebugInfo(p, appDomain, boxValue.GetObject()));
                items.Add(info);
            }
            if (corValue is ICorDebugStringValue)
            {
                InfoNode             info        = new InfoNode(parent, "ICorDebugStringValue", "");
                ICorDebugStringValue stringValue = (ICorDebugStringValue)corValue;
                info.AddChild("Length", stringValue.GetLength().ToString());
                info.AddChild("String", stringValue.GetString());
                items.Add(info);
            }
            if (corValue is ICorDebugArrayValue)
            {
                InfoNode info = new InfoNode(parent, "ICorDebugArrayValue", "");
                info.AddChild("...", "...");
                items.Add(info);
            }
            if (corValue is ICorDebugHandleValue)
            {
                InfoNode             info        = new InfoNode(parent, "ICorDebugHandleValue", "");
                ICorDebugHandleValue handleValue = (ICorDebugHandleValue)corValue;
                info.AddChild("HandleType", handleValue.GetHandleType().ToString());
                items.Add(info);
            }

            return(items);
        }