Beispiel #1
0
        public static List <MonoIlOffset> GetIlOffsets(MonoJitInfo jitInfo)
        {
            CheckInput(jitInfo);

            uint codeSize = (uint)jitInfo.CodeSize;
            var  list     = new List <MonoIlOffset>();

            int lastOffset = -1;
            var ptr        = jitInfo.MonoMethod.Pointer;
            var domain     = Mono.Domain;

            // TODO: optimize this to use a binary search
            for (uint i = 0; i != codeSize; i++)
            {
                int result = Debug_GetIlOffsetFromNativeOffset(ptr, domain, i);
                if (result != lastOffset)
                {
                    lastOffset = result;
                    list.Add(new MonoIlOffset {
                        IlOffset     = (uint)result,
                        NativeOffset = i,
                    });
                }
            }

            list.Sort((lhs, rhs) => lhs.NativeOffset.CompareTo(rhs.NativeOffset));
            return(list);
        }
Beispiel #2
0
 static void CheckInput(MonoJitInfo jitInfo)
 {
     if (!jitInfo.MonoMethod.IsValid())
     {
         throw new InvalidOperationException($"The mono method on the {nameof(jitInfo)} must be vald!");
     }
     if (!IsEnabled)
     {
         throw new InvalidOperationException($"Mono debug must be enabled!");
     }
 }
Beispiel #3
0
        private IEnumerable <SharpDisasm.Instruction> GetInstructions(MonoJitInfo jit)
        {
            Disassembler.Translator.IncludeBinary  = true;
            Disassembler.Translator.IncludeAddress = true;
            ArchitectureMode mode = ArchitectureMode.x86_64;

            if (IntPtr.Size == 4)
            {
                mode = ArchitectureMode.x86_32;
            }
            var disasm = new Disassembler(jit.CodeStart, jit.CodeSize, mode, (ulong)jit.CodeStart, true);

            return(disasm.Disassemble());
        }
Beispiel #4
0
        public static List <MonoSourceLocation> GetSourceLocation(MonoJitInfo jitInfo, IEnumerable <uint> ilOffsets)
        {
            CheckInput(jitInfo);
            var ptr    = jitInfo.MonoMethod.Pointer;
            var domain = Mono.Domain;

            var sourceLocations = new List <MonoSourceLocation>();

            foreach (var offset in ilOffsets)
            {
                IntPtr sourceLoc = IntPtr.Zero;
                try {
                    sourceLoc = Debug_GetSourceLocation(ptr, offset, domain);
                    if (sourceLoc == IntPtr.Zero)
                    {
                        sourceLocations.Add(new MonoSourceLocation());
                        continue;
                    }
                    unsafe {
                        var sourceLocPtr = (MonoSourceLocation_Internal *)sourceLoc.ToPointer();
                        var output       = new MonoSourceLocation {
                            Column   = sourceLocPtr->Column,
                            Row      = sourceLocPtr->Row,
                            IlOffset = sourceLocPtr->IlOffset,
                            File     = Marshal.PtrToStringAnsi(sourceLocPtr->SourceFile)
                        };
                        sourceLocations.Add(output);
                    }
                }
                finally {
                    if (sourceLoc != IntPtr.Zero)
                    {
                        Debug_FreeSourceLocation(sourceLoc);
                    }
                }
            }
            return(sourceLocations);
        }
Beispiel #5
0
 public static int GetIlOffsetFromNativeOffset(MonoJitInfo jitInfo, uint nativeOffset)
 {
     CheckInput(jitInfo);
     return(Debug_GetIlOffsetFromNativeOffset(jitInfo.MonoMethod.Pointer, Mono.Domain, nativeOffset));
 }