namespace Pdb2Mdb {
- class Converter {
+ public class Converter {
MonoSymbolWriter mdb;
Dictionary<string, SourceFile> files = new Dictionary<string, SourceFile> ();
- public Converter (MonoSymbolWriter mdb)
+ public static void Convert (string filename)
+ {
+ var asm = AssemblyDefinition.ReadAssembly (filename);
+
+ var pdb = asm.Name.Name + ".pdb";
+ pdb = Path.Combine (Path.GetDirectoryName (filename), pdb);
+
+ using (var stream = File.OpenRead (pdb)) {
+ var funcs = PdbFile.LoadFunctions (stream, true);
+ Converter.Convert (asm, funcs, new MonoSymbolWriter (filename));
+ }
+ }
+
+ internal Converter (MonoSymbolWriter mdb)
{
this.mdb = mdb;
}
- public static void Convert (AssemblyDefinition assembly, IEnumerable<PdbFunction> functions, MonoSymbolWriter mdb)
+ internal static void Convert (AssemblyDefinition assembly, IEnumerable<PdbFunction> functions, MonoSymbolWriter mdb)
{
var converter = new Converter (mdb);
void ConvertFunction (PdbFunction function)
{
+ if (function.lines == null)
+ return;
+
var method = new SourceMethod { Name = function.name, Token = (int) function.token };
var file = GetSourceFile (mdb, function);
void ConvertSequencePoints (PdbFunction function, SourceFile file, SourceMethodBuilder builder)
{
- if (function.lines == null)
- return;
-
- foreach (var line in function.lines.SelectMany (lines => lines.lines))
+ int last_line = 0;
+ foreach (var line in function.lines.SelectMany (lines => lines.lines)) {
+ // 0xfeefee is an MS convention, we can't pass it into mdb files, so we use the last non-hidden line
+ bool is_hidden = line.lineBegin == 0xfeefee;
builder.MarkSequencePoint (
(int) line.offset,
file.CompilationUnit.SourceFile,
- (int) line.lineBegin,
- (int) line.colBegin, line.lineBegin == 0xfeefee);
+ is_hidden ? last_line : (int) line.lineBegin,
+ (int) line.colBegin, is_hidden ? -1 : (int)line.lineEnd, is_hidden ? -1 : (int)line.colEnd,
+ is_hidden);
+ if (!is_hidden)
+ last_line = (int) line.lineBegin;
+ }
}
void ConvertVariables (PdbFunction function)
void ConvertScope (PdbScope scope)
{
- ConvertSlots (scope.slots);
+ ConvertSlots (scope, scope.slots);
foreach (var s in scope.scopes)
ConvertScope (s);
}
- void ConvertSlots (IEnumerable<PdbSlot> slots)
+ void ConvertSlots (PdbScope scope, IEnumerable<PdbSlot> slots)
{
- foreach (var slot in slots)
+ int scope_idx = mdb.OpenScope ((int)scope.address);
+ foreach (var slot in slots) {
mdb.DefineLocalVariable ((int) slot.slot, slot.name);
+ mdb.DefineScopeVariable (scope_idx, (int)slot.slot);
+ }
+ mdb.CloseScope ((int)(scope.address + scope.length));
}
SourceFile GetSourceFile (MonoSymbolWriter mdb, PdbFunction function)
var assembly = AssemblyDefinition.ReadAssembly (asm);
var pdb = assembly.Name.Name + ".pdb";
+ pdb = Path.Combine (Path.GetDirectoryName (asm), pdb);
if (!File.Exists (pdb))
Usage ();