예제 #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();
        }
예제 #2
0
        void WriteScope(ref CurrentMethod info, PdbScope scope, int recursionCounter)
        {
            if (recursionCounter >= 1000)
            {
                Error("Too many PdbScopes");
                return;
            }

            int startOffset = info.GetOffset(scope.Start);
            int endOffset   = info.GetOffset(scope.End);

            writer.OpenScope(startOffset);
            AddLocals(info.Method, scope.Variables, (uint)startOffset, (uint)endOffset);
            if (scope.Constants.Count > 0)
            {
                if (writer3 == null)
                {
                    Error("Symbol writer doesn't implement ISymbolWriter3: no constants can be written to the PDB file");
                }
                else
                {
                    var constants = scope.Constants;
                    var sig       = new FieldSig();
                    for (int i = 0; i < constants.Count; i++)
                    {
                        var constant = constants[i];
                        sig.Type = constant.Type;
                        var token = metaData.GetToken(sig);
                        writer3.DefineConstant2(constant.Name, constant.Value ?? 0, token.Raw);
                    }
                }
            }
            foreach (var ns in scope.Namespaces)
            {
                writer.UsingNamespace(ns);
            }
            foreach (var childScope in scope.Scopes)
            {
                WriteScope(ref info, childScope, recursionCounter + 1);
            }
            writer.CloseScope(startOffset == 0 && endOffset == info.BodySize ? endOffset : endOffset - localsEndScopeIncValue);
        }