示例#1
0
        public string OnMemoryExecute(LuaFunction luaf, uint address, string name = null)
        {
            try
            {
                if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable() &&
                    DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
                {
                    if (N64CoreTypeDynarec())
                    {
                        return(Guid.Empty.ToString());
                    }

                    var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
                    _luaFunctions.Add(nlf);

                    DebuggableCore.MemoryCallbacks.Add(
                        new MemoryCallback(MemoryCallbackType.Execute, "Lua Hook", nlf.Callback, address, null));
                    return(nlf.Guid.ToString());
                }
            }
            catch (NotImplementedException)
            {
                LogMemoryExecuteCallbacksNotImplemented();
                return(Guid.Empty.ToString());
            }

            LogMemoryExecuteCallbacksNotImplemented();
            return(Guid.Empty.ToString());
        }
示例#2
0
        public LuaTable GetRegisters()
        {
            var table = Lua.NewTable();

            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                foreach (var kvp in DebuggableCore.GetCpuFlagsAndRegisters())
                {
                    table[kvp.Key] = kvp.Value.Value;
                }
            }
            catch (NotImplementedException)
            {
                Log(string.Format(
                        "Error: {0} does not yet implement getregisters()",
                        Emulator.Attributes().CoreName));
            }

            return(table);
        }
        public string OnMemoryWrite(
            LuaFunction luaf,
            uint?address = null,
            [LuaArbitraryStringParam] string name = null,
            [LuaASCIIStringParam] string scope    = null)
        {
            try
            {
                if (DebuggableCore?.MemoryCallbacksAvailable() == true)
                {
                    if (!HasScope(scope))
                    {
                        LogScopeNotAvailable(scope);
                        return(Guid.Empty.ToString());
                    }

                    var nlf = _luaLibsImpl.CreateAndRegisterNamedFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentFile, name);
                    DebuggableCore.MemoryCallbacks.Add(
                        new MemoryCallback(ProcessScope(scope), MemoryCallbackType.Write, "Lua Hook", nlf.MemCallback, address, null));
                    return(nlf.Guid.ToString());
                }
            }
            catch (NotImplementedException)
            {
                LogMemoryCallbacksNotImplemented();
                return(Guid.Empty.ToString());
            }

            LogMemoryCallbacksNotImplemented();

            return(Guid.Empty.ToString());
        }
示例#4
0
        public string OnMemoryRead(LuaFunction luaf, uint?address = null, string name = null, string scope = null)
        {
            try
            {
                if (DebuggableCore?.MemoryCallbacksAvailable() == true)
                {
                    if (!HasScope(scope))
                    {
                        LogScopeNotAvailable(scope);
                        return(Guid.Empty.ToString());
                    }

                    var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentFile, name);
                    RegisteredFunctions.Add(nlf);
                    DebuggableCore.MemoryCallbacks.Add(
                        new MemoryCallback(ProcessScope(scope), MemoryCallbackType.Read, "Lua Hook", nlf.MemCallback, address, null));
                    return(nlf.Guid.ToString());
                }
            }
            catch (NotImplementedException)
            {
                LogMemoryCallbacksNotImplemented();
                return(Guid.Empty.ToString());
            }

            LogMemoryCallbacksNotImplemented();
            return(Guid.Empty.ToString());
        }
示例#5
0
        public string OnMemoryExecuteAny(LuaFunction luaf, string name = null, string scope = null)
        {
            try
            {
                if (DebuggableCore?.MemoryCallbacksAvailable() == true &&
                    DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
                {
                    if (!HasScope(scope))
                    {
                        LogScopeNotAvailable(scope);
                        return(Guid.Empty.ToString());
                    }

                    var nlf = new NamedLuaFunction(luaf, "OnMemoryExecuteAny", LogOutputCallback, CurrentFile, name);
                    RegisteredFunctions.Add(nlf);
                    DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(
                                                           ProcessScope(scope),
                                                           MemoryCallbackType.Execute,
                                                           "Lua Hook",
                                                           nlf.MemCallback,
                                                           null,
                                                           null
                                                           ));
                    return(nlf.Guid.ToString());
                }
                // fall through
            }
            catch (NotImplementedException)
            {
                // fall through
            }
            LogMemoryExecuteCallbacksNotImplemented();
            return(Guid.Empty.ToString());
        }
