Debugger: Extend 'brk' cmd:

. brk all <on|off>
Fix 'brk' cmd for invalid opcodes of length 2 & 3
This commit is contained in:
tomcw 2021-12-11 13:41:34 +00:00
parent 1ab0d56558
commit 0ac210b132
4 changed files with 66 additions and 14 deletions

View File

@ -839,10 +839,9 @@ _Help:
//=========================================================================== //===========================================================================
// iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3 // iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3
static int IsDebugBreakOnInvalid( int iOpcodeType ) static bool IsDebugBreakOnInvalid(int iOpcodeType)
{ {
g_bDebugBreakpointHit |= ((g_nDebugBreakOnInvalid >> iOpcodeType) & 1) ? BP_HIT_INVALID : 0; return ((g_nDebugBreakOnInvalid >> iOpcodeType) & 1) ? true : false;
return g_bDebugBreakpointHit;
} }
// iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3 // iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3
@ -875,14 +874,15 @@ Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
// Cases: // Cases:
// 0. CMD // display // 0. CMD // display
// 1a. CMD # // display // 1a. CMD # // display
// 1b. CMD ON | OFF //set // 1b. CMD ON | OFF // set
// 1c. CMD ? // error // 1c. CMD ? // error
// 2a. CMD # ON | OFF // set // 2a. CMD # ON | OFF // set
// 2b. CMD # ? // error // 2b. CMD ALL ON | OFF // set all
// 2c. CMD # ? // error
TCHAR sText[ CONSOLE_WIDTH ]; TCHAR sText[ CONSOLE_WIDTH ];
bool bValidParam = true; bool bValidParam = true;
int iParamArg = nArgs; int iParamArg = nArgs; // last arg is the 'ON' / 'OFF' param
int iParam; int iParam;
int nFound = FindParam( g_aArgs[ iParamArg ].sArg, MATCH_EXACT, iParam, _PARAM_GENERAL_BEGIN, _PARAM_GENERAL_END ); int nFound = FindParam( g_aArgs[ iParamArg ].sArg, MATCH_EXACT, iParam, _PARAM_GENERAL_BEGIN, _PARAM_GENERAL_END );
@ -894,14 +894,17 @@ Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
if (iParam == PARAM_OFF) if (iParam == PARAM_OFF)
nActive = 0; nActive = 0;
else else
{
bValidParam = false; bValidParam = false;
nFound = 0;
}
} }
else else
bValidParam = false; bValidParam = false;
if (nArgs == 1) if (nArgs == 1)
{ {
if (! nFound) // bValidParam) // case 1a or 1c if (! nFound)
{ {
if ((iType < AM_IMPLIED) || (iType > AM_3)) if ((iType < AM_IMPLIED) || (iType > AM_3))
goto _Help; goto _Help;
@ -925,11 +928,19 @@ Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
else else
if (nArgs == 2) if (nArgs == 2)
{ {
if (! bValidParam) // case 2b int iParam1;
if (FindParam(g_aArgs[1].sArg, MATCH_EXACT, iParam1, PARAM_ALL, PARAM_ALL)) // case 2b
{
for (iType = 0; iType <= AM_3; iType++)
SetDebugBreakOnInvalid(iType, nActive);
ConsoleBufferPushFormat(sText, TEXT("Enter debugger on BRK opcode and INVALID opcodes: %s"), g_aParameters[iParam].m_sName);
return ConsoleUpdate();
}
else if (! bValidParam) // case 2c
{ {
goto _Help; goto _Help;
} }
else // case 2a (or not 2b ;-) else // case 2a
{ {
if ((iType < 0) || (iType > AM_3)) if ((iType < 0) || (iType > AM_3))
goto _Help; goto _Help;
@ -8203,12 +8214,41 @@ void DebugExitDebugger ()
static void CheckBreakOpcode( int iOpcode ) static void CheckBreakOpcode( int iOpcode )
{ {
if (iOpcode == 0x00) // BRK if (iOpcode == 0x00) // BRK
IsDebugBreakOnInvalid( AM_IMPLIED ); g_bDebugBreakpointHit |= IsDebugBreakOnInvalid(AM_IMPLIED) ? BP_HIT_INVALID : 0;
if (g_aOpcodes[iOpcode].sMnemonic[0] >= 'a') // All 6502/65C02 undocumented opcodes mnemonics are lowercase strings! if (g_aOpcodes[iOpcode].sMnemonic[0] >= 'a') // All 6502/65C02 undocumented opcodes mnemonics are lowercase strings!
{ {
// TODO: Translate g_aOpcodes[iOpcode].nAddressMode into {AM_1, AM_2, AM_3} // Translate g_aOpcodes[iOpcode].nAddressMode into {AM_1, AM_2, AM_3}
IsDebugBreakOnInvalid( AM_1 ); int iOpcodeType = AM_1;
switch (g_aOpcodes[iOpcode].nAddressMode)
{
case AM_1: // Invalid 1 Byte
case AM_IMPLIED:
iOpcodeType = AM_1;
break;
case AM_2: // Invalid 2 Bytes
case AM_M: // 4 #Immediate
case AM_Z: // 6 Zeropage
case AM_ZX: // 9 Zeropage, X
case AM_ZY: // 10 Zeropage, Y
case AM_R: // 11 Relative
case AM_IZX: // 12 Indexed (Zeropage Indirect, X)
case AM_NZY: // 14 Indirect (Zeropage) Indexed, Y
case AM_NZ: // 15 Indirect (Zeropage)
iOpcodeType = AM_2;
break;
case AM_3: // Invalid 3 Bytes
case AM_A: // 5 $Absolute
case AM_AX: // 7 Absolute, X
case AM_AY: // 8 Absolute, Y
case AM_IAX: // 13 Indexed (Absolute Indirect, X)
case AM_NA: // 16 Indirect (Absolute) i.e. JMP
iOpcodeType = AM_3;
break;
default:
_ASSERT(0);
}
g_bDebugBreakpointHit |= IsDebugBreakOnInvalid(iOpcodeType) ? BP_HIT_INVALID : 0;
} }
// User wants to enter debugger on specific opcode? (NB. Can't be BRK) // User wants to enter debugger on specific opcode? (NB. Can't be BRK)

View File

@ -456,6 +456,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{TEXT("SAVE") , NULL, PARAM_SAVE }, {TEXT("SAVE") , NULL, PARAM_SAVE },
{TEXT("START") , NULL, PARAM_START }, // benchmark {TEXT("START") , NULL, PARAM_START }, // benchmark
{TEXT("STOP") , NULL, PARAM_STOP }, // benchmark {TEXT("STOP") , NULL, PARAM_STOP }, // benchmark
{TEXT("ALL") , NULL, PARAM_ALL },
// Help Categories // Help Categories
{"*" , NULL, PARAM_WILDSTAR }, {"*" , NULL, PARAM_WILDSTAR },
{"BOOKMARKS" , NULL, PARAM_CAT_BOOKMARKS }, {"BOOKMARKS" , NULL, PARAM_CAT_BOOKMARKS },

View File

@ -984,7 +984,7 @@ Update_t CmdHelpSpecific (int nArgs)
break; break;
// Breakpoints // Breakpoints
case CMD_BREAK_INVALID: case CMD_BREAK_INVALID:
ConsoleColorizePrintFormat( sTemp, sText, TEXT(" Usage: [%s%s | %s%s] | [ # | # %s%s | # %s%s ]") ConsoleColorizePrintFormat( sTemp, sText, TEXT(" Usage: [%s%s | %s%s] | [# | # %s%s | # %s%s]")
, CHC_COMMAND , CHC_COMMAND
, g_aParameters[ PARAM_ON ].m_sName , g_aParameters[ PARAM_ON ].m_sName
, CHC_COMMAND , CHC_COMMAND
@ -994,6 +994,16 @@ Update_t CmdHelpSpecific (int nArgs)
, CHC_COMMAND , CHC_COMMAND
, g_aParameters[ PARAM_OFF ].m_sName , g_aParameters[ PARAM_OFF ].m_sName
); );
ConsoleColorizePrintFormat(sTemp, sText, TEXT(" Usage: [%s%s %s%s | %s%s %s%s]")
, CHC_COMMAND
, g_aParameters[PARAM_ALL].m_sName
, CHC_COMMAND
, g_aParameters[PARAM_ON].m_sName
, CHC_COMMAND
, g_aParameters[PARAM_ALL].m_sName
, CHC_COMMAND
, g_aParameters[PARAM_OFF].m_sName
);
ConsoleColorizePrint( sTemp, TEXT("Where: # is 0=BRK, 1=Invalid Opcode_1, 2=Invalid Opcode_2, 3=Invalid Opcode_3")); ConsoleColorizePrint( sTemp, TEXT("Where: # is 0=BRK, 1=Invalid Opcode_1, 2=Invalid Opcode_2, 3=Invalid Opcode_3"));
break; break;
// case CMD_BREAK_OPCODE: // case CMD_BREAK_OPCODE:

View File

@ -1405,6 +1405,7 @@ const DisasmData_t* pDisasmData; // If != NULL then bytes are marked up as data
, PARAM_SAVE , PARAM_SAVE
, PARAM_START , PARAM_START
, PARAM_STOP , PARAM_STOP
, PARAM_ALL
, _PARAM_GENERAL_END , _PARAM_GENERAL_END
, PARAM_GENERAL_NUM = _PARAM_GENERAL_END - _PARAM_GENERAL_BEGIN , PARAM_GENERAL_NUM = _PARAM_GENERAL_END - _PARAM_GENERAL_BEGIN