Hi,

for the ApiChange tool I do load quite a lot assemblies and serach
normally for method, event, property, field, .. usage across other
assemblies. For this I do simply load the assembly and check if there
is a match. If yes then I do load the pdb for the already loaded
assembly to load the pdb directly or download it from a symbol server
when present. Then I can extract the file/line number via

        public KeyValuePair<string, int> GetFileLine(Instruction ins,
MethodDefinition method, bool bSearchForward)
        {
            using (Tracer t = new Tracer(myType, "GetFileLine"))
            {
                t.Info("Try to get file and line info for {0} {1}
forwardSearch {2}", method.DeclaringType.FullName, method.Name,
bSearchForward);

                var symReader =
LoadPdbForModule(method.DeclaringType.Module);
                if (symReader != null && method.Body != null)
                {
                    symReader.Read(method.Body);
                    Instruction current = ins;

                    if (bSearchForward)
                    {
                        current = GetILInstructionWithLineNumber(ins,
true);
                        if (current == null)
                        {
                            current =
GetILInstructionWithLineNumber(ins, false);
                        }
                    }
                    else
                    {
                        current = GetILInstructionWithLineNumber(ins,
false);
                        if (current == null)
                        {
                            current =
GetILInstructionWithLineNumber(ins, true);
                        }
                    }

                    if (current != null)
                    {
                        return new KeyValuePair<string, int>(
 
PatchDriveLetter(current.SequencePoint.Document.Url),
current.SequencePoint.StartLine);
                    }
                }
                else
                {
                    t.Info("No symbol reader present or method has no
body");
                }

                return new KeyValuePair<string, int>("", 0);
            }
        }

With Cecil 0.9 this seems no longer to be possible. The PdbReader does
container a method that looks promising:

void Read (MethodBody body, InstructionMapper mapper);

But I did not see what method I need to provide as valid instruction
mapper for a given MethodBody. At least I did not see how a valid one
should work.

Yours,
  Alois Kraus

-- 
--
mono-cecil

Reply via email to