Show previous instruction for breakpoint in debugger

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
Ralf
Manic Miner
Posts: 779
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Show previous instruction for breakpoint in debugger

Post by Ralf » Sun Jul 29, 2018 7:18 pm

Maybe a basic question but I genuinely don't know the answer.

So I set a breakpoint in debugger and run the program. At some moment It hits the breakpoint and enters the debugger.

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!
0 x

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 » Sun Jul 29, 2018 7:44 pm

Ralf wrote:
Sun Jul 29, 2018 7:18 pm
But how can I find it without crazy guessing?
Look at the stack. If there was a call, it’ll hold the address of the instruction after the call.
Ralf wrote:
Sun Jul 29, 2018 7:18 pm
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?
Yes, SpecEmu does two things: (1) it shows the previous instruction right in the debugger, and (2) optionally allows you create runtime logs. Beware of the logs, though; they tend to get out of hand size-wise pretty fast.
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
Stefan
Berk
Posts: 26
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: Show previous instruction for breakpoint in debugger

Post by Stefan » Sun Jul 29, 2018 9:52 pm

Ralf wrote:
Sun Jul 29, 2018 7:18 pm
So I set a breakpoint in debugger and run the program. At some moment It hits the breakpoint and enters the debugger.

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?
I've never used it, but the rewind function of TommyGun sounds very promising.
0 x

User avatar
djnzx48
Microbot
Posts: 154
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Show previous instruction for breakpoint in debugger

Post by djnzx48 » Mon Jul 30, 2018 8:59 am

I just came across this disassembler called z80dismblr which can generate some sort of control flow graph showing all the calls and jumps. It's probably overkill for this purpose but it might still be helpful.
0 x

Ralf
Manic Miner
Posts: 779
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Show previous instruction for breakpoint in debugger

Post by Ralf » Mon Jul 30, 2018 9:39 am

Thanks!

It'll try different options, beginning with Spec Emu.
As for Tommy Gun, I have a general bad experience with it so it'll be my last resort.
Look at the stack. If there was a call, it’ll hold the address of the instruction after the call.
Yes, that would work in SOME cases.
But...
In general case we don't know if the instruction in breakpoint was reached by call or by jump. If it was reached by jump then stack will
show some last return point but it won't be my previous instruction.
And sometimes programs modify stack address or stack content. In such case the value at top of the stack will be totally meaningless.
0 x

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 11:22 am

Ralf wrote:
Mon Jul 30, 2018 9:39 am
It'll try different options, beginning with Spec Emu.
I think it has the most powerful debugger out there. I use it on a regular basis, even though it doesn’t run natively on OS X. Fuse just doesn’t cut it sometimes.
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.

AndyC
Microbot
Posts: 161
Joined: Mon Nov 13, 2017 5:12 am

Re: Show previous instruction for breakpoint in debugger

Post by AndyC » Mon Jul 30, 2018 12:52 pm

Ralf wrote:
Mon Jul 30, 2018 9:39 am
Yes, that would work in SOME cases.
But...
In general case we don't know if the instruction in breakpoint was reached by call or by jump. If it was reached by jump then stack will
show some last return point but it won't be my previous instruction.
And sometimes programs modify stack address or stack content. In such case the value at top of the stack will be totally meaningless.
Indeed. Any post-facto inspection can be fooled by abusive code. What would possibly be more useful is a breakpoint type that stops execution if the next value of PC would execute the breakpoint line.
0 x

Ralf
Manic Miner
Posts: 779
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Show previous instruction for breakpoint in debugger

Post by Ralf » Mon Jul 30, 2018 1:18 pm

What would possibly be more useful is a breakpoint type that stops execution if the next value of PC would execute the breakpoint line.
Yes, it would solve my problem.

Actually ZX Spin has quite advanced breakpoints. You may set them not on reaching some instruction but meeting some condition like "A reqister equal to 1" or "memory cell 30000 content equal to 100" and so on. I'll try to experiment what can be done with it.

But I suppose if I make a condition "PC=30000" it will break into debugger at 30000, not at instruction just before 30000 :(
0 x

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 2:01 pm

Ralf wrote:
Mon Jul 30, 2018 1:18 pm
Actually ZX Spin has quite advanced breakpoints. You may set them not on reaching some instruction but meeting some condition like "A reqister equal to 1" or "memory cell 30000 content equal to 100" and so on. I'll try to experiment what can be done with it.
Most debuggers can do that, including Fuse, by the way. There are even more sophisticated options available.
Ralf wrote:
Mon Jul 30, 2018 1:18 pm
But I suppose if I make a condition "PC=30000" it will break into debugger at 30000, not at instruction just before 30000 :(
Like I said, SpecEmu almost always displays the previous instruction address when you break into the debugger, even if you do it at a random point (without setting a breakpoint). If, however, you’re debugging your own code, you’re likely to know exactly how it’s supposed to branch out anyway.
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.

AndyC
Microbot
Posts: 161
Joined: Mon Nov 13, 2017 5:12 am

Re: Show previous instruction for breakpoint in debugger

Post by AndyC » 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.
0 x

Post Reply