Replace sprintf_s() and wsprintf() with StrFormat(). (PR #1041)

And these Debugger related:
. Improve FormatAddress() and GetSymbol().
. GetSymbol(), FindSymbolFromAddress(), FormatAddress() are changed to use std::string instead.
. Remove static variable (not nice) in FormatAddress().
. GetSymbol() returns std::string reference instead of pointer.
This commit is contained in:
Kelvin Lee
2022-02-27 04:54:06 +11:00
committed by GitHub
parent 9ad6b11cf9
commit 253a59fde6
21 changed files with 238 additions and 323 deletions
+28 -37
View File
@@ -1700,15 +1700,9 @@ Update_t CmdBreakpointEnable (int nArgs) {
void _BWZ_List( const Breakpoint_t * aBreakWatchZero, const int iBWZ ) //, bool bZeroBased )
{
static const char sFlags[] = "-*";
static char sName[ MAX_SYMBOLS_LEN+1 ];
WORD nAddress = aBreakWatchZero[ iBWZ ].nAddress;
const char* pSymbol = GetSymbol( nAddress, 2 );
if (! pSymbol)
{
sName[0] = 0;
pSymbol = sName;
}
std::string strAddressBuf;
std::string const& symbol = GetSymbol(aBreakWatchZero[iBWZ].nAddress, 2, strAddressBuf);
char cBPM = aBreakWatchZero[iBWZ].eSource == BP_SRC_MEM_READ_ONLY ? 'R'
: aBreakWatchZero[iBWZ].eSource == BP_SRC_MEM_WRITE_ONLY ? 'W'
@@ -1717,10 +1711,10 @@ void _BWZ_List( const Breakpoint_t * aBreakWatchZero, const int iBWZ ) //, bool
ConsoleBufferPushFormat( " #%d %c %04X %c %s",
// (bZeroBased ? iBWZ + 1 : iBWZ),
iBWZ,
sFlags[ (int) aBreakWatchZero[ iBWZ ].bEnabled ],
sFlags[ aBreakWatchZero[ iBWZ ].bEnabled ? 1 : 0 ],
aBreakWatchZero[ iBWZ ].nAddress,
cBPM,
pSymbol
symbol.c_str()
);
}
@@ -2270,9 +2264,8 @@ void _CmdColorGet( const int iScheme, const int iColor )
}
else
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, "Color: %d\nOut of range!", iColor );
GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK );
std::string strText = StrFormat( "Color: %d\nOut of range!", iColor );
GetFrame().FrameMessageBox(strText.c_str(), "ERROR", MB_OK);
}
}
@@ -5774,7 +5767,6 @@ Update_t CmdOutputCalc (int nArgs)
return Help_Arg_1( CMD_OUTPUT_CALC );
WORD nAddress = g_aArgs[1].nValue;
TCHAR sText [ CONSOLE_WIDTH ];
bool bHi = false;
bool bLo = false;
@@ -5796,28 +5788,27 @@ Update_t CmdOutputCalc (int nArgs)
// CHC_NUM_DEC
// CHC_ARG_
// CHC_STRING
wsprintf( sText, TEXT("$%04X 0z%08X %5d '%c' "),
nAddress, nBit, nAddress, c );
std::string strText = StrFormat( "$%04X 0z%08X %5d '%c' ", nAddress, nBit, nAddress, c );
if (bParen)
strcat( sText, TEXT("(") );
strText += '(';
if (bHi & bLo)
strcat( sText, TEXT("High Ctrl") );
strText += "High Ctrl";
else
if (bHi)
strcat( sText, TEXT("High") );
strText += "High";
else
if (bLo)
strcat( sText, TEXT("Ctrl") );
strText += "Ctrl";
if (bParen)
strcat( sText, TEXT(")") );
strText += ')';
ConsoleBufferPush( sText );
ConsoleBufferPush( strText.c_str() );
// If we colorize then w must also guard against character ouput $60
// ConsolePrint( sText );
// ConsolePrint( strText.c_str() );
return ConsoleUpdate();
}
@@ -8420,33 +8411,33 @@ void DebugContinueStepping(const bool bCallerWillUpdateDisplay/*=false*/)
if (regs.pc == g_nDebugStepUntil || g_bDebugBreakpointHit)
{
char szStopMessage[CONSOLE_WIDTH];
const char* pszStopReason = szStopMessage;
std::string strStopMessage;
const char* pszStopReason = "";
if (regs.pc == g_nDebugStepUntil)
pszStopReason = TEXT("PC matches 'Go until' address");
pszStopReason = "PC matches 'Go until' address";
else if (g_bDebugBreakpointHit & BP_HIT_INVALID)
pszStopReason = TEXT("Invalid opcode");
pszStopReason = "Invalid opcode";
else if (g_bDebugBreakpointHit & BP_HIT_OPCODE)
pszStopReason = TEXT("Opcode match");
pszStopReason = "Opcode match";
else if (g_bDebugBreakpointHit & BP_HIT_REG)
pszStopReason = TEXT("Register matches value");
pszStopReason = "Register matches value";
else if (g_bDebugBreakpointHit & BP_HIT_MEM)
sprintf_s(szStopMessage, sizeof(szStopMessage), "Memory access at $%04X", g_uBreakMemoryAddress);
pszStopReason = (strStopMessage = StrFormat("Memory access at $%04X", g_uBreakMemoryAddress)).c_str();
else if (g_bDebugBreakpointHit & BP_HIT_MEMW)
sprintf_s(szStopMessage, sizeof(szStopMessage), "Write access at $%04X", g_uBreakMemoryAddress);
pszStopReason = (strStopMessage = StrFormat("Write access at $%04X", g_uBreakMemoryAddress)).c_str();
else if (g_bDebugBreakpointHit & BP_HIT_MEMR)
sprintf_s(szStopMessage, sizeof(szStopMessage), "Read access at $%04X", g_uBreakMemoryAddress);
pszStopReason = (strStopMessage = StrFormat("Read access at $%04X", g_uBreakMemoryAddress)).c_str();
else if (g_bDebugBreakpointHit & BP_HIT_PC_READ_FLOATING_BUS_OR_IO_MEM)
pszStopReason = TEXT("PC reads from floating bus or I/O memory");
pszStopReason = "PC reads from floating bus or I/O memory";
else if (g_bDebugBreakpointHit & BP_HIT_INTERRUPT)
sprintf_s(szStopMessage, sizeof(szStopMessage), "Interrupt occurred at $%04X", g_LBR);
pszStopReason = (strStopMessage = StrFormat("Interrupt occurred at $%04X", g_LBR)).c_str();
else if (g_bDebugBreakpointHit & BP_DMA_TO_IO_MEM)
sprintf_s(szStopMessage, sizeof(szStopMessage), "HDD DMA to I/O memory or ROM $%04X", g_uDebugBreakOnDmaIoMemoryAddr);
pszStopReason = (strStopMessage = StrFormat("HDD DMA to I/O memory or ROM $%04X", g_uDebugBreakOnDmaIoMemoryAddr)).c_str();
else if (g_bDebugBreakpointHit & BP_DMA_FROM_IO_MEM)
sprintf_s(szStopMessage, sizeof(szStopMessage), "HDD DMA from I/O memory $%04X", g_uDebugBreakOnDmaIoMemoryAddr);
pszStopReason = (strStopMessage = StrFormat("HDD DMA from I/O memory $%04X", g_uDebugBreakOnDmaIoMemoryAddr)).c_str();
else
pszStopReason = TEXT("Unknown!");
pszStopReason = "Unknown!";
ConsoleBufferPushFormat( "Stop reason: %s", pszStopReason );
ConsoleUpdate();