From e449da5b4739e6e9fa8fff7b313678df6b461f27 Mon Sep 17 00:00:00 2001 From: michaelangel007 Date: Thu, 28 Aug 2014 16:52:41 -0700 Subject: [PATCH] Debugger: Fix ASC overflowing _sOpCodes in FormatOpcodeBytes() --- source/Debugger/Debugger_Assembler.cpp | 5 +++- source/Debugger/Debugger_Assembler.h | 27 +++++++++---------- source/Debugger/Debugger_DisassemblerData.cpp | 3 ++- source/Debugger/Debugger_Display.cpp | 24 +++++++++-------- source/Debugger/Debugger_Types.h | 8 +++--- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/source/Debugger/Debugger_Assembler.cpp b/source/Debugger/Debugger_Assembler.cpp index d5e4944e..98dab54b 100644 --- a/source/Debugger/Debugger_Assembler.cpp +++ b/source/Debugger/Debugger_Assembler.cpp @@ -464,7 +464,7 @@ bool _6502_CalcRelativeOffset( int nOpcode, int nBaseAddress, int nTargetAddress //=========================================================================== -int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpbyte_ ) +int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpbyte_, const DisasmData_t** pData_ ) { #if _DEBUG if (! g_aOpcodes) @@ -489,6 +489,9 @@ int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpby DisasmData_t* pData = Disassembly_IsDataAddress( nBaseAddress ); if( pData ) { + if( pData_ ) + *pData_ = pData; + nSlack = pData->nEndAddress - pData->nStartAddress + 1; // *inclusive* KEEP IN SYNC: _CmdDefineByteRange() CmdDisasmDataList() _6502_GetOpmodeOpbyte() FormatNopcodeBytes() // Data Disassembler diff --git a/source/Debugger/Debugger_Assembler.h b/source/Debugger/Debugger_Assembler.h index 21b8588d..61767ed1 100644 --- a/source/Debugger/Debugger_Assembler.h +++ b/source/Debugger/Debugger_Assembler.h @@ -119,18 +119,18 @@ // NOTE: Keep in sync AsmDirectives_e g_aAssemblerDirectives ! enum AsmDirectives_e { - FIRST_A_DIRECTIVE = 1, - FIRST_B_DIRECTIVE = FIRST_A_DIRECTIVE + NUM_ASM_A_DIRECTIVES, // Acme - FIRST_D_DIRECTIVE = FIRST_B_DIRECTIVE + NUM_ASM_B_DIRECTIVES, // Big Mac - FIRST_L_DIRECTIVE = FIRST_D_DIRECTIVE + NUM_ASM_D_DIRECTIVES, // DOS Tool Kit - FIRST_M_DIRECTIVE = FIRST_L_DIRECTIVE + NUM_ASM_L_DIRECTIVES, // Lisa - FIRST_u_DIRECTIVE = FIRST_M_DIRECTIVE + NUM_ASM_M_DIRECTIVES, // Merlin - FIRST_O_DIRECTIVE = FIRST_u_DIRECTIVE + NUM_ASM_u_DIRECTIVES, // MicroSparc - FIRST_S_DIRECTIVE = FIRST_O_DIRECTIVE + NUM_ASM_O_DIRECTIVES, // Orca - FIRST_T_DIRECTIVE = FIRST_S_DIRECTIVE + NUM_ASM_S_DIRECTIVES, // SC - FIRST_W_DIRECTIVE = FIRST_T_DIRECTIVE + NUM_ASM_T_DIRECTIVES, // Ted - FIRST_Z_DIRECTIVE = FIRST_W_DIRECTIVE + NUM_ASM_W_DIRECTIVES, // Weller - NUM_ASM_DIRECTIVES = FIRST_Z_DIRECTIVE + NUM_ASM_Z_DIRECTIVES // Custom + FIRST_A_DIRECTIVE = 1 , // Acme + FIRST_B_DIRECTIVE = FIRST_A_DIRECTIVE + NUM_ASM_A_DIRECTIVES, // Big Mac + FIRST_D_DIRECTIVE = FIRST_B_DIRECTIVE + NUM_ASM_B_DIRECTIVES, // DOS Tool Kit + FIRST_L_DIRECTIVE = FIRST_D_DIRECTIVE + NUM_ASM_D_DIRECTIVES, // Lisa + FIRST_M_DIRECTIVE = FIRST_L_DIRECTIVE + NUM_ASM_L_DIRECTIVES, // Merlin + FIRST_u_DIRECTIVE = FIRST_M_DIRECTIVE + NUM_ASM_M_DIRECTIVES, // MicroSparc + FIRST_O_DIRECTIVE = FIRST_u_DIRECTIVE + NUM_ASM_u_DIRECTIVES, // Orca + FIRST_S_DIRECTIVE = FIRST_O_DIRECTIVE + NUM_ASM_O_DIRECTIVES, // SC + FIRST_T_DIRECTIVE = FIRST_S_DIRECTIVE + NUM_ASM_S_DIRECTIVES, // Ted + FIRST_W_DIRECTIVE = FIRST_T_DIRECTIVE + NUM_ASM_T_DIRECTIVES, // Weller + FIRST_Z_DIRECTIVE = FIRST_W_DIRECTIVE + NUM_ASM_W_DIRECTIVES, // Custom + NUM_ASM_DIRECTIVES = FIRST_Z_DIRECTIVE + NUM_ASM_Z_DIRECTIVES // NUM_ASM_DIRECTIVES = 1 + // Opcode ... rest are psuedo opcodes // NUM_ASM_A_DIRECTIVES + // Acme @@ -190,8 +190,7 @@ extern int g_aAssemblerFirstDirective[ NUM_ASSEMBLERS ]; // Prototypes _______________________________________________________________ - int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_ ); -// void _6502_GetOpcodeOpmode( int & iOpcode_, int & iOpmode_, int & nOpbytes_ ); + int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_, const DisasmData_t** pData = NULL ); void _6502_GetOpcodeOpmodeOpbyte( int & iOpcode_, int & iOpmode_, int & nOpbytes_ ); bool _6502_GetStackReturnAddress( WORD & nAddress_ ); bool _6502_GetTargets( WORD nAddress, int *pTargetPartial_, int *pTargetPointer_, int * pBytes_ diff --git a/source/Debugger/Debugger_DisassemblerData.cpp b/source/Debugger/Debugger_DisassemblerData.cpp index cff01e5c..82d1edd3 100644 --- a/source/Debugger/Debugger_DisassemblerData.cpp +++ b/source/Debugger/Debugger_DisassemblerData.cpp @@ -387,7 +387,8 @@ Update_t CmdDisasmDataDefString ( int nArgs ) int iArg = 2; WORD nAddress = _CmdDefineByteRange( nArgs, iArg, tData ); - tData.iDirective = g_aAssemblerFirstDirective[ g_iAssemblerSyntax ] + ASM_DEFINE_APPLE_TEXT; +// tData.iDirective = g_aAssemblerFirstDirective[ g_iAssemblerSyntax ] + ASM_DEFINE_APPLE_TEXT; + tData.iDirective = FIRST_M_DIRECTIVE + ASM_M_ASCII; // ASM_MERLIN tData.eElementType = (Nopcode_e)( NOP_STRING_APPLE + iCmd ); tData.bSymbolLookup = false; diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index dd971ff6..7e95fb48 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -1298,9 +1298,8 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ ) int iOpmode; int nOpbyte; - iOpcode = _6502_GetOpmodeOpbyte( nBaseAddress, iOpmode, nOpbyte ); - DisasmData_t* pData = Disassembly_IsDataAddress( nBaseAddress ); - line_.pDisasmData = pData; + iOpcode = _6502_GetOpmodeOpbyte( nBaseAddress, iOpmode, nOpbyte, &line_.pDisasmData ); + const DisasmData_t* pData = line_.pDisasmData; // Disassembly_IsDataAddress( nBaseAddress ); line_.iOpcode = iOpcode; line_.iOpmode = iOpmode; @@ -1329,8 +1328,7 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ ) if ((iOpmode == AM_AY) || (iOpmode == AM_ZY) || (iOpmode == AM_NZY)) line_.bTargetY = true; // ,Y - const int nMaxOpcodes = 3; - unsigned int nMinBytesLen = (nMaxOpcodes * (2 + g_bConfigDisasmOpcodeSpaces)); // 2 char for byte (or 3 with space) + unsigned int nMinBytesLen = (MAX_OPCODES * (2 + g_bConfigDisasmOpcodeSpaces)); // 2 char for byte (or 3 with space) int bDisasmFormatFlags = 0; @@ -1551,7 +1549,6 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ ) strcpy( line_.sMnemonic, g_aOpcodes[ line_.iOpcode ].sMnemonic ); } - // TODO: BUG! _sOpcOdes overflow! int nSpaces = strlen( line_.sOpCodes ); while (nSpaces < (int)nMinBytesLen) { @@ -1585,12 +1582,17 @@ void FormatOpcodeBytes ( WORD nBaseAddress, DisasmLine_t & line_ ) int nOpbyte = line_.nOpbyte; char *pDst = line_.sOpCodes; - for( int iByte = 0; iByte < nOpbyte; iByte++ ) + int nMaxOpBytes = nOpbyte; + if ( nMaxOpBytes > MAX_OPCODES) // 2.8.0.0 fix // TODO: FIX: show max 8 bytes for HEX + nMaxOpBytes = MAX_OPCODES; + + for( int iByte = 0; iByte < nMaxOpBytes; iByte++ ) { BYTE nMem = (unsigned)*(mem+nBaseAddress + iByte); sprintf( pDst, "%02X", nMem ); // sBytes+strlen(sBytes) pDst += 2; + // TODO: If Disassembly_IsDataAddress() don't show spaces... if (g_bConfigDisasmOpcodeSpaces) { strcat( pDst, " " ); @@ -1652,8 +1654,8 @@ void FormatNopcodeBytes ( WORD nBaseAddress, DisasmLine_t & line_ ) *pDst = 0; case NOP_STRING_APPLE: iByte = line_.nOpbyte; // handled all bytes of text - if( len > MAX_IMMEDIATE_LEN ) - len = MAX_IMMEDIATE_LEN; + if( len > (MAX_IMMEDIATE_LEN - 5)) // need 5 extra characters + len = (MAX_IMMEDIATE_LEN - 5); // 1=", 2=", 5=... *pDst++ = '"'; for( int i = 0; i < len; i++ ) // iNopcode = Length of Data @@ -3203,10 +3205,10 @@ void DrawSubWindow_Console (Update_t bUpdate) void DrawSubWindow_Data (Update_t bUpdate) { // HDC hDC = g_hDC; - int iBackground; + int iBackground; const int nMaxOpcodes = WINDOW_DATA_BYTES_PER_LINE; - char sAddress [ 5]; + char sAddress[ 5 ]; assert( CONSOLE_WIDTH > WINDOW_DATA_BYTES_PER_LINE ); diff --git a/source/Debugger/Debugger_Types.h b/source/Debugger/Debugger_Types.h index c974e02b..8ceffeab 100644 --- a/source/Debugger/Debugger_Types.h +++ b/source/Debugger/Debugger_Types.h @@ -889,9 +889,9 @@ enum DisasmText_e { MAX_ADDRESS_LEN = 40, - nMaxOpcodes = 3, + MAX_OPCODES = 3, // only display 3 opcode bytes CHARS_FOR_ADDRESS = 8, // 4 digits + end-of-string + padding - MAX_IMMEDIATE_LEN = 16, // Data Disassembly + MAX_IMMEDIATE_LEN = 20, // Data Disassembly }; struct DisasmLine_t @@ -901,7 +901,7 @@ int nOpbyte; char sAddress [ CHARS_FOR_ADDRESS ]; - char sOpCodes [(nMaxOpcodes*3)+1]; + char sOpCodes [(MAX_OPCODES*3)+1]; // Added for Data Disassembler char sLabel [ MAX_SYMBOLS_LEN+1 ]; // label is a symbol @@ -911,7 +911,7 @@ int nSlack ; char sMnemonic [ MAX_SYMBOLS_LEN+1 ]; // either the real Mnemonic or the Assembler Directive -const DisasmData_t* pDisasmData; +const DisasmData_t* pDisasmData; // If != NULL then bytes are marked up as data not code // int nTarget; // address -> string