diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 79e9a303..c8ff0434 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -315,6 +315,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static bool g_bIgnoreNextKey = false; + static WORD g_LBR = 0x0000; // Last Branch Record + // Private ________________________________________________________________________________________ @@ -2184,6 +2186,13 @@ Update_t CmdOut (int nArgs) return UPDATE_CONSOLE_DISPLAY; // TODO: Verify // 1 } +//=========================================================================== +Update_t CmdLBR(int nArgs) +{ + TCHAR sText[CONSOLE_WIDTH]; + ConsolePrintFormat(sText, " LBR = $%04X", g_LBR); + return ConsoleUpdate(); +} // Color __________________________________________________________________________________________ @@ -8145,6 +8154,28 @@ static void CheckBreakOpcode( int iOpcode ) g_bDebugBreakpointHit |= BP_HIT_OPCODE; } +static void UpdateLBR(void) +{ + const BYTE nOpcode = *(mem + regs.pc); + + bool isControlFlowOpcode = + nOpcode == OPCODE_BRK || + nOpcode == OPCODE_JSR || + nOpcode == OPCODE_JMP_A || + nOpcode == OPCODE_RTI || + nOpcode == OPCODE_RTS || + nOpcode == OPCODE_JMP_NA; + + if (GetMainCpu() == CPU_65C02 && nOpcode == OPCODE_JMP_IAX) + isControlFlowOpcode = true; + + if (g_aOpcodes[nOpcode].nAddressMode == AM_R) + isControlFlowOpcode = true; + + if (isControlFlowOpcode) + g_LBR = regs.pc; +} + void DebugContinueStepping(const bool bCallerWillUpdateDisplay/*=false*/) { static bool bForceSingleStepNext = false; // Allow at least one instruction to execute so we don't trigger on the same invalid opcode @@ -8186,7 +8217,7 @@ void DebugContinueStepping(const bool bCallerWillUpdateDisplay/*=false*/) BYTE nOpcode = *(mem+regs.pc); // Update profiling stats - int nOpmode = g_aOpcodes[ nOpcode ].nAddressMode; + int nOpmode = g_aOpcodes[ nOpcode ].nAddressMode; g_aProfileOpcodes[ nOpcode ].m_nCount++; g_aProfileOpmodes[ nOpmode ].m_nCount++; @@ -8206,6 +8237,8 @@ void DebugContinueStepping(const bool bCallerWillUpdateDisplay/*=false*/) if (bDoSingleStep) { + UpdateLBR(); + SingleStep(g_bGoCmd_ReinitFlag); g_bGoCmd_ReinitFlag = false; @@ -8494,6 +8527,7 @@ void DebugInitialize () void DebugReset(void) { g_videoScannerDisplayInfo.Reset(); + g_LBR = 0x0000; } // Add character to the input line diff --git a/source/Debugger/Debugger_Commands.cpp b/source/Debugger/Debugger_Commands.cpp index 33fb3b7c..456ae7c4 100644 --- a/source/Debugger/Debugger_Commands.cpp +++ b/source/Debugger/Debugger_Commands.cpp @@ -52,6 +52,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {TEXT("JSR") , CmdJSR , CMD_JSR , "Call sub-routine" }, {TEXT("NOP") , CmdNOP , CMD_NOP , "Zap the current instruction with a NOP" }, {TEXT("OUT") , CmdOut , CMD_OUT , "Output byte to IO $C0xx" }, + {TEXT("LBR") , CmdLBR , CMD_LBR , "Show Last Branch Record" }, // CPU - Meta Info {TEXT("PROFILE") , CmdProfile , CMD_PROFILE , "List/Save 6502 profiling" }, {TEXT("R") , CmdRegisterSet , CMD_REGISTER_SET , "Set register" }, diff --git a/source/Debugger/Debugger_Types.h b/source/Debugger/Debugger_Types.h index e222c641..afae7630 100644 --- a/source/Debugger/Debugger_Types.h +++ b/source/Debugger/Debugger_Types.h @@ -295,6 +295,7 @@ , CMD_JSR , CMD_NOP , CMD_OUT + , CMD_LBR // CPU - Meta Info , CMD_PROFILE , CMD_REGISTER_SET @@ -605,6 +606,7 @@ Update_t CmdJSR (int nArgs); Update_t CmdNOP (int nArgs); Update_t CmdOut (int nArgs); + Update_t CmdLBR (int nArgs); Update_t CmdStepOver (int nArgs); Update_t CmdStepOut (int nArgs); Update_t CmdTrace (int nArgs); // alias for CmdStepIn