Permalink
Browse files

Fixes for missing debugging line information--call instructions conta…

…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 2116ef782745016eebbbfbff1f9d27fcfdd09bd2
Showing with 878 additions and 281 deletions.
  1. +11 −4 Campy.Compiler/cfg.cs
  2. +3 −5 Campy.Compiler/importer.cs
  3. +503 −262 Campy.Compiler/inst.cs
  4. +318 −5 ConsoleApp4/Program.cs
  5. +43 −5 Tests/EvenOddSort/UnitTest1.cs
View
@@ -1,4 +1,5 @@
using Swigged.LLVM;
using Mono.Collections.Generic;
using Swigged.LLVM;
namespace Campy.Compiler
{
@@ -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);
}
@@ -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);
}
Oops, something went wrong.

0 comments on commit 2116ef7

Please sign in to comment.