private static void GetAllScopes(
            ISymUnmanagedScope root,
            ArrayBuilder<ISymUnmanagedScope> allScopes,
            ArrayBuilder<ISymUnmanagedScope> containingScopes,
            int offset,
            bool isScopeEndInclusive)
        {
            var stack = ArrayBuilder<ISymUnmanagedScope>.GetInstance();
            stack.Push(root);

            while (stack.Any())
            {
                var scope = stack.Pop();
                allScopes.Add(scope);
                if (offset >= 0 && scope.IsInScope(offset, isScopeEndInclusive))
                {
                    containingScopes.Add(scope);
                }

                foreach (var nested in scope.GetScopes())
                {
                    stack.Push(nested);
                }
            }

            stack.Free();
        }
        private static void ForEachLocalVariableRecursive(
            ISymUnmanagedScope scope,
            int offset,
            bool isScopeEndInclusive,
            Action<ISymUnmanagedVariable> action)
        {
            Debug.Assert(offset < 0 || scope.IsInScope(offset, isScopeEndInclusive));

            // apply action on locals of the current scope:
            foreach (var local in scope.GetLocals())
            {
                action(local);
            }

            // recurse:
            foreach (var child in scope.GetChildren())
            {
                if (offset < 0 || child.IsInScope(offset, isScopeEndInclusive))
                {
                    ForEachLocalVariableRecursive(child, offset, isScopeEndInclusive, action);
                    if (offset >= 0)
                    {
                        return;
                    }
                }
            }
        }
        internal SymScope(ISymUnmanagedScope target)
        {
            // We should not wrap null instances
            if (target == null)
                throw new ArgumentNullException("target");

            m_target = target;
        }
Beispiel #4
0
 internal SymbolScope(ISymUnmanagedScope unmanagedScope)
 {
     if (unmanagedScope == null)
     {
         throw new ArgumentNullException("unmanagedScope");
     }
     this.unmanagedScope = unmanagedScope;
 }
Beispiel #5
0
        public static void ValidateRange(ISymUnmanagedScope scope, int expectedStartOffset, int expectedLength)
        {
            int actualOffset;
            Assert.Equal(HResult.S_OK, scope.GetStartOffset(out actualOffset));
            Assert.Equal(expectedStartOffset, actualOffset);

            Assert.Equal(HResult.S_OK, scope.GetEndOffset(out actualOffset));
            Assert.Equal(expectedStartOffset + expectedLength, 2);
        }
Beispiel #6
0
		public ISymbolScope[] GetChildren() {
			uint numScopes;
			scope.GetChildren(0, out numScopes, null);
			var unScopes = new ISymUnmanagedScope[numScopes];
			scope.GetChildren((uint)unScopes.Length, out numScopes, unScopes);
			var scopes = new ISymbolScope[numScopes];
			for (uint i = 0; i < numScopes; i++)
				scopes[i] = new SymbolScope(unScopes[i]);
			return scopes;
		}
Beispiel #7
0
 private static void GetAllScopes(ISymUnmanagedScope scope, ArrayBuilder<ISymUnmanagedScope> builder, int offset, bool isScopeEndInclusive)
 {
     builder.Add(scope);
     foreach (var nested in scope.GetScopes())
     {
         if ((offset < 0) || nested.IsInScope(offset, isScopeEndInclusive))
         {
             GetAllScopes(nested, builder, offset, isScopeEndInclusive);
             if (offset >= 0)
             {
                 return;
             }
         }
     }
 }
