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 WriteScopesAndLocals(XmlElement node, SymbolToken localSigToken)
        {
            Debug.Assert(m_writer != null, "XML Writer not innitialized");
            Debug.Assert(node != null, "Node must be passed.");
            m_writer.OpenScope(Util.ToInt32(node.GetAttribute("startOffset"), 16));
            foreach (XmlElement child in node.ChildNodes)
            {
                switch (child.Name)
                {
                case "scope":
                    WriteScopesAndLocals(child, localSigToken);
                    break;

                case "local":
                    string name        = child.GetAttribute("name");
                    int    addr1       = Util.ToInt32(child.GetAttribute("il_index"));
                    int    startOffset = Util.ToInt32(child.GetAttribute("il_start"), 16);
                    int    endOffset   = Util.ToInt32(child.GetAttribute("il_end"), 16);
                    int    attributes  = Util.ToInt32(child.GetAttribute("attributes"));
                    m_writer.DefineLocalVariable(name, attributes, localSigToken, (int)SymAddressKind.ILOffset,
                                                 addr1, 0, 0, startOffset, endOffset);
                    break;

                case "constant":
                    m_writer.DefineConstant(child.GetAttribute("name"), child.GetAttribute("value"),
                                            Util.ToByteArray(child.GetAttribute("signature")));
                    break;

                default:
                    throw new FormatException("Unrecognized Xml element");
                }
            }
            m_writer.CloseScope(Util.ToInt32(node.GetAttribute("endOffset"), 16));
        }
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();
        }