private List <Constant> ReadConstants(ISymbolScope scope) { // Read the constants. // IldbSymbols.dll doesn't support ISymUnmanagedScope2 so nothing we can do for ILDB to read // constants (even though it does support writing them). But RefEmit doesn't ever emit constants // anyway, so there should be no need for this. if (symFormat == SymbolFormat.ILDB) { return(null); } // Note - ISymbolConstants are written to the xml, but cannot be easily round-tripped. // The SigTokens cannot be easily retrieved from either the pdb or the assembly metadata List <Constant> constants = new List <Constant>(); ISymbolScope2 scope2 = (ISymbolScope2)scope; foreach (ISymbolConstant c in scope2.GetConstants()) { Constant constData = new Constant(); constData.name = c.GetName(); constData.value = c.GetValue().ToString(); constData.signature = Util.ToHexString(c.GetSignature()); constants.Add(constData); } return(constants); }
private void WriteScopes(ISymbolScope2 scope) { m_writer.WriteStartElement("scope"); { m_writer.WriteAttributeString("startOffset", Util.AsIlOffset(scope.StartOffset)); m_writer.WriteAttributeString("endOffset", Util.AsIlOffset(scope.EndOffset)); { // If there are no locals, then this element will just be empty. WriteLocalsHelper(scope, false); } foreach (ISymbolScope child in scope.GetChildren()) { WriteScopes((ISymbolScope2)child); } } m_writer.WriteEndElement(); // </scope> }
private void WriteLocalsHelper(ISymbolScope2 scope, bool IncludeChildScopes) { foreach (ISymbolVariable l in scope.GetLocals()) { m_writer.WriteStartElement("local"); { m_writer.WriteAttributeString("name", l.Name); // Each local maps to a unique "IL Index" or "slot" number. // This index is what you pass to ICorDebugILFrame::GetLocalVariable() to get // a specific local variable. Debug.Assert(l.AddressKind == SymAddressKind.ILOffset); int slot = l.AddressField1; m_writer.WriteAttributeString("il_index", Util.CultureInvariantToString(slot)); // Provide scope range m_writer.WriteAttributeString("il_start", Util.AsIlOffset(scope.StartOffset)); m_writer.WriteAttributeString("il_end", Util.AsIlOffset(scope.EndOffset)); m_writer.WriteAttributeString("attributes", l.Attributes.ToString()); Byte[] b_signature = l.GetSignature(); m_writer.WriteAttributeString("signature", Util.ToHexString(b_signature)); } m_writer.WriteEndElement(); // </local> } foreach (ISymbolConstant c in scope.GetConstants()) { // BUGBUG - ISymbolConstants are written to the xml, but cannot be easily round-tripped. // The SigTokens cannot be easily retrieved from either the pdb or the assembly metadata m_writer.WriteStartElement("constant"); { m_writer.WriteAttributeString("name", c.GetName()); m_writer.WriteAttributeString("value", c.GetValue().ToString()); m_writer.WriteAttributeString("signature", Util.ToHexString(c.GetSignature())); } m_writer.WriteEndElement(); // </constant> } if (!IncludeChildScopes) { return; } foreach (ISymbolScope childScope in scope.GetChildren()) { WriteLocalsHelper((ISymbolScope2)childScope); } }
private void WriteLocalsHelper(ISymbolScope2 scope, bool IncludeChildScopes) { foreach (ISymbolVariable l in scope.GetLocals()) { m_writer.WriteStartElement("local"); { m_writer.WriteAttributeString("name", l.Name); // Each local maps to a unique "IL Index" or "slot" number. // This index is what you pass to ICorDebugILFrame::GetLocalVariable() to get // a specific local variable. Debug.Assert(l.AddressKind == SymAddressKind.ILOffset); int slot = l.AddressField1; m_writer.WriteAttributeString("il_index", Util.CultureInvariantToString(slot)); // Provide scope range m_writer.WriteAttributeString("il_start", Util.AsIlOffset(scope.StartOffset)); m_writer.WriteAttributeString("il_end", Util.AsIlOffset(scope.EndOffset)); m_writer.WriteAttributeString("attributes", l.Attributes.ToString()); Byte[] b_signature = l.GetSignature(); m_writer.WriteAttributeString("signature", Util.ToHexString(b_signature)); } m_writer.WriteEndElement(); // </local> } foreach (ISymbolConstant c in scope.GetConstants()) { // BUGBUG - ISymbolConstants are written to the xml, but cannot be easily round-tripped. // The SigTokens cannot be easily retrieved from either the pdb or the assembly metadata m_writer.WriteStartElement("constant"); { m_writer.WriteAttributeString("name", c.GetName()); m_writer.WriteAttributeString("value", c.GetValue().ToString()); m_writer.WriteAttributeString("signature", Util.ToHexString(c.GetSignature())); } m_writer.WriteEndElement(); // </constant> } if (!IncludeChildScopes) { return; } foreach (ISymbolScope childScope in scope.GetChildren()) { WriteLocalsHelper((ISymbolScope2) childScope); } }
// Helper method to write the local variables in the given scope. // Scopes match an IL range, and also have child scopes. private void WriteLocalsHelper(ISymbolScope2 scope) { WriteLocalsHelper(scope, true); }
private void WriteScopes(ISymbolScope2 scope) { m_writer.WriteStartElement("scope"); { m_writer.WriteAttributeString("startOffset", Util.AsIlOffset(scope.StartOffset)); m_writer.WriteAttributeString("endOffset", Util.AsIlOffset(scope.EndOffset)); { // If there are no locals, then this element will just be empty. WriteLocalsHelper(scope, false); } foreach (ISymbolScope child in scope.GetChildren()) { WriteScopes((ISymbolScope2) child); } } m_writer.WriteEndElement(); // </scope> }