Beispiel #8
0
 public int GetChildren(int cChildren, out int pcChildren, ISymUnmanagedScope[] children)
 {
     _scope.GetChildren(cChildren, out pcChildren, children);
     if (children != null)
     {
         for (int i = 0; i < pcChildren; i++)
         {
             children[i] = new SymScope(_reader, children[i]);
         }
     }
     return SymUnmanagedReaderExtensions.S_OK;
 }
 public static ImmutableArray <ISymUnmanagedNamespace> GetNamespaces(this ISymUnmanagedScope scope)
 {
     return(ToImmutableOrEmpty(GetItems(scope,
                                        (ISymUnmanagedScope a, int b, out int c, ISymUnmanagedNamespace[] d) => a.GetNamespaces(b, out c, d))));
 }
        public static ISymUnmanagedMethod GetMethod(this ISymUnmanagedScope instance)
        {
            ISymUnmanagedMethod returnValue = instance.__GetMethod();

            return(returnValue);
        }
        public static ISymUnmanagedScope GetRootScope(this ISymUnmanagedMethod instance)
        {
            ISymUnmanagedScope returnValue = instance.__GetRootScope();

            return(returnValue);
        }
		// ISymUnmanagedScope
		
		public static ISymUnmanagedScope[] GetChildren(this ISymUnmanagedScope symScope)
		{
			uint count;
			symScope.GetChildren(0, out count, new ISymUnmanagedScope[0]);
			ISymUnmanagedScope[] children = new ISymUnmanagedScope[count];
			symScope.GetChildren(count, out count, children);
			return children;
		}
Beispiel #13
0
 public static ISymUnmanagedConstant[] GetAndValidateConstants(ISymUnmanagedScope scope, int expectedCount)
 {
     int count, count2;
     Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetConstants(0, out count, null));
     Assert.Equal(expectedCount, count);
     var constants = new ISymUnmanagedConstant[count];
     Assert.Equal(HResult.S_OK, ((ISymUnmanagedScope2)scope).GetConstants(count, out count2, constants));
     Assert.Equal(count, count2);
     return constants;
 }
Beispiel #14
0
 public SymbolScopeImpl(ISymUnmanagedScope scope, SymbolMethod method, SymbolScope parent)
 {
     this.scope  = scope;
     this.method = method;
     this.parent = parent;
 }
