Re-add cpu tracing

This commit is contained in:
gdkchan 2018-07-03 19:20:19 -03:00
parent c88e942362
commit 19f89abe69
4 changed files with 72 additions and 4 deletions

View file

@ -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<long, ATranslatedSub> CachedSubs;
public event EventHandler<ACpuTraceEventArgs> CpuTrace;
public bool EnableCpuTrace { get; set; }
public ATranslator()
{
CachedSubs = new ConcurrentDictionary<long, ATranslatedSub>();
@ -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);

View file

@ -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;
}
}
}

View file

@ -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;

View file

@ -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