Show previous instruction for breakpoint in debugger

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
User avatar
Ast A. Moore
Manic Miner
Posts: 626
Joined: Mon Nov 13, 2017 3:16 pm

Re: Show previous instruction for breakpoint in debugger

Post by Ast A. Moore » Mon Jul 30, 2018 9:22 pm

AndyC wrote:
Mon Jul 30, 2018 7:46 pm
Ast A. Moore wrote:
Mon Jul 30, 2018 2:01 pm
If, however, you’re debugging your own code, you’re likely to know exactly how it’s supposed to branch out anyway.
Well, you probably know how it's supposed to branch out, but if it were working you wouldn't need a debugger. :lol: It's quite easy to POP a little too much off the stack, for example, and end up accidentally RETurning to the wrong piece of code in an unexpected state. A debugger which helps you spot that would probably be super handy.
Oh, I’ve been burned by that exact situation on more occasions I’m willing to admit. :D But my observation was more general in nature—debugging your own code is immensely easier than someone else’s.

P.S. Don’t underestimate the power of RZX recordings. They saved my butt so many times. Particularly indispensable for tracking down intermittent bugs.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Manic Miner
Posts: 274
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Show previous instruction for breakpoint in debugger

Post by Seven.FFF » Tue Jul 31, 2018 2:19 am

The way I debug this scenario in Zeus is to write a data breakpoint expression that breaks on the jump target address, which when breaking also prints the frame count (since emulation start) and tstate count (since the start of frame)*.

Knowing that jumps and calls are usually 10 or 17 Ts, I subtract one of these numbers from my printed numbers, and set another breakpoint to break when these values are hit. If they are, voilà.

If not, I try with 17, 12, 6, 4, whatever the other possible instructions are.

Zeus also has a feature similar to RZX recording, except it just records keystrokes and the Tstates they occurred. Unlike a RZX, playback is still possible after the code has been modified, because it’s only an event snapshot rather a code+event snapshot. I often use this recording and playback in conjunction with data breakpoints, particularly when the conditions to reproduce the target state are complicated.

Sounds fiddly, but really only takes a few minutes in practice.

Before I do stuff like this, of course, I also search memory for the two bytes of the jump target address! This will find any obvious JP <Address> instructions.

*In Zeus there is also a running Tstate count (since emulation start) which combines the two, and is even easier to reference.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32

Posts: 18
Joined: Sat Jan 06, 2018 6:47 am
Location: Sweden

Re: Show previous instruction for breakpoint in debugger

Post by Magnus » Tue Jul 31, 2018 7:53 am

Ralf wrote:
Sun Jul 29, 2018 7:18 pm
And it's a first instruction of some block of code. So I may suspect some JP or CALL was before it. But how can I find it without crazy guessing?
Does any emulators stores adresses of executed commands in some log so I could check the log and find a few instructions before my breakpoint?
Thanks for any help!
Hi Ralf,

My emulator actually "stops" on the instruction before the breakpoint (I use quotes here, because of course the emulator reaches the breakpoint). This is not really by design, but a side effect of how my debugger works. It is quite practical though.

0 x
My Spectrum emulator project:

Post Reply