Beispiel #15
0
 public int GetScopeFromOffset(int offset, [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedScope scope)
 {
     // SymReader doesn't support.
     scope = null;
     return(HResult.S_OK);
 }
 public static ImmutableArray <ISymUnmanagedConstant> GetConstants(this ISymUnmanagedScope scope)
 {
     return(ToImmutableOrEmpty(GetConstantsInternal((ISymUnmanagedScope2)scope)));
 }
Beispiel #17
0
 internal SymbolScope(ISymUnmanagedScope unScope)
 {
     Contract.Requires(unScope != null);
     private_scope = unScope;
 }
 private static ISymUnmanagedVariable[] GetLocalsInternal(ISymUnmanagedScope scope)
 {
     return(GetItems(scope,
                     (ISymUnmanagedScope a, out int b) => a.GetLocalCount(out b),
                     (ISymUnmanagedScope a, int b, out int c, ISymUnmanagedVariable[] d) => a.GetLocals(b, out c, d)));
 }
 public static ImmutableArray <ISymUnmanagedVariable> GetLocals(this ISymUnmanagedScope scope)
 {
     return(ToImmutableOrEmpty(GetLocalsInternal(scope)));
 }
 private static ISymUnmanagedScope[] GetScopesInternal(ISymUnmanagedScope scope)
 {
     return(GetItems(scope,
                     (ISymUnmanagedScope a, int b, out int c, ISymUnmanagedScope[] d) => a.GetChildren(b, out c, d)));
 }
Beispiel #21
0
        /// <summary>
        /// Emits scope debugging symbols based on <c>ISymUnmanagedScope</c> insatnce, representing
        /// scope from new assembly.
        /// </summary>
        /// <param name="smScope">Scope from new version of changed assembly.</param>
        /// <param name="placeholder">Placeholder translation for local variables.</param>
        public void EmitScope(ISymUnmanagedScope smScope, Dictionary<int, int> placeholder)
        {
            if(State != WriterState.Building){
                throw new TranslatingException("ISym* interfaces were not initialized.");
            }
            uint scStartOffset = smScope.__GetStartOffset();
            uint scEndOffset = smScope.__GetEndOffset();
            mWriter.OpenScope(scStartOffset);

            uint localsCount = smScope.__GetLocalCount();
            if(localsCount > 0){
                uint read;
                ISymUnmanagedVariable[] variables = new ISymUnmanagedVariable[localsCount];
                smScope.__GetLocals(localsCount,out read,variables);
                for (int i = 0; i < localsCount; i++) {
                    byte[] signature = variables[i].GetSignature();
                    Signature sig = new Signature(signature);
                    sig.Migrate(translator);
                    signature = sig.Compress();

                    string name = variables[i].GetName();
                    uint addr1 = 0;//variables[i].GetAddressField1();
                    uint addr2 = 0;//variables[i].GetAddressField2();
                    uint addr3 = 0;//variables[i].GetAddressField3();
                    uint addrKind = variables[i].GetAddressKind();//variables[i].GetAddressKind();
                    if((variables[i].GetAttributes() & 1) != 1)
                    {
                        addr1 = variables[i].GetAddressField1();
                        addrKind = variables[i].GetAddressKind();
                        if (placeholder != null && placeholder.ContainsKey((int)addr1))
                        {
                            addr1 = (uint)placeholder[(int)addr1];
                        }
                    }
                    uint varStartOffset = scStartOffset;
                    uint varEndOffset = scEndOffset;
                    uint attributes = variables[i].GetAttributes();

                    IntPtr pName = Marshal.StringToCoTaskMemUni(name);
                    IntPtr pSig = Marshal.AllocCoTaskMem(signature.Length);
                    Marshal.Copy(signature,0,pSig,signature.Length);

                    try{
                        mWriter.DefineLocalVariable(pName,attributes,(uint)signature.Length,pSig,addrKind,
                                                    addr1,addr2,addr3,varStartOffset,varEndOffset);
                    } finally {
                        Marshal.FreeCoTaskMem(pSig);
                        Marshal.FreeCoTaskMem(pName);
                    }
                }
            }
            ISymUnmanagedScope[] subScopes = smScope.GetChildren();
            foreach(ISymUnmanagedScope subScope in subScopes){
                EmitScope(subScope,placeholder);
            }
            mWriter.CloseScope(scEndOffset);
        }
Beispiel #22
0
 int ISymUnmanagedMethod.GetRootScope(out ISymUnmanagedScope retVal)
 {
     retVal = _rootScope;
     return(SymUnmanagedReaderExtensions.S_OK);
 }
Beispiel #23
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);
        }
Beispiel #24
0
		public SymbolScope(ISymUnmanagedScope scope) {
			this.scope = scope;
		}
Beispiel #25
0
 public int GetRootScope([MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedScope scope)
 {
     // SymReader always creates a new scope instance
     scope = new SymScope(GetRootScopeData());
     return(HResult.S_OK);
 }
 public static void GetChildren(this ISymUnmanagedScope instance, uint cChildren, out uint pcChildren, ISymUnmanagedScope[] children)
 {
     instance.__GetChildren(cChildren, out pcChildren, children);
 }
Beispiel #27
0
            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;
            }
 public static uint GetLocalCount(this ISymUnmanagedScope instance)
 {
     return(instance.__GetLocalCount());
 }
Beispiel #29
0
        internal static void GetAllScopes(this ISymUnmanagedMethod method, ArrayBuilder <ISymUnmanagedScope> builder, int offset, bool isScopeEndInclusive)
        {
            ISymUnmanagedScope scope = method.GetRootScope();

            GetAllScopes(scope, builder, offset, isScopeEndInclusive);
        }
Beispiel #30
0
 internal SymScope(ISymUnmanagedScope target)
 {
     m_target = target;
 }
        public static ISymUnmanagedScope GetScopeFromOffset(this ISymUnmanagedMethod instance, uint offset)
        {
            ISymUnmanagedScope returnValue = instance.__GetScopeFromOffset(offset);

            return(returnValue);
        }
