diff --git a/ChocolArm64/ATranslator.cs b/ChocolArm64/ATranslator.cs index a51d88496..3cc0318c0 100644 --- a/ChocolArm64/ATranslator.cs +++ b/ChocolArm64/ATranslator.cs @@ -1,8 +1,10 @@ using ChocolArm64.Decoder; +using ChocolArm64.Events; using ChocolArm64.Instruction; using ChocolArm64.Memory; using ChocolArm64.State; using ChocolArm64.Translation; +using System; using System.Collections.Concurrent; using System.Reflection.Emit; @@ -12,6 +14,10 @@ namespace ChocolArm64 { private ConcurrentDictionary CachedSubs; + public event EventHandler CpuTrace; + + public bool EnableCpuTrace { get; set; } + public ATranslator() { CachedSubs = new ConcurrentDictionary(); @@ -50,6 +56,11 @@ namespace ChocolArm64 { do { + if (EnableCpuTrace) + { + CpuTrace?.Invoke(this, new ACpuTraceEventArgs(Position)); + } + if (!CachedSubs.TryGetValue(Position, out ATranslatedSub Sub)) { Sub = TranslateTier0(State, Memory, Position); diff --git a/ChocolArm64/Events/ACpuTraceEventArgs.cs b/ChocolArm64/Events/ACpuTraceEventArgs.cs new file mode 100644 index 000000000..0284f4eeb --- /dev/null +++ b/ChocolArm64/Events/ACpuTraceEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace ChocolArm64.Events +{ + public class ACpuTraceEventArgs : EventArgs + { + public long Position { get; private set; } + + public ACpuTraceEventArgs(long Position) + { + this.Position = Position; + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/OsHle/Process.cs b/Ryujinx.HLE/OsHle/Process.cs index f106a700d..555d630fd 100644 --- a/Ryujinx.HLE/OsHle/Process.cs +++ b/Ryujinx.HLE/OsHle/Process.cs @@ -197,7 +197,7 @@ namespace Ryujinx.HLE.OsHle throw new ObjectDisposedException(nameof(Process)); } - AThread CpuThread = new AThread(new ATranslator(), Memory, EntryPoint); + AThread CpuThread = new AThread(GetTranslator(), Memory, EntryPoint); KThread Thread = new KThread(CpuThread, this, ProcessorId, Priority); @@ -239,6 +239,49 @@ namespace Ryujinx.HLE.OsHle throw new UndefinedInstructionException(e.Position, e.RawOpCode); } + public void EnableCpuTracing() + { + Translator.EnableCpuTrace = true; + } + + public void DisableCpuTracing() + { + Translator.EnableCpuTrace = false; + } + + private void CpuTraceHandler(object sender, ACpuTraceEventArgs e) + { + Executable Exe = GetExecutable(e.Position); + + if (Exe == null) + { + return; + } + + if (!TryGetSubName(Exe, e.Position, out string SubName)) + { + SubName = string.Empty; + } + + long Offset = e.Position - Exe.ImageBase; + + string ExeNameWithAddr = $"{Exe.Name}:0x{Offset:x8}"; + + Ns.Log.PrintDebug(LogClass.Cpu, ExeNameWithAddr + " " + SubName); + } + + private ATranslator GetTranslator() + { + if (Translator == null) + { + Translator = new ATranslator(); + + Translator.CpuTrace += CpuTraceHandler; + } + + return Translator; + } + public void PrintStackTrace(AThreadState ThreadState) { StringBuilder Trace = new StringBuilder(); @@ -265,9 +308,9 @@ namespace Ryujinx.HLE.OsHle long Offset = Position - Exe.ImageBase; - string ExeNameWithAddr = $"{Exe.Name}:{Offset:x8}"; + string ExeNameWithAddr = $"{Exe.Name}:0x{Offset:x8}"; - Trace.AppendLine(" " + SubName + " (" + ExeNameWithAddr + ")"); + Trace.AppendLine(" " + ExeNameWithAddr + " " + SubName); } long FramePointer = (long)ThreadState.X29; diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index 59f7f859e..d4aaf0fea 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -2,7 +2,7 @@ Enable_Memory_Checks = false #Enable print debug logs -Logging_Enable_Debug = false +Logging_Enable_Debug = true #Enable print stubbed calls logs Logging_Enable_Stub = true