gdb: Support precise tracking of PC value when GDB Stub is enabled

This commit is contained in:
Coxxs 2025-06-23 07:00:48 +08:00
parent 009d319bc2
commit 838296ccb6
3 changed files with 43 additions and 0 deletions

View file

@ -164,11 +164,21 @@ namespace ARMeilleure.State
internal void OnBreak(ulong address, int imm)
{
if (Optimizations.EnableDebugging)
{
DebugPc = Pc;
}
_breakCallback?.Invoke(this, address, imm);
}
internal void OnSupervisorCall(ulong address, int imm)
{
if (Optimizations.EnableDebugging)
{
DebugPc = Pc;
}
_supervisorCallback?.Invoke(this, address, imm);
}

View file

@ -22,6 +22,11 @@ namespace ARMeilleure.State
public ulong ExclusiveValueHigh;
public int Running;
public long Tpidr2El0;
/// <summary>
/// This is only set when Optimizations.EnableDebugging is true.
/// </summary>
public ulong CurrentPc;
}
private static NativeCtxStorage _dummyStorage = new();
@ -39,6 +44,11 @@ namespace ARMeilleure.State
public ulong GetPc()
{
if (Optimizations.EnableDebugging)
{
return GetStorage().CurrentPc;
}
// TODO: More precise tracking of PC value.
return GetStorage().DispatchAddress;
}
@ -268,6 +278,11 @@ namespace ARMeilleure.State
return StorageOffset(ref _dummyStorage, ref _dummyStorage.Running);
}
public static int GetCurrentPcOffset()
{
return StorageOffset(ref _dummyStorage, ref _dummyStorage.CurrentPc);
}
private static int StorageOffset<T>(ref NativeCtxStorage storage, ref T target)
{
return (int)Unsafe.ByteOffset(ref Unsafe.As<NativeCtxStorage, T>(ref storage), ref target);

View file

@ -388,6 +388,11 @@ namespace ARMeilleure.Translation
// Return to managed rather than tail call.
bool useReturns = Optimizations.EnableDebugging;
if (Optimizations.EnableDebugging)
{
EmitPcUpdate(context, block.Address);
}
InstEmitFlowHelper.EmitVirtualJump(context, Const(block.Address), isReturn: useReturns);
}
else
@ -410,6 +415,11 @@ namespace ARMeilleure.Translation
}
}
if (Optimizations.EnableDebugging)
{
EmitPcUpdate(context, opCode.Address);
}
Operand lblPredicateSkip = default;
if (context.IsInIfThenBlock && context.CurrentIfThenBlockCond != Condition.Al)
@ -506,6 +516,14 @@ namespace ARMeilleure.Translation
context.MarkLabel(lblExit);
}
internal static void EmitPcUpdate(EmitterContext context, ulong address)
{
long currentPcOffs = NativeContext.GetCurrentPcOffset();
Operand currentPcAddr = context.Add(context.LoadArgument(OperandType.I64, 0), Const(currentPcOffs));
context.Store(currentPcAddr, Const(address));
}
public void InvalidateJitCacheRegion(ulong address, ulong size)
{
ulong[] overlapAddresses = [];