Beispiel #32
0
 public int GetScopeFromOffset(int offset, out ISymUnmanagedScope retVal)
 {
     throw new NotImplementedException();
 }
        public static ISymUnmanagedScope GetParent(this ISymUnmanagedScope instance)
        {
            ISymUnmanagedScope returnValue = instance.__GetParent();

            return(returnValue);
        }
Beispiel #34
0
 internal SymScope(ISymUnmanagedScope target)
 {
     m_target = target;
 }
 public static uint GetEndOffset(this ISymUnmanagedScope instance)
 {
     return(instance.__GetEndOffset());
 }
 public static void GetLocals(this ISymUnmanagedScope instance, uint cLocals, out uint pcLocals, ISymUnmanagedVariable[] locals)
 {
     instance.__GetLocals(cLocals, out pcLocals, locals);
     ProcessOutParameter(locals);
 }
Beispiel #37
0
        public ISymbolScope[] GetChildren()
        {
            int count;
            m_target.GetChildren(0, out count, null);
            ISymUnmanagedScope[] uScopes = new ISymUnmanagedScope[count];
            m_target.GetChildren(count, out count, uScopes);

            int i;
            ISymbolScope[] scopes = new ISymbolScope[count];
            for (i = 0; i < count; i++)
            {
                scopes[i] = new SymScope(uScopes[i]);
            }
            return scopes;
        }
 public static void GetNamespaces(this ISymUnmanagedScope instance, uint cNameSpaces, out uint pcNameSpaces, ISymUnmanagedNamespace[] namespaces)
 {
     instance.__GetNamespaces(cNameSpaces, out pcNameSpaces, namespaces);
     ProcessOutParameter(namespaces);
 }
Beispiel #39
0
 public int GetRootScope(out ISymUnmanagedScope retVal)
 {
     _method.GetRootScope(out retVal);
     if (retVal != null)
     {
         retVal = new SymScope(_reader, retVal);
     }
     return SymUnmanagedReaderExtensions.S_OK;
 }
Beispiel #40
0
 public SymbolScope(ISymUnmanagedScope scope)
 {
     this.scope = scope;
 }
Beispiel #41
0
 internal SymScope(SymReader reader, ISymUnmanagedScope scope)
 {
     _reader = reader;
     _scope = scope;
 }
Beispiel #42
0
        private void WriteScopes(ISymUnmanagedScope scope)
        {
            writer.WriteStartElement("scope");
            {
                writer.WriteAttributeString("startOffset", AsILOffset(scope.GetStartOffset()));
                writer.WriteAttributeString("endOffset", AsILOffset(scope.GetEndOffset()));
                {
                    foreach (ISymUnmanagedNamespace @namespace in scope.GetNamespaces())
                    {
                        WriteNamespace(@namespace);
                    }

                    WriteLocalsHelper(scope, slotNames: null, includeChildScopes: false);
                }
                foreach (ISymUnmanagedScope child in scope.GetScopes())
                {
                    WriteScopes(child);
                }
            }
            writer.WriteEndElement(); // </scope>
        }
Beispiel #43
0
 public int GetParent(out ISymUnmanagedScope pRetVal)
 {
     throw new NotImplementedException();
 }
Beispiel #44
0
        private static ISymbolScope WrapRawScope(ISymUnmanagedScope rawScope)
        {
            if (ConstructorOfISymbolScope == null)
            {
                // NOTE: We have the sources for this type, so we can just make the constructor
                // public if reflection proves to be too expensive.
                var assembly = typeof(SymbolBinder).Assembly;
                var type = assembly.GetType("Microsoft.Samples.Debugging.CorSymbolStore.SymScope", throwOnError: true);
                var ctor = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single();
                Interlocked.CompareExchange(ref ConstructorOfISymbolScope, ctor, null);
            }

            return (ISymbolScope)ConstructorOfISymbolScope.Invoke(new object[] { rawScope });
        }
		public static void GetChildren(this ISymUnmanagedScope instance, uint cChildren, out uint pcChildren, ISymUnmanagedScope[] children)
		{
			instance.__GetChildren(cChildren, out pcChildren, children);
			ProcessOutParameter(children);
		}
