コード例 #1
0
        public static ISymUnmanagedVariable[] GetAndValidateVariables(ISymUnmanagedScope scope, int expectedCount)
        {
            int count, count2, count3;

            Assert.Equal(HResult.S_OK, scope.GetLocalCount(out count));
            Assert.Equal(expectedCount, count);
            Assert.Equal(HResult.S_OK, scope.GetLocals(0, out count2, null));
            Assert.Equal(expectedCount, count2);
            var variables = new ISymUnmanagedVariable[count];

            Assert.Equal(HResult.S_OK, scope.GetLocals(count, out count3, variables));
            Assert.Equal(count, count3);
            return(variables);
        }
コード例 #2
0
        private static void ForEachLocalVariableRecursive(
            ISymUnmanagedScope scope,
            int offset,
            ref ISymUnmanagedVariable[] localsBuffer,
            Action <ISymUnmanagedVariable> action)
        {
            Debug.Assert((offset < 0) || scope.IsInScope(offset));

            // apply action on locals of the current scope:

            int localCount;

            scope.GetLocalCount(out localCount);

            if (localCount > 0)
            {
                EnsureBufferSize(ref localsBuffer, localCount);
                scope.GetLocals(localCount, out localCount, localsBuffer);

                for (int i = 0; i < localCount; i++)
                {
                    action(localsBuffer[i]);
                }
            }

            // recurse:

            int childCount;

            scope.GetChildren(0, out childCount, null);

            if (childCount > 0)
            {
                var children = new ISymUnmanagedScope[childCount];
                scope.GetChildren(childCount, out childCount, children);

                foreach (var child in children)
                {
                    if ((offset < 0) || child.IsInScope(offset))
                    {
                        ForEachLocalVariableRecursive(child, offset, ref localsBuffer, action);
                        if (offset >= 0)
                        {
                            return;
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void ValidateRootScope(ISymUnmanagedScope scope)
        {
            int count;

            Assert.Equal(HResult.S_OK, scope.GetLocalCount(out count));
            Assert.Equal(0, count);

            Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetConstantCount(out count));
            Assert.Equal(0, count);

            Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetNamespaces(0, out count, null));
            Assert.Equal(0, count);

            ISymUnmanagedScope parent;

            Assert.Equal(HResult.S_OK, scope.GetParent(out parent));
            Assert.Null(parent);
        }
コード例 #4
0
        //
        // Gather the local details in a scope and then recurse to child scopes
        //
        private void ProbeScopeForLocals(List <LocalVariable> variables, ISymUnmanagedScope scope)
        {
            int localCount;

            ThrowExceptionForHR(scope.GetLocalCount(out localCount));

            ISymUnmanagedVariable[] locals = new ISymUnmanagedVariable[localCount];
            ThrowExceptionForHR(scope.GetLocals(localCount, out localCount, locals));

            for (int i = 0; i < localCount; i++)
            {
                var local = locals[i];

                int slot;
                ThrowExceptionForHR(local.GetAddressField1(out slot));

                int nameLength;
                ThrowExceptionForHR(local.GetName(0, out nameLength, null));

                // nameLength includes terminating '\0'
                char[] nameBuffer = new char[nameLength];
                ThrowExceptionForHR(local.GetName(nameLength, out nameLength, nameBuffer));

                int attributes;
                ThrowExceptionForHR(local.GetAttributes(out attributes));

                variables.Add(new LocalVariable()
                {
                    Slot = slot, Name = new String(nameBuffer, 0, nameLength - 1), CompilerGenerated = (attributes & 0x1) != 0
                });
            }

            int childrenCount;

            ThrowExceptionForHR(scope.GetChildren(0, out childrenCount, null));

            ISymUnmanagedScope[] children = new ISymUnmanagedScope[childrenCount];
            ThrowExceptionForHR(scope.GetChildren(childrenCount, out childrenCount, children));

            for (int i = 0; i < childrenCount; i++)
            {
                ProbeScopeForLocals(variables, children[i]);
            }
        }
コード例 #5
0
        private static ISymUnmanagedVariable[] GetLocalsInternal(ISymUnmanagedScope scope)
        {
            int numAvailable;

            scope.GetLocalCount(out numAvailable);
            if (numAvailable == 0)
            {
                return(null);
            }

            int numRead;
            var locals = new ISymUnmanagedVariable[numAvailable];

            scope.GetLocals(numAvailable, out numRead, locals);
            if (numRead != numAvailable)
            {
                throw new InvalidOperationException(string.Format("Read only {0} of {1} locals.", numRead, numAvailable));
            }

            return(locals);
        }
コード例 #6
0
        public static ImmutableArray <ISymUnmanagedVariable> GetLocals(this ISymUnmanagedScope scope)
        {
            int numAvailable;

            scope.GetLocalCount(out numAvailable);
            if (numAvailable == 0)
            {
                return(ImmutableArray <ISymUnmanagedVariable> .Empty);
            }

            int numRead;
            var locals = new ISymUnmanagedVariable[numAvailable];

            scope.GetLocals(numAvailable, out numRead, locals);
            if (numRead != numAvailable)
            {
                throw new InvalidOperationException(string.Format("Read only {0} of {1} locals.", numRead, numAvailable));
            }

            return(ImmutableArray.Create(locals));
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: erisonliang/qizmt
            static void _PrintLocals(ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip, System.IO.TextWriter writer)
            {
                int varcount;
                unmScope.GetLocalCount(out varcount);
                ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount];
                unmScope.GetLocals(varcount, out varcount, vars);

                for (int iv = 0; iv < varcount; iv++)
                {
                    ISymUnmanagedVariable var = vars[iv];
                    string varname;
                    {
                        int namelen;
                        var.GetName(0, out namelen, null);
                        StringBuilder sbName = new StringBuilder(namelen);
                        var.GetName(sbName.Capacity, out namelen, sbName);
                        namelen--; // Remove nul.
                        sbName.Length = namelen;
                        varname = sbName.ToString();
                    }
                    string valstr;
                    {
                        int field1;
                        var.GetAddressField1(out field1);
                        ICorDebugValue pvalue;
                        ilframe.GetLocalVariable((uint)field1, out pvalue);
                        valstr = ToString(pvalue);
                    }
                    writer.WriteLine("{0}={1}", varname, valstr);
                }

                int cChildren;
                unmScope.GetChildren(0, out cChildren, null);
                ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren];
                unmScope.GetChildren(children.Length, out cChildren, children);
                for (int ic = 0; ic < cChildren; ic++)
                {
                    _PrintLocals(ilframe, children[ic], ip, writer);
                }

            }
コード例 #8
0
ファイル: Program.cs プロジェクト: erisonliang/qizmt
            static ICorDebugValue _FindLocal(string name, ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip)
            {
                int varcount;
                unmScope.GetLocalCount(out varcount);
                ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount];
                unmScope.GetLocals(varcount, out varcount, vars);

                for (int iv = 0; iv < varcount; iv++)
                {
                    ISymUnmanagedVariable var = vars[iv];
                    string varname;
                    {
                        int namelen;
                        var.GetName(0, out namelen, null);
                        StringBuilder sbName = new StringBuilder(namelen);
                        var.GetName(sbName.Capacity, out namelen, sbName);
                        namelen--; // Remove nul.
                        sbName.Length = namelen;
                        varname = sbName.ToString();
                    }
                    if (name == varname)
                    {
                        int field1;
                        var.GetAddressField1(out field1);
                        ICorDebugValue pvalue;
                        ilframe.GetLocalVariable((uint)field1, out pvalue);
                        return pvalue;
                    }
                }

                int cChildren;
                unmScope.GetChildren(0, out cChildren, null);
                ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren];
                unmScope.GetChildren(children.Length, out cChildren, children);
                for (int ic = 0; ic < cChildren; ic++)
                {
                    ICorDebugValue pvalue = _FindLocal(name, ilframe, children[ic], ip);
                    if (null != pvalue)
                    {
                        return pvalue;
                    }
                }

                return null;
            }
