mirror of
https://github.com/irmen/prog8.git
synced 2025-04-05 18:38:05 +00:00
vm: add property for custom breakpoint handler
This commit is contained in:
parent
002006517a
commit
a04839dd6b
codeGenCpu6502/src/prog8/codegen/cpu6502
docs/source
virtualmachine/src/prog8/vm
@ -124,7 +124,7 @@ internal class AssemblyProgram(
|
||||
breakpoints.add("break \$" + match.groupValues[1])
|
||||
}
|
||||
val num = breakpoints.size
|
||||
breakpoints.add(0, "; vice monitor breakpoint list now follows")
|
||||
breakpoints.add(0, "; breakpoint list now follows")
|
||||
breakpoints.add(1, "; $num breakpoints have been defined")
|
||||
breakpoints.add(2, "del")
|
||||
viceMonListFile.toFile().appendText(breakpoints.joinToString("\n") + "\n")
|
||||
|
@ -123,7 +123,7 @@ One or more .p8 module files
|
||||
Auto-starts target system emulator after successful compilation.
|
||||
emu2 starts the alternative emulator if available.
|
||||
The compiled program and the symbol and breakpoint lists
|
||||
(for the machine code monitor) are immediately loaded into the emulator..
|
||||
(for the machine code monitor) are immediately loaded into the emulator (if it supports them)
|
||||
|
||||
``-out <directory>``
|
||||
sets directory location for output files instead of current directory
|
||||
@ -207,8 +207,8 @@ the ``srcdirs`` command line option.
|
||||
|
||||
.. _debugging:
|
||||
|
||||
Debugging (with VICE)
|
||||
---------------------
|
||||
Debugging (with VICE or Box16)
|
||||
------------------------------
|
||||
|
||||
There's support for using the monitor and debugging capabilities of the rather excellent
|
||||
`VICE emulator <http://vice-emu.sourceforge.net/>`_.
|
||||
@ -218,7 +218,7 @@ a *breakpoint* at that position. Some systems use a BRK instruction for this, bu
|
||||
this will usually halt the machine altogether instead of just suspending execution.
|
||||
Prog8 issues a NOP instruction instead and creates a 'virtual' breakpoint at this position.
|
||||
All breakpoints are then written to a file called "programname.vice-mon-list",
|
||||
which is meant to be used by the VICE emulator.
|
||||
which is meant to be used by the VICE and Box16 emulators.
|
||||
It contains a series of commands for VICE's monitor, including source labels and the breakpoint settings.
|
||||
If you use the emulator autostart feature of the compiler, it will take care of this for you.
|
||||
If you launch VICE manually, you'll have to use a command line option to load this file:
|
||||
@ -228,6 +228,9 @@ If you launch VICE manually, you'll have to use a command line option to load th
|
||||
VICE will then use the label names in memory disassembly, and will activate any breakpoints as well.
|
||||
If your running program hits one of the breakpoints, VICE will halt execution and drop you into the monitor.
|
||||
|
||||
Box16 is the alternative emulator for the Commander X16 and it also includes debugging facilities
|
||||
that support these symbol and breakpoint lists.
|
||||
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
@ -36,6 +36,7 @@ class VirtualMachine(irProgram: IRProgram) {
|
||||
val registers = Registers()
|
||||
val callStack = Stack<Pair<IRCodeChunk, Int>>()
|
||||
val valueStack = Stack<UByte>() // max 128 entries
|
||||
var breakpointHandler: ((pcChunk: IRCodeChunk, pcIndex: Int) -> Unit)? = null // can set custom breakpoint handler
|
||||
var pcChunk: IRCodeChunk
|
||||
var pcIndex = 0
|
||||
var stepCount = 0
|
||||
@ -348,7 +349,10 @@ class VirtualMachine(irProgram: IRProgram) {
|
||||
|
||||
private fun InsBREAKPOINT() {
|
||||
nextPc()
|
||||
throw BreakpointException(pcChunk, pcIndex)
|
||||
if(breakpointHandler!=null)
|
||||
breakpointHandler?.invoke(pcChunk, pcIndex)
|
||||
else
|
||||
throw BreakpointException(pcChunk, pcIndex)
|
||||
}
|
||||
|
||||
private fun InsLOADCPU(i: IRInstruction) {
|
||||
@ -2217,6 +2221,10 @@ class VmRunner: IVirtualMachineRunner {
|
||||
fun runAndTestProgram(irSource: String, test: (VirtualMachine) -> Unit) {
|
||||
val irProgram = IRFileReader().read(irSource)
|
||||
val vm = VirtualMachine(irProgram)
|
||||
// vm.breakpointHandler = { pcChunk, pcIndex ->
|
||||
// println("UNHANDLED BREAKPOINT")
|
||||
// println(" IN CHUNK: $pcChunk(${pcChunk.label}) INDEX: $pcIndex = INSTR ${pcChunk.instructions[pcIndex]}")
|
||||
// }
|
||||
vm.run()
|
||||
test(vm)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user