Beispiel #46
0
 // Helper method to write the local variables in the given scope.
 // Scopes match an IL range, and also have child scopes.
 private void WriteLocalsHelper(ISymUnmanagedScope rawScope, Dictionary<int, ImmutableArray<string>> slotNames, bool includeChildScopes)
 {
     WriteLocalsHelper(WrapRawScope(rawScope), slotNames, includeChildScopes);
 }
Beispiel #47
0
 public static ISymUnmanagedScope[] GetAndValidateChildScopes(ISymUnmanagedScope scope, int expectedCount)
 {
     int count, count2;
     Assert.Equal(HResult.S_OK, scope.GetChildren(0, out count, null));
     Assert.Equal(expectedCount, count);
     var children = new ISymUnmanagedScope[count];
     Assert.Equal(HResult.S_OK, scope.GetChildren(count, out count2, children));
     Assert.Equal(count, count2);
     return children;
 }
Beispiel #48
0
        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
            }
        }
Beispiel #49
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;
 }
Beispiel #50
0
 internal SymScope(SymReader reader, ISymUnmanagedScope scope)
 {
     _reader = reader;
     _scope  = scope;
 }
        //
        // 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]);
            }
        }
Beispiel #52
0
 public MockSymUnmanagedMethod(ISymUnmanagedScope rootScope)
 {
     _rootScope = rootScope;
 }
Beispiel #53
0
 int ISymUnmanagedMethod.GetRootScope(out ISymUnmanagedScope retVal)
 {
     retVal = _rootScope;
     return(HResult.S_OK);
 }
Beispiel #54
0
 int ISymUnmanagedMethod.GetScopeFromOffset(int offset, out ISymUnmanagedScope retVal)
 {
     throw new NotImplementedException();
 }
Beispiel #55
0
            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);
                }

            }
Beispiel #56
0
 public int GetParent(out ISymUnmanagedScope pRetVal)
 {
     throw new NotImplementedException();
 }
