Re: [cc65] brk_handler

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2000-02-28 00:01:57


				 
> I just noticed that the handler routine installed by set_brk, remembers
> the PC as pointing to the BRK opcode.
> I this intentional? I would have expected it to point after
> the BRK command, so returning from user handler will
> continue the program.

This is intentional. IMHO it is not the job of the breakpoint handler to
decide what to do in this situation, since it cannot know, for which purpose
the BRK was inserted.

For example, the debugger module that comes with cc65 will insert temporary
breakpoints when single stepping through the code. These breakpoints are
invisible for the user and replaced by the original instruction when the
debugger is re-entered. Since the break handler does not know the length of
the original opcode, skipping would always be wrong in this situation. The
same is true for user inserted breakpoints or when the CPU starts executing
random bytes (because of a bad pointer or similar): The low level handler has
no knowledge about the situation and cannot handle this correctly.

On the other side, I have to admit that it does not really matter which
behaviour the handler has, since the debugger can always correct it (provided
that the handler does not act at random). The current design was choosen,
because I wrote the break handler for the debugger module, and it uses BRK for
breakpoints (both, user and temporary), so having the PC point to the BRK
instruction was easier for the high level code. Apart from that, it seemed
more logical to me (it stresses the usage of BRK as a breakpoint), even if it
does not mirror the exact behaviour of the CPU.

But you are right, this behaviour is somewhat confusing, since it is not what
a low level programmer would expect. I did not think about this when writing
the break handler code. It should certainly be documented somewhere.

> Or should the user handler fiddle with _brk_pc?

Yes. Just set it to whatever address you want before returning. This is also
true for the registers or flags. If you change the values, the program will
continue with the changed values.

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:35 CET