Skip to content

Commit

Permalink
Fix reading mdb scope end (#466)
Browse files Browse the repository at this point in the history
* Fix reading mdb scope end
  • Loading branch information
jbevain authored Nov 16, 2017
1 parent 14e6162 commit b4f4571
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
26 changes: 25 additions & 1 deletion Mono.Cecil.Cil/CodeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Mono.Cecil/AssemblyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions Mono.Cecil/MethodDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ();
Expand Down

0 comments on commit b4f4571

Please sign in to comment.