Beispiel #57
0
 List<DebugLocalVariableInfo> GetLocalVariablesInScope(ISymUnmanagedScope symScope)
 {
     List<DebugLocalVariableInfo> vars = new List<DebugLocalVariableInfo>();
     foreach (ISymUnmanagedVariable symVar in symScope.GetLocals()) {
         ISymUnmanagedVariable symVarCopy = symVar;
         var locVarSig = new DebugSignatureReader().ReadTypeSignature(symVar.GetSignature());
         DebugType locVarType = DebugType.CreateFromSignature(this.DebugModule, locVarSig, declaringType);
         // Compiler generated?
         // NB: Display class does not have the compiler-generated flag
         if ((symVar.GetAttributes() & 1) == 1 || symVar.GetName().StartsWith("CS$")) {
             // Get display class from local variable
             if (locVarType.IsDisplayClass) {
                 AddCapturedLocalVariables(
                     vars,
                     (int)symScope.GetStartOffset(),
                     (int)symScope.GetEndOffset(),
                     delegate(StackFrame context) {
                         return GetLocalVariableValue(context, symVarCopy);
                     },
                     locVarType
                 );
             }
         } else {
             DebugLocalVariableInfo locVar = new DebugLocalVariableInfo(
                 symVar.GetName(),
                 (int)symVar.GetAddressField1(),
                 // symVar also has Get*Offset methods, but the are not implemented
                 (int)symScope.GetStartOffset(),
                 (int)symScope.GetEndOffset(),
                 locVarType,
                 delegate(StackFrame context) {
                     return GetLocalVariableValue(context, symVarCopy);
                 }
             );
             vars.Add(locVar);
         }
     }
     foreach(ISymUnmanagedScope childScope in symScope.GetChildren()) {
         vars.AddRange(GetLocalVariablesInScope(childScope));
     }
     return vars;
 }
        private static void SerializeScope(
            MetadataBuilder metadataBuilder,
            MetadataModel metadataModel,
            MethodDefinitionHandle methodHandle,
            ImportScopeHandle importScopeHandle,
            ISymUnmanagedScope symScope,
            Dictionary <int, DynamicLocalInfo> dynamicSlots,
            Dictionary <string, DynamicLocalInfo> dynamicNames,
            bool vbSemantics,
            ref LocalVariableHandle lastLocalVariableHandle,
            ref LocalConstantHandle lastLocalConstantHandle)
        {
            // VB Windows PDB encode the range as end-inclusive,
            // all Portable PDBs use end-exclusive encoding.
            int start = symScope.GetStartOffset();
            int end   = symScope.GetEndOffset() + (vbSemantics ? 1 : 0);

            metadataBuilder.AddLocalScope(
                method: methodHandle,
                importScope: importScopeHandle,
                variableList: NextHandle(lastLocalVariableHandle),
                constantList: NextHandle(lastLocalConstantHandle),
                startOffset: start,
                length: end - start);

            foreach (var symLocal in symScope.GetLocals())
            {
                int    slot = symLocal.GetSlot();
                string name = symLocal.GetName();

                lastLocalVariableHandle = metadataBuilder.AddLocalVariable(
                    attributes: (LocalVariableAttributes)symLocal.GetAttributes(),
                    index: slot,
                    name: metadataBuilder.GetOrAddString(name));

                DynamicLocalInfo dynamicInfo;
                if (slot > 0 && dynamicSlots.TryGetValue(slot, out dynamicInfo) ||
                    slot == 0 && dynamicNames.TryGetValue(name, out dynamicInfo))
                {
                    metadataBuilder.AddCustomDebugInformation(
                        parent: lastLocalVariableHandle,
                        kind: metadataBuilder.GetOrAddGuid(PortableCustomDebugInfoKinds.DynamicLocalVariables),
                        value: SerializeDynamicLocalBlob(metadataBuilder, dynamicInfo));
                }
            }

            foreach (var symConstant in symScope.GetConstants())
            {
                string name  = symConstant.GetName();
                object value = symConstant.GetValue();

                lastLocalConstantHandle = metadataBuilder.AddLocalConstant(
                    name: metadataBuilder.GetOrAddString(name),
                    signature: SerializeConstantSignature(metadataBuilder, metadataModel, symConstant.GetSignature(), value));

                DynamicLocalInfo dynamicInfo;
                if (dynamicNames.TryGetValue(name, out dynamicInfo))
                {
                    metadataBuilder.AddCustomDebugInformation(
                        parent: lastLocalConstantHandle,
                        kind: metadataBuilder.GetOrAddGuid(PortableCustomDebugInfoKinds.DynamicLocalVariables),
                        value: SerializeDynamicLocalBlob(metadataBuilder, dynamicInfo));
                }
            }

            int previousChildScopeEnd = start;

            foreach (ISymUnmanagedScope child in symScope.GetChildren())
            {
                int childScopeStart = child.GetStartOffset();
                int childScopeEnd   = child.GetEndOffset();

                // scopes are properly nested:
                if (childScopeStart < previousChildScopeEnd || childScopeEnd > end)
                {
                    // TODO: loc/warning
                    throw new BadImageFormatException($"Invalid scope IL offset range: [{childScopeStart}, {childScopeEnd}), method 0x{MetadataTokens.GetToken(methodHandle):x}.");
                }

                previousChildScopeEnd = childScopeEnd;

                SerializeScope(metadataBuilder, metadataModel, methodHandle, importScopeHandle, child, dynamicSlots, dynamicNames, vbSemantics, ref lastLocalVariableHandle, ref lastLocalConstantHandle);
            }
        }