示例#6
0
        private string SetMemoryEvent(MemoryCallbackType type, string callback, uint address, uint bytes, string name, uint?checkAddress = null, uint checkValue = 0, string domain = "System Bus")
        {
            domain = NormalizeDomain(domain);
            try
            {
                if (DebuggableCore?.MemoryCallbacksAvailable() == true &&
                    (type != MemoryCallbackType.Execute || DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable))
                {
                    name = name ?? callback;

                    uint mask = 0;
                    for (var i = 0; i < bytes; i++)
                    {
                        mask |= (uint)(0xFF << (i * 8));
                    }

                    if (!HasDomain(domain))
                    {
                        throw new ApiError($"{Emulator.Attributes().CoreName} does not support memory callbacks on the domain {domain}");
                    }
                    HttpClient client = new HttpClient();
                    DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(
                                                           domain,
                                                           type,
                                                           name,
                                                           (uint address, uint value, uint flags) =>
                    {
                        if (checkAddress != null && ReadUnsignedByte((int)checkAddress, domain) == checkValue)
                        {
                            try
                            {
                                client.GetAsync(callback).Result.ToString();
                            }
                            catch { }
                        }
                    },
                                                           address,
                                                           mask
                                                           ));
                    return(name);
                }
                // fall through
            }
            catch (NotImplementedException) { }
            if (type == MemoryCallbackType.Execute)
            {
                throw new ApiError($"{Emulator.Attributes().CoreName} does not support memory execute callbacks.");
            }
            throw new ApiError($"{Emulator.Attributes().CoreName} does not support memory callbacks.");
        }
示例#7
0
        public void SetRegister(string register, int value)
        {
            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                DebuggableCore.SetCpuRegister(register, value);
            }
            catch (NotImplementedException)
            {
                Console.WriteLine($"Error: {Emulator.Attributes().CoreName} does not yet implement {nameof(IDebuggable.SetCpuRegister)}()");
            }
        }
示例#8
0
        public void SetRegister(string register, int value)
        {
            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                DebuggableCore.SetCpuRegister(register, value);
            }
            catch (NotImplementedException)
            {
                Log(string.Format(
                        "Error: {0} does not yet implement setregister()",
                        Emulator.Attributes().CoreName));
            }
        }
示例#9
0
            protected override void TraceFromCallback()
            {
                var  regs   = DebuggableCore.GetCpuFlagsAndRegisters();
                uint pc     = (uint)regs["M68K PC"].Value;
                var  length = 0;
                var  disasm = Disassembler.Disassemble(MemoryDomains.SystemBus, pc, out length);

                var traceInfo = new TraceInfo
                {
                    Disassembly = string.Format("{0:X6}:  {1}", pc, disasm)
                };

                var sb = new StringBuilder();

                foreach (var r in regs)
                {
                    if (r.Key.StartsWith("M68K"))                        // drop Z80 regs until it has its own debugger/tracer
                    {
                        if (r.Key != "M68K SP" && r.Key != "M68K ISP" && // copies of a7
                            r.Key != "M68K PC" &&                        // already present in every line start
                            r.Key != "M68K IR")                          // copy of last opcode, already shown in raw bytes
                        {
                            sb.Append(
                                string.Format("{0}:{1} ",
                                              r.Key.Replace("M68K", "").Trim(),
                                              r.Value.Value.ToHexString(r.Value.BitSize / 4)));
                        }
                    }
                }
                var sr = regs["M68K SR"].Value;

                sb.Append(
                    string.Format("{0}{1}{2}{3}{4}",
                                  (sr & 16) > 0 ? "X" : "x",
                                  (sr & 8) > 0 ? "N" : "n",
                                  (sr & 4) > 0 ? "Z" : "z",
                                  (sr & 2) > 0 ? "V" : "v",
                                  (sr & 1) > 0 ? "C" : "c"));

                traceInfo.RegisterInfo = sb.ToString().Trim();

                Put(traceInfo);
            }
示例#10
0
        public int GetRegister(string name)
        {
            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                var registers = DebuggableCore.GetCpuFlagsAndRegisters();
                return(registers.ContainsKey(name)
                                        ? (int)registers[name].Value
                                        : 0);
            }
            catch (NotImplementedException)
            {
                Log($"Error: {Emulator.Attributes().CoreName} does not yet implement getregister()");
                return(0);
            }
        }
示例#11
0
        private string SetMemoryEvent(MemoryCallbackType type, string callback, uint address, uint bytes, string name, int checkAddr = -1, uint checkValue = 0)
        {
            try
            {
                if (
                    DebuggableCore != null &&
                    DebuggableCore.MemoryCallbacksAvailable() &&
                    (type != MemoryCallbackType.Execute || DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
                    )
                {
                    name = name ?? callback;
                    uint mask = 0;
                    for (var i = 0; i < bytes; i++)
                    {
                        mask |= (uint)(0xFF << (i * 8));
                    }

                    HttpClient client = new HttpClient();
                    DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(type, name, () =>
                    {
                        if (checkAddr < 0 || ReadUnsignedByte(checkAddr) == checkValue)
                        {
                            try
                            {
                                client.GetAsync(callback).Result.ToString();
                            }
                            catch { }
                        }
                    }, address, mask));
                    return(name);
                }
            }
            catch (NotImplementedException) { }
            if (type == MemoryCallbackType.Execute)
            {
                throw new ApiError($"{Emulator.Attributes().CoreName} does not support memory execute callbacks.");
            }
            throw new ApiError($"{Emulator.Attributes().CoreName} does not support memory callbacks.");
        }
