From c9634766e00d6a1e55c6471007f69b52f36ea7d1 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Tue, 13 Aug 2019 17:27:23 +0200 Subject: [PATCH] fix #393 by using one-shot breakpoints --- src/debugger/Debugger.cxx | 20 +++++++++++++++++++- src/debugger/Debugger.hxx | 1 + src/emucore/M6502.cxx | 9 ++++++++- src/emucore/M6502.hxx | 5 ++++- src/emucore/tia/TIA.cxx | 10 ---------- src/emucore/tia/TIA.hxx | 6 ------ 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 3592ebc2e..8915fbc6a 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -196,6 +196,12 @@ PackedBitArray& Debugger::breakPoints() const return mySystem.m6502().breakPoints(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PackedBitArray& Debugger::breakPointFlags() const +{ + return mySystem.m6502().breakPointFlags(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TrapArray& Debugger::readTraps() const { @@ -329,8 +335,18 @@ int Debugger::trace() uInt64 startCycle = mySystem.cycles(); int targetPC = myCpuDebug->pc() + 3; // return address + // set temporary breakpoint at target PC (if not existing already) + breakPoints().initialize(); + if(!breakPoints().isSet(targetPC)) + { + breakPoints().set(targetPC); + breakPointFlags().initialize(); + breakPointFlags().set(targetPC); + } + unlockSystem(); - myOSystem.console().tia().updateScanlineByTrace(targetPC).flushLineCache(); + mySystem.m6502().execute(11900000); // max. ~10 seconds + myOSystem.console().tia().flushLineCache(); lockSystem(); addState("trace"); @@ -345,6 +361,7 @@ void Debugger::toggleBreakPoint(uInt16 bp) { breakPoints().initialize(); breakPoints().toggle(bp); + breakPointFlags().initialize(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -353,6 +370,7 @@ void Debugger::setBreakPoint(uInt16 bp, bool set) breakPoints().initialize(); if(set) breakPoints().set(bp); else breakPoints().clear(bp); + breakPointFlags().initialize(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 6c6a21050..c71311ddf 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -150,6 +150,7 @@ class Debugger : public DialogContainer TiaOutputWidget& tiaOutput() const { return myDialog->tiaOutput(); } PackedBitArray& breakPoints() const; + PackedBitArray& breakPointFlags() const; TrapArray& readTraps() const; TrapArray& writeTraps() const; diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index 2fff129ea..f6f468715 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -282,7 +282,14 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) if(myBreakPoints.isInitialized() && myBreakPoints.isSet(PC)) { myLastBreakCycle = mySystem->cycles(); - result.setDebugger(currentCycles, "BP: ", PC); + // disable a one-shot breakpoint + if(myBreakPoints.isInitialized() && myBreakPointFlags.isSet(PC)) + { + myBreakPoints.clear(PC); + myBreakPointFlags.clear(PC); + } + else + result.setDebugger(currentCycles, "BP: ", PC); return; } diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index ba10f138e..84672c378 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -213,6 +213,8 @@ class M6502 : public Serializable void attach(Debugger& debugger); PackedBitArray& breakPoints() { return myBreakPoints; } + // flags used for one-shot breakpoints + PackedBitArray& breakPointFlags() { return myBreakPointFlags; } TrapArray& readTraps() { return myReadTraps; } TrapArray& writeTraps() { return myWriteTraps; } @@ -426,7 +428,8 @@ class M6502 : public Serializable Debugger* myDebugger; // Addresses for which the specified action should occur - PackedBitArray myBreakPoints;// , myReadTraps, myWriteTraps, myReadTrapIfs, myWriteTrapIfs; + PackedBitArray myBreakPoints; + PackedBitArray myBreakPointFlags; TrapArray myReadTraps, myWriteTraps; // Did we just now hit a trap? diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 8a3797bbd..3713cf98c 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -1171,16 +1171,6 @@ TIA& TIA::updateScanlineByStep() return *this; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TIA& TIA::updateScanlineByTrace(int target) -{ - uInt32 count = 10000; // only try up to 10000 steps - while (mySystem->m6502().getPC() != target && count-- && - mySystem->m6502().execute(1)); - - return *this; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 TIA::registerValue(uInt8 reg) const { diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 1a1c15818..6c7f1aaee 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -471,12 +471,6 @@ class TIA : public Device */ TIA& updateScanlineByStep(); - /** - This method should be called to update the TIA with a new partial - scanline by tracing to target address. - */ - TIA& updateScanlineByTrace(int target); - /** Retrieve the last value written to a certain register. */