[hatari-devel] Catching trap exit?
Nicolas Pomarède
npomarede at corp.free.fr
Tue Oct 19 22:36:28 CEST 2010
Le 19/10/2010 22:07, Eero Tamminen a écrit :
>> - you can have a simple step instruction that breaks each time PC is
>> changed
>
> Do you mean shortcut for:
> b pc ! "pc" :once
> or for:
> c 1
> debugger command?
this should be for the case where you execute one opcode at (pc) then
stop, so I think it's more for "c 1"
Your 1st example would not work for the following code :
move #1567,d0
.loop dbf d0,loop
When pc = .loop, you will execute 1568 dbf, but pc won't change (from
the point of view of the debugger, it will change at the 68000 level),
so I think your 1set example will only break after the last dbf ?
I think the correst "step" command should be the one that breaks 1568 times.
>> - you can have a more elaborate step instruction that breaks after
>> opcodes that changes PC by jumping elsewhere. This is handy to execute a
>> sub routine / trap handler as a whole, without going step by step in the
>> routine.
>
> Is the longest such instruction shorter than shortest such instruction?
?? Sorry, I don't understand what is "such instruction" ?
>
> If yes, then a shortcut for this is enough:
> b pc> "pc"&& pc< "pc<maxlen + 1>" :once
what is maxlen ? If it's the maximum size of a branch instruction, then
it won't work the way you propose.
jsr $123456.l will take 6 bytes
trap / bsr.s will take 2 bytes
so if you encounter a bsr.s and add a breakpoint at pc+6, the following
code will fool your breakpoint :
bsr.s routine ; 2 bytes
rts ; 2 bytes
routine
nop ; 2 bytes
...
rts
-> this will break when reaching the nop, because it's at pc+4 (relative
to the bsr.s)
The only safe way is to know how many byte take bsr.s/trap/jsr.l and at
a breakpoint at pc+opcode_length.
>
> I quickly looked at these values but they didn't seem to match the next
> instruction address so I guess I was doing something wrong. How you
> would get that value in Hatari C-code?
Have a look at m68k_do_rts in cpuemu.h :
m68k_setpc(get_long(m68k_areg(regs, 7)));
so get_long(m68k_areg(regs, 7)) is what you need to return from a non
exception branch (for exceptions, return pc is at 2(a7), so
get_long(m68k_areg(regs, 7)+2) will do the trick)
Nicolas
More information about the hatari-devel
mailing list