示例#12
0
            protected override void TraceFromCallback(uint addr, uint value, uint flags)
            {
                var  regs   = DebuggableCore.GetCpuFlagsAndRegisters();
                uint pc     = (uint)regs["M68K PC"].Value;
                var  disasm = Disassembler.Disassemble(MemoryDomains.SystemBus, pc & 0xFFFFFF, out _);

                var traceInfo = new TraceInfo
                {
                    Disassembly = $"{pc:X6}:  {disasm}".PadRight(50)
                };

                var sb = new StringBuilder();

                foreach (var r in regs)
                {
                    if (r.Key.StartsWith("M68K"))                        // drop Z80 regs until it has its own debugger/tracer
                    {
                        if (r.Key != "M68K SP" && r.Key != "M68K ISP" && // copies of a7
                            r.Key != "M68K PC" &&                        // already present in every line start
                            r.Key != "M68K IR")                          // copy of last opcode, already shown in raw bytes
                        {
                            sb.Append($"{r.Key.Replace("M68K", "").Trim()}:{r.Value.Value.ToHexString(r.Value.BitSize / 4)} ");
                        }
                    }
                }
                var sr = regs["M68K SR"].Value;

                sb.Append(string.Concat(
                              (sr & 16) > 0 ? "X" : "x",
                              (sr & 8) > 0 ? "N" : "n",
                              (sr & 4) > 0 ? "Z" : "z",
                              (sr & 2) > 0 ? "V" : "v",
                              (sr & 1) > 0 ? "C" : "c"));

                traceInfo.RegisterInfo = sb.ToString().Trim();

                Put(traceInfo);
            }
        public string OnMemoryRead(LuaFunction luaf, uint?address = null, string name = null)
        {
            try
            {
                if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable())
                {
                    var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
                    _luaFunctions.Add(nlf);

                    DebuggableCore.MemoryCallbacks.Add(
                        new MemoryCallback(MemoryCallbackType.Read, "Lua Hook", nlf.Callback, address));
                    return(nlf.Guid.ToString());
                }
            }
            catch (NotImplementedException)
            {
                LogMemoryCallbacksNotImplemented();
                return(Guid.Empty.ToString());
            }

            LogMemoryCallbacksNotImplemented();
            return(Guid.Empty.ToString());
        }
示例#14
0
        public Dictionary <string, ulong> GetRegisters()
        {
            var table = new Dictionary <string, ulong>();

            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                foreach (var kvp in DebuggableCore.GetCpuFlagsAndRegisters())
                {
                    table[kvp.Key] = kvp.Value.Value;
                }
            }
            catch (NotImplementedException)
            {
                Console.WriteLine($"Error: {Emulator.Attributes().CoreName} does not yet implement {nameof(IDebuggable.GetCpuFlagsAndRegisters)}()");
            }

            return(table);
        }
示例#15
0
        public ulong?GetRegister(string name)
        {
            try
            {
                if (DebuggableCore == null)
                {
                    throw new NotImplementedException();
                }

                var   registers = DebuggableCore.GetCpuFlagsAndRegisters();
                ulong?value     = null;
                if (registers.ContainsKey(name))
                {
                    value = registers[name].Value;
                }
                return(value);
            }
            catch (NotImplementedException)
            {
                Console.WriteLine($"Error: {Emulator.Attributes().CoreName} does not yet implement {nameof(IDebuggable.GetCpuFlagsAndRegisters)}()");
                return(null);
            }
        }
示例#16
0
        public string OnMemoryExecute(LuaFunction luaf, uint address, string name = null, string domain = null)
        {
            try
            {
                if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable() &&
                    DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
                {
                    if (N64CoreTypeDynarec())
                    {
                        return(Guid.Empty.ToString());
                    }

                    var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
                    _luaFunctions.Add(nlf);

                    if (string.IsNullOrWhiteSpace(domain))
                    {
                        if (Domains != null && Domains.HasSystemBus)
                        {
                            domain = Domains.SystemBus.Name;
                        }
                    }

                    DebuggableCore.MemoryCallbacks.Add(
                        new MemoryCallback(domain, MemoryCallbackType.Execute, "Lua Hook", nlf.MemCallback, address, null));
                    return(nlf.Guid.ToString());
                }
            }
            catch (NotImplementedException)
            {
                LogMemoryExecuteCallbacksNotImplemented();
                return(Guid.Empty.ToString());
            }

            LogMemoryExecuteCallbacksNotImplemented();
            return(Guid.Empty.ToString());
        }
示例#17
0
 public LuaTable AvailableScopes()
 {
     return(DebuggableCore?.MemoryCallbacksAvailable() == true
                         ? _th.ListToTable(DebuggableCore.MemoryCallbacks.AvailableScopes, indexFrom : 0)
                         : _th.CreateTable());
 }
示例#18
0
 public LuaTable AvailableScopes()
 {
     return(DebuggableCore?.MemoryCallbacksAvailable() == true
                         ? DebuggableCore.MemoryCallbacks.AvailableScopes.ToLuaTable(Lua)
                         : Lua.NewTable());
 }