Debugger: Fix ASC overflowing _sOpCodes in FormatOpcodeBytes()

This commit is contained in:
michaelangel007 2014-08-28 16:52:41 -07:00
parent 56bb3c1b18
commit e449da5b47
5 changed files with 36 additions and 31 deletions

View File

@ -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 _DEBUG
if (! g_aOpcodes) if (! g_aOpcodes)
@ -489,6 +489,9 @@ int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpby
DisasmData_t* pData = Disassembly_IsDataAddress( nBaseAddress ); DisasmData_t* pData = Disassembly_IsDataAddress( nBaseAddress );
if( pData ) if( pData )
{ {
if( pData_ )
*pData_ = pData;
nSlack = pData->nEndAddress - pData->nStartAddress + 1; // *inclusive* KEEP IN SYNC: _CmdDefineByteRange() CmdDisasmDataList() _6502_GetOpmodeOpbyte() FormatNopcodeBytes() nSlack = pData->nEndAddress - pData->nStartAddress + 1; // *inclusive* KEEP IN SYNC: _CmdDefineByteRange() CmdDisasmDataList() _6502_GetOpmodeOpbyte() FormatNopcodeBytes()
// Data Disassembler // Data Disassembler

View File

@ -119,18 +119,18 @@
// NOTE: Keep in sync AsmDirectives_e g_aAssemblerDirectives ! // NOTE: Keep in sync AsmDirectives_e g_aAssemblerDirectives !
enum AsmDirectives_e enum AsmDirectives_e
{ {
FIRST_A_DIRECTIVE = 1, FIRST_A_DIRECTIVE = 1 , // Acme
FIRST_B_DIRECTIVE = FIRST_A_DIRECTIVE + NUM_ASM_A_DIRECTIVES, // Acme FIRST_B_DIRECTIVE = FIRST_A_DIRECTIVE + NUM_ASM_A_DIRECTIVES, // Big Mac
FIRST_D_DIRECTIVE = FIRST_B_DIRECTIVE + NUM_ASM_B_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, // DOS Tool Kit FIRST_L_DIRECTIVE = FIRST_D_DIRECTIVE + NUM_ASM_D_DIRECTIVES, // Lisa
FIRST_M_DIRECTIVE = FIRST_L_DIRECTIVE + NUM_ASM_L_DIRECTIVES, // Lisa FIRST_M_DIRECTIVE = FIRST_L_DIRECTIVE + NUM_ASM_L_DIRECTIVES, // Merlin
FIRST_u_DIRECTIVE = FIRST_M_DIRECTIVE + NUM_ASM_M_DIRECTIVES, // Merlin FIRST_u_DIRECTIVE = FIRST_M_DIRECTIVE + NUM_ASM_M_DIRECTIVES, // MicroSparc
FIRST_O_DIRECTIVE = FIRST_u_DIRECTIVE + NUM_ASM_u_DIRECTIVES, // MicroSparc FIRST_O_DIRECTIVE = FIRST_u_DIRECTIVE + NUM_ASM_u_DIRECTIVES, // Orca
FIRST_S_DIRECTIVE = FIRST_O_DIRECTIVE + NUM_ASM_O_DIRECTIVES, // Orca FIRST_S_DIRECTIVE = FIRST_O_DIRECTIVE + NUM_ASM_O_DIRECTIVES, // SC
FIRST_T_DIRECTIVE = FIRST_S_DIRECTIVE + NUM_ASM_S_DIRECTIVES, // SC FIRST_T_DIRECTIVE = FIRST_S_DIRECTIVE + NUM_ASM_S_DIRECTIVES, // Ted
FIRST_W_DIRECTIVE = FIRST_T_DIRECTIVE + NUM_ASM_T_DIRECTIVES, // Ted FIRST_W_DIRECTIVE = FIRST_T_DIRECTIVE + NUM_ASM_T_DIRECTIVES, // Weller
FIRST_Z_DIRECTIVE = FIRST_W_DIRECTIVE + NUM_ASM_W_DIRECTIVES, // Weller FIRST_Z_DIRECTIVE = FIRST_W_DIRECTIVE + NUM_ASM_W_DIRECTIVES, // Custom
NUM_ASM_DIRECTIVES = FIRST_Z_DIRECTIVE + NUM_ASM_Z_DIRECTIVES // Custom NUM_ASM_DIRECTIVES = FIRST_Z_DIRECTIVE + NUM_ASM_Z_DIRECTIVES
// NUM_ASM_DIRECTIVES = 1 + // Opcode ... rest are psuedo opcodes // NUM_ASM_DIRECTIVES = 1 + // Opcode ... rest are psuedo opcodes
// NUM_ASM_A_DIRECTIVES + // Acme // NUM_ASM_A_DIRECTIVES + // Acme
@ -190,8 +190,7 @@ extern int g_aAssemblerFirstDirective[ NUM_ASSEMBLERS ];
// Prototypes _______________________________________________________________ // Prototypes _______________________________________________________________
int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_ ); int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_, const DisasmData_t** pData = NULL );
// void _6502_GetOpcodeOpmode( int & iOpcode_, int & iOpmode_, int & nOpbytes_ );
void _6502_GetOpcodeOpmodeOpbyte( int & iOpcode_, int & iOpmode_, int & nOpbytes_ ); void _6502_GetOpcodeOpmodeOpbyte( int & iOpcode_, int & iOpmode_, int & nOpbytes_ );
bool _6502_GetStackReturnAddress( WORD & nAddress_ ); bool _6502_GetStackReturnAddress( WORD & nAddress_ );
bool _6502_GetTargets( WORD nAddress, int *pTargetPartial_, int *pTargetPointer_, int * pBytes_ bool _6502_GetTargets( WORD nAddress, int *pTargetPartial_, int *pTargetPointer_, int * pBytes_

View File

@ -387,7 +387,8 @@ Update_t CmdDisasmDataDefString ( int nArgs )
int iArg = 2; int iArg = 2;
WORD nAddress = _CmdDefineByteRange( nArgs, iArg, tData ); 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.eElementType = (Nopcode_e)( NOP_STRING_APPLE + iCmd );
tData.bSymbolLookup = false; tData.bSymbolLookup = false;

View File

@ -1298,9 +1298,8 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ )
int iOpmode; int iOpmode;
int nOpbyte; int nOpbyte;
iOpcode = _6502_GetOpmodeOpbyte( nBaseAddress, iOpmode, nOpbyte ); iOpcode = _6502_GetOpmodeOpbyte( nBaseAddress, iOpmode, nOpbyte, &line_.pDisasmData );
DisasmData_t* pData = Disassembly_IsDataAddress( nBaseAddress ); const DisasmData_t* pData = line_.pDisasmData; // Disassembly_IsDataAddress( nBaseAddress );
line_.pDisasmData = pData;
line_.iOpcode = iOpcode; line_.iOpcode = iOpcode;
line_.iOpmode = iOpmode; line_.iOpmode = iOpmode;
@ -1329,8 +1328,7 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ )
if ((iOpmode == AM_AY) || (iOpmode == AM_ZY) || (iOpmode == AM_NZY)) if ((iOpmode == AM_AY) || (iOpmode == AM_ZY) || (iOpmode == AM_NZY))
line_.bTargetY = true; // ,Y line_.bTargetY = true; // ,Y
const int nMaxOpcodes = 3; unsigned int nMinBytesLen = (MAX_OPCODES * (2 + g_bConfigDisasmOpcodeSpaces)); // 2 char for byte (or 3 with space)
unsigned int nMinBytesLen = (nMaxOpcodes * (2 + g_bConfigDisasmOpcodeSpaces)); // 2 char for byte (or 3 with space)
int bDisasmFormatFlags = 0; int bDisasmFormatFlags = 0;
@ -1551,7 +1549,6 @@ int GetDisassemblyLine ( WORD nBaseAddress, DisasmLine_t & line_ )
strcpy( line_.sMnemonic, g_aOpcodes[ line_.iOpcode ].sMnemonic ); strcpy( line_.sMnemonic, g_aOpcodes[ line_.iOpcode ].sMnemonic );
} }
// TODO: BUG! _sOpcOdes overflow!
int nSpaces = strlen( line_.sOpCodes ); int nSpaces = strlen( line_.sOpCodes );
while (nSpaces < (int)nMinBytesLen) while (nSpaces < (int)nMinBytesLen)
{ {
@ -1585,12 +1582,17 @@ void FormatOpcodeBytes ( WORD nBaseAddress, DisasmLine_t & line_ )
int nOpbyte = line_.nOpbyte; int nOpbyte = line_.nOpbyte;
char *pDst = line_.sOpCodes; 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); BYTE nMem = (unsigned)*(mem+nBaseAddress + iByte);
sprintf( pDst, "%02X", nMem ); // sBytes+strlen(sBytes) sprintf( pDst, "%02X", nMem ); // sBytes+strlen(sBytes)
pDst += 2; pDst += 2;
// TODO: If Disassembly_IsDataAddress() don't show spaces...
if (g_bConfigDisasmOpcodeSpaces) if (g_bConfigDisasmOpcodeSpaces)
{ {
strcat( pDst, " " ); strcat( pDst, " " );
@ -1652,8 +1654,8 @@ void FormatNopcodeBytes ( WORD nBaseAddress, DisasmLine_t & line_ )
*pDst = 0; *pDst = 0;
case NOP_STRING_APPLE: case NOP_STRING_APPLE:
iByte = line_.nOpbyte; // handled all bytes of text iByte = line_.nOpbyte; // handled all bytes of text
if( len > MAX_IMMEDIATE_LEN ) if( len > (MAX_IMMEDIATE_LEN - 5)) // need 5 extra characters
len = MAX_IMMEDIATE_LEN; len = (MAX_IMMEDIATE_LEN - 5); // 1=", 2=", 5=...
*pDst++ = '"'; *pDst++ = '"';
for( int i = 0; i < len; i++ ) // iNopcode = Length of Data 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) void DrawSubWindow_Data (Update_t bUpdate)
{ {
// HDC hDC = g_hDC; // HDC hDC = g_hDC;
int iBackground; int iBackground;
const int nMaxOpcodes = WINDOW_DATA_BYTES_PER_LINE; const int nMaxOpcodes = WINDOW_DATA_BYTES_PER_LINE;
char sAddress [ 5]; char sAddress[ 5 ];
assert( CONSOLE_WIDTH > WINDOW_DATA_BYTES_PER_LINE ); assert( CONSOLE_WIDTH > WINDOW_DATA_BYTES_PER_LINE );

View File

@ -889,9 +889,9 @@
enum DisasmText_e enum DisasmText_e
{ {
MAX_ADDRESS_LEN = 40, MAX_ADDRESS_LEN = 40,
nMaxOpcodes = 3, MAX_OPCODES = 3, // only display 3 opcode bytes
CHARS_FOR_ADDRESS = 8, // 4 digits + end-of-string + padding 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 struct DisasmLine_t
@ -901,7 +901,7 @@
int nOpbyte; int nOpbyte;
char sAddress [ CHARS_FOR_ADDRESS ]; char sAddress [ CHARS_FOR_ADDRESS ];
char sOpCodes [(nMaxOpcodes*3)+1]; char sOpCodes [(MAX_OPCODES*3)+1];
// Added for Data Disassembler // Added for Data Disassembler
char sLabel [ MAX_SYMBOLS_LEN+1 ]; // label is a symbol char sLabel [ MAX_SYMBOLS_LEN+1 ]; // label is a symbol
@ -911,7 +911,7 @@
int nSlack ; int nSlack ;
char sMnemonic [ MAX_SYMBOLS_LEN+1 ]; // either the real Mnemonic or the Assembler Directive 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 int nTarget; // address -> string