diff --git a/Mono.Cecil.Cil/CodeReader.cs b/Mono.Cecil.Cil/CodeReader.cs index 76add4d13..ab6d90047 100644 --- a/Mono.Cecil.Cil/CodeReader.cs +++ b/Mono.Cecil.Cil/CodeReader.cs @@ -62,6 +62,30 @@ public MethodBody ReadMethodBody (MethodDefinition method) return this.body; } + public int ReadCodeSize (MethodDefinition method) + { + var position = MoveTo (method); + + var code_size = ReadCodeSize (); + + MoveBackTo (position); + return code_size; + } + + int ReadCodeSize () + { + var flags = ReadByte (); + switch (flags & 0x3) { + case 0x2: // tiny + return flags >> 2; + case 0x3: // fat + Advance (-1 + 2 + 2); // go back, 2 bytes flags, 2 bytes stack size + return (int) ReadUInt32 (); + default: + throw new InvalidOperationException (); + } + } + void ReadMethodBody () { var flags = ReadByte (); @@ -161,7 +185,7 @@ void ReadScope (ScopeDebugInformation scope) { var start_instruction = GetInstruction (scope.Start.Offset); if (start_instruction != null) - scope.Start = new InstructionOffset (start_instruction); + scope.Start = new InstructionOffset (start_instruction); var end_instruction = GetInstruction (scope.End.Offset); scope.End = end_instruction != null diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index a2ad803eb..f25cd3aea 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -2099,6 +2099,11 @@ public MethodBody ReadMethodBody (MethodDefinition method) return code.ReadMethodBody (method); } + public int ReadCodeSize (MethodDefinition method) + { + return code.ReadCodeSize (method); + } + public CallSite ReadCallSite (MetadataToken token) { if (!MoveTo (Table.StandAloneSig, token.RID)) diff --git a/Mono.Cecil/MethodDefinition.cs b/Mono.Cecil/MethodDefinition.cs index 71de613ce..5dda999ce 100644 --- a/Mono.Cecil/MethodDefinition.cs +++ b/Mono.Cecil/MethodDefinition.cs @@ -143,9 +143,9 @@ public bool HasBody { public MethodBody Body { get { - MethodBody localBody = this.body; - if (localBody != null) - return localBody; + var local = this.body; + if (local != null) + return local; if (!HasBody) return null; diff --git a/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs b/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs index 66a722590..59e933a37 100644 --- a/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs +++ b/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs @@ -78,6 +78,7 @@ public MethodDebugInformation Read (MethodDefinition method) return null; var info = new MethodDebugInformation (method); + info.code_size = ReadCodeSize (method); var scopes = ReadScopes (entry, info); ReadLineNumbers (entry, info); @@ -86,6 +87,11 @@ public MethodDebugInformation Read (MethodDefinition method) return info; } + static int ReadCodeSize (MethodDefinition method) + { + return method.Module.Read (method, (m, reader) => reader.ReadCodeSize (m)); + } + static void ReadLocalVariables (MethodEntry entry, ScopeDebugInformation [] scopes) { var locals = entry.GetLocals ();