Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indentation to tracelogs #4084

Open
vadosnaprimer opened this issue Oct 9, 2024 · 3 comments
Open

Add indentation to tracelogs #4084

vadosnaprimer opened this issue Oct 9, 2024 · 3 comments
Labels
App: EmuHawk Relating to EmuHawk frontend Enhancement For feature requests or possible improvements

Comments

@vadosnaprimer
Copy link
Contributor

vadosnaprimer commented Oct 9, 2024

FCEUX and latest Gens have this, and it's super useful for quickly determining subroutines (and skipping over them as needed). A core can determine indentation based on stack size, and pass the number to the tracer, which would then pad each line by that size.

Example code for gpgx (to show how it'd look):

protected override void TraceFromCallback(uint addr, uint value, uint flags)
{
	var regs = DebuggableCore.GetCpuFlagsAndRegisters();
	uint pc = (uint)regs["M68K PC"].Value & 0xFFFFFF;
	var disasm = Disassembler.Disassemble(MemoryDomains.SystemBus, pc, out _);

	var stackBase = MemoryDomains.SystemBus.PeekUint(0, true);
	var stackPointer = regs["M68K A7"].Value;
	var stackSize = (int)((stackBase - stackPointer) / 4) & 63;

	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"));

	this.Put(new(disassembly: $"{new string(' ', stackSize)}{pc:X6}:  {disasm}".PadRight(50+stackSize), registerInfo: sb.ToString().Trim()));
}

изображение

@YoshiRulz YoshiRulz added Enhancement For feature requests or possible improvements App: EmuHawk Relating to EmuHawk frontend labels Oct 9, 2024
@RetroEdit
Copy link
Contributor

RetroEdit commented Oct 11, 2024

If implemented, it might be worth making it optional. Column-aligned is easier to read sometimes. To be fair it's not that important because unindenting is probably a pretty easy operation with a simple regex replace like '^ +' to ' ' (in a text editor or otherwise).

@CasualPokePlayer
Copy link
Member

CasualPokePlayer commented Oct 11, 2024

How well does it handle say the stack pointer going off the rails due to some crash, or possibly tricks manipulating the stack pointer (e.g. on the NES and GB (and probably other systems) a "popslide" technique can be used to quickly copy video memory, typically setting the stack pointer to ROM and popping off the ""stack"" to read memory as fast as possible, then writing the results to VRAM; setting the stack pointer to ROM might also be used in some ACE exploits as a way to redirect execution to more controllable memory).

@vadosnaprimer
Copy link
Contributor Author

vadosnaprimer commented Oct 11, 2024

If implemented, it might be worth making it optional.

Forgot to mention, yeah.

Column-aligned is easier to read sometimes. To be fair it's not that important because unindenting is probably a pretty easy operation with a simple regex replace like '^ +' to ' ' (in a text editor or otherwise).

I'd expect many text editors to be able to remove leading spaces.

How well does it handle say the stack pointer going off the rails due to some crash

My initial code for a Gens mod didn't handle this in any way, but r57shell's version simply does &63 with the indent size, I think it's a fair solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App: EmuHawk Relating to EmuHawk frontend Enhancement For feature requests or possible improvements
Projects
None yet
Development

No branches or pull requests

4 participants