Ejemplo n.º 1
0
        void Write(MethodDef method)
        {
            uint rid = metaData.GetRid(method);

            if (rid == 0)
            {
                Error("Method {0} ({1:X8}) is not defined in this module ({2})", method, method.MDToken.Raw, module);
                return;
            }

            var  body       = method.Body;
            uint methodSize = GetSizeOfBody(body);

            writer.OpenMethod(new SymbolToken((int)new MDToken(MD.Table.Method, metaData.GetRid(method)).Raw));
            writer.OpenScope(0);
            AddLocals(method, body.Variables, 0, methodSize);
            seqPointsHelper.Write(this, body.Instructions);
            foreach (var scope in GetScopes(body.Scope))
            {
                foreach (var ns in scope.Namespaces)
                {
                    writer.UsingNamespace(ns);
                }
            }
            writer.CloseScope((int)methodSize);
            writer.CloseMethod();
        }
Ejemplo n.º 2
0
 private void WriteMethod(XmlElement node)
 {
     m_writer.OpenMethod(Util.AsSymToken(node.GetAttribute("token")));
     if (node.GetAttribute("localSigMetadataToken").Length != 0)
     {
         var SymTok = new SymbolToken(Util.ToInt32(node.GetAttribute("localSigMetadataToken"), 16));
         WriteScopesAndLocals(node["scope"], SymTok);
         WriteSequencePoints(node);
     }
     m_writer.CloseMethod();
 }
Ejemplo n.º 3
0
        void Write(MethodDef method, List <PdbCustomDebugInfo> cdiBuilder)
        {
            uint rid = metaData.GetRid(method);

            if (rid == 0)
            {
                Error("Method {0} ({1:X8}) is not defined in this module ({2})", method, method.MDToken.Raw, module);
                return;
            }

            var info        = new CurrentMethod(this, method, instrToOffset);
            var body        = method.Body;
            var symbolToken = new SymbolToken((int)new MDToken(MD.Table.Method, metaData.GetRid(method)).Raw);

            writer.OpenMethod(symbolToken);
            seqPointsHelper.Write(this, info.Method.Body.Instructions);

            var pdbMethod = body.PdbMethod;

            if (pdbMethod == null)
            {
                body.PdbMethod = pdbMethod = new PdbMethod();
            }
            var scope = pdbMethod.Scope;

            if (scope == null)
            {
                pdbMethod.Scope = scope = new PdbScope();
            }
            if (scope.Namespaces.Count == 0 && scope.Variables.Count == 0 && scope.Constants.Count == 0)
            {
                if (scope.Scopes.Count == 0)
                {
                    // We must open at least one sub scope (the sym writer creates the 'method' scope
                    // which covers the whole method) or the native PDB reader will fail to read all
                    // sequence points.
                    writer.OpenScope(0);
                    writer.CloseScope((int)info.BodySize);
                }
                else
                {
                    foreach (var childScope in scope.Scopes)
                    {
                        WriteScope(ref info, childScope, 0);
                    }
                }
            }
            else
            {
                Debug.Fail("Root scope isn't empty");
                WriteScope(ref info, scope, 0);
            }

            PdbAsyncMethodCustomDebugInfo asyncMethod;

            GetPseudoCustomDebugInfos(method.CustomDebugInfos, cdiBuilder, out asyncMethod);
            if (cdiBuilder.Count != 0)
            {
                customDebugInfoWriterContext.Logger = GetLogger();
                var cdiData = PdbCustomDebugInfoWriter.Write(metaData, method, customDebugInfoWriterContext, cdiBuilder);
                if (cdiData != null)
                {
                    writer.SetSymAttribute(symbolToken, "MD2", cdiData);
                }
            }

            if (asyncMethod != null)
            {
                if (writer3 == null || !writer3.SupportsAsyncMethods)
                {
                    Error("PDB symbol writer doesn't support writing async methods");
                }
                else
                {
                    WriteAsyncMethod(ref info, asyncMethod);
                }
            }

            writer.CloseMethod();
        }