コード例 #9
0
        //
        // Gather the local details in a scope and then recurse to child scopes
        //
        private void ProbeScopeForLocals(List<ILLocalVariable> variables, ISymUnmanagedScope scope)
        {
            int localCount;
            ThrowExceptionForHR(scope.GetLocalCount(out localCount));

            ISymUnmanagedVariable[] locals = new ISymUnmanagedVariable[localCount];
            ThrowExceptionForHR(scope.GetLocals(localCount, out localCount, locals));

            for (int i = 0; i < localCount; i++)
            {
                var local = locals[i];

                int slot;
                ThrowExceptionForHR(local.GetAddressField1(out slot));

                int nameLength;
                ThrowExceptionForHR(local.GetName(0, out nameLength, null));

                // nameLength includes terminating '\0'
                char[] nameBuffer = new char[nameLength];
                ThrowExceptionForHR(local.GetName(nameLength, out nameLength, nameBuffer));

                int attributes;
                ThrowExceptionForHR(local.GetAttributes(out attributes));

                variables.Add(new ILLocalVariable() { Slot = slot, Name = new String(nameBuffer, 0, nameLength - 1), CompilerGenerated = (attributes & 0x1) != 0 });
            }

            int childrenCount;
            ThrowExceptionForHR(scope.GetChildren(0, out childrenCount, null));

            ISymUnmanagedScope[] children = new ISymUnmanagedScope[childrenCount];
            ThrowExceptionForHR(scope.GetChildren(childrenCount, out childrenCount, children));

            for (int i = 0; i < childrenCount; i++)
            {
                ProbeScopeForLocals(variables, children[i]);
            }
        }
コード例 #10
0
ファイル: SymTestHelpers.cs プロジェクト: antonfirsov/roslyn
 public static ISymUnmanagedVariable[] GetAndValidateVariables(ISymUnmanagedScope scope, int expectedCount)
 {
     int count, count2, count3;
     Assert.Equal(HResult.S_OK, scope.GetLocalCount(out count));
     Assert.Equal(expectedCount, count);
     Assert.Equal(HResult.S_OK, scope.GetLocals(0, out count2, null));
     Assert.Equal(expectedCount, count2);
     var variables = new ISymUnmanagedVariable[count];
     Assert.Equal(HResult.S_OK, scope.GetLocals(count, out count3, variables));
     Assert.Equal(count, count3);
     return variables;
 }
コード例 #11
0
ファイル: SymTestHelpers.cs プロジェクト: antonfirsov/roslyn
        public static void ValidateRootScope(ISymUnmanagedScope scope)
        {
            int count;
            Assert.Equal(HResult.S_OK, scope.GetLocalCount(out count));
            Assert.Equal(0, count);

            Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetConstantCount(out count));
            Assert.Equal(0, count);

            Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetNamespaces(0, out count, null));
            Assert.Equal(0, count);

            ISymUnmanagedScope parent;
            Assert.Equal(HResult.S_OK, scope.GetParent(out parent));
            Assert.Null(parent);
        }
コード例 #12
0
ファイル: SymReader.cs プロジェクト: NileshMoradiya/roslyn
 public int GetLocalCount(out int pRetVal)
 {
     return(_scope.GetLocalCount(out pRetVal));
 }
コード例 #13
0
ファイル: Reader.cs プロジェクト: julianhaslinger/SHFB
        internal void GetLocalSourceNames(ISymUnmanagedScope/*!*/ scope, Hashtable/*!*/ localSourceNames)
        {
            uint numLocals = scope.GetLocalCount();
            IntPtr[] localPtrs = new IntPtr[numLocals];
            scope.GetLocals((uint)localPtrs.Length, out numLocals, localPtrs);

            char[] nameBuffer = new char[100];
            uint nameLen;
            for (int i = 0; i < numLocals; i++)
            {
                ISymUnmanagedVariable local =
                  (ISymUnmanagedVariable)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(localPtrs[i], typeof(ISymUnmanagedVariable));
                if (local != null)
                {
                    local.GetName((uint)nameBuffer.Length, out nameLen, nameBuffer);
                    int localIndex = (int)local.GetAddressField1();
                    localSourceNames[localIndex] = new String(nameBuffer, 0, (int)nameLen - 1);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(local);
                }
                System.Runtime.InteropServices.Marshal.Release(localPtrs[i]);
            }

            IntPtr[] subscopes = new IntPtr[100];
            uint numScopes;
            scope.GetChildren((uint)subscopes.Length, out numScopes, subscopes);
            for (int i = 0; i < numScopes; i++)
            {
                ISymUnmanagedScope subscope =
                  (ISymUnmanagedScope)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(subscopes[i], typeof(ISymUnmanagedScope));
                if (subscope != null)
                {
                    this.GetLocalSourceNames(subscope, localSourceNames);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(subscope);
                }
                System.Runtime.InteropServices.Marshal.Release(subscopes[i]);
                //TODO: need to figure out how map these scope to blocks and set HasLocals on those blocks
            }
        }