Skip to content

Commit

Permalink
Fixes for missing debugging line information--call instructions conta…
Browse files Browse the repository at this point in the history
…in a method reference that must have symbols re-read. I'm not sure why Mono.Cecil is this way.
  • Loading branch information
kaby76 committed Apr 4, 2018
1 parent b41d2c0 commit 2116ef7
Show file tree
Hide file tree
Showing 5 changed files with 878 additions and 281 deletions.
15 changes: 11 additions & 4 deletions Campy.Compiler/cfg.cs
@@ -1,4 +1,5 @@
using Swigged.LLVM;
using Mono.Collections.Generic;
using Swigged.LLVM;

namespace Campy.Compiler
{
Expand Down Expand Up @@ -328,12 +329,18 @@ public Vertex Split(int i)
System.Console.WriteLine("New node is " + result.Name);
}

var sr = result._original_method_reference.Module.SymbolReader;
var mdi = sr?.Read(result._method_definition);
Collection<SequencePoint> sqps = mdi != null ? mdi.SequencePoints : new Collection<SequencePoint>();

// Add instructions from split point to new block.
for (int j = i; j < count; ++j)
{
INST inst_to_move = INST.Wrap(Instructions[j].Instruction);
CFG.Vertex v = inst_to_move.Block;
inst_to_move.Block = (CFG.Vertex) result;
var offset = Instructions[j].Instruction.Offset;
INST inst_to_move = INST.Wrap(
Instructions[j].Instruction,
result,
sqps.Where(s => { return s.Offset == offset; }).FirstOrDefault());
result.Instructions.Add(inst_to_move);
}

Expand Down
8 changes: 3 additions & 5 deletions Campy.Compiler/importer.cs
Expand Up @@ -251,18 +251,16 @@ private void ExtractBasicBlocksOfMethod(Tuple<MethodReference, List<TypeReferenc
_cfg.Entries.Add(v);

// Get debugging information on line/column/offset in method.
original_method_reference.Module.ReadSymbols();
var sr = original_method_reference.Module.SymbolReader;
var mdi = sr?.Read(method_definition);
var sqps = mdi?.SequencePoints;
Collection<SequencePoint> sqps = mdi != null ? mdi.SequencePoints : new Collection<SequencePoint>();

// Add instructions to the basic block.
for (int j = 0; j < instruction_count; ++j)
{
Mono.Cecil.Cil.Instruction mi = method_definition.Body.Instructions[j];
INST i = INST.Wrap(mi);
i.Block = v;
if (sqps != null)
i.SeqPoint = sqps.Where(s => { return s.Offset == mi.Offset; }).FirstOrDefault();
INST i = INST.Wrap(mi, v, sqps.Where(s => { return s.Offset == mi.Offset; }).FirstOrDefault());
v.Instructions.Add(i);
}

Expand Down

0 comments on commit 2116ef7

Please sign in to comment.