Skip to content

Commit 485c085

Browse files
committed
[GEN][ZH] Implement DEBUG_LOG_RAW, DEBUG_LOG_LEVEL_RAW for raw string logging
1 parent 903975e commit 485c085

File tree

37 files changed

+241
-165
lines changed

37 files changed

+241
-165
lines changed

Generals/Code/GameEngine/Include/Common/Debug.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class AsciiString;
138138
#ifdef DEBUG_LOGGING
139139

140140
DEBUG_EXTERN_C void DebugLog(const char *format, ...);
141+
DEBUG_EXTERN_C void DebugLogRaw(const char *format, ...);
141142
DEBUG_EXTERN_C const char* DebugGetLogFileName();
142143
DEBUG_EXTERN_C const char* DebugGetLogFileNamePrev();
143144

@@ -152,14 +153,18 @@ class AsciiString;
152153
};
153154
extern const char *TheDebugLevels[DEBUG_LEVEL_MAX];
154155

155-
#define DEBUG_LOG(m) do { { DebugLog m ; } } while (0)
156+
#define DEBUG_LOG(m) do { { DebugLog m ; } } while (0) // Log message with trailing new line character (LF)
157+
#define DEBUG_LOG_RAW(m) do { { DebugLogRaw m ; } } while (0) // Log message without trailing new line character (LF)
156158
#define DEBUG_LOG_LEVEL(l, m) do { if (l & DebugLevelMask) { DebugLog m ; } } while (0)
159+
#define DEBUG_LOG_LEVEL_RAW(l, m) do { if (l & DebugLevelMask) { DebugLogRaw m ; } } while (0)
157160
#define DEBUG_ASSERTLOG(c, m) do { { if (!(c)) DebugLog m ; } } while (0)
158161

159162
#else
160163

161164
#define DEBUG_LOG(m) ((void)0)
165+
#define DEBUG_LOG_RAW(m) ((void)0)
162166
#define DEBUG_LOG_LEVEL(l, m) ((void)0)
167+
#define DEBUG_LOG_LEVEL_RAW(l, m) ((void)0)
163168
#define DEBUG_ASSERTLOG(c, m) ((void)0)
164169

165170
#endif

Generals/Code/GameEngine/Source/Common/CommandLine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ static void parseCommandLine(const CommandLineParam* params, int numParams)
14001400
{
14011401
DEBUG_LOG((" %s", argv[arg]));
14021402
}
1403-
DEBUG_LOG((""));
1403+
DEBUG_LOG_RAW(("\n"));
14041404
DebugSetFlags(debugFlags); // turn timestamps back on iff they were on before
14051405
arg = 1;
14061406
#endif // DEBUG_LOGGING

Generals/Code/GameEngine/Source/Common/RTS/PlayerList.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,20 @@ void PlayerList::setLocalPlayer(Player *player)
322322
#ifdef INTENSE_DEBUG
323323
if (player)
324324
{
325-
DEBUG_LOG(("\n----------"));
326325
// did you know? you can use "%ls" to print a doublebyte string, even in a single-byte printf...
327326
DEBUG_LOG(("Switching local players. The new player is named '%ls' (%s) and owns the following objects:",
328327
player->getPlayerDisplayName().str(),
329328
TheNameKeyGenerator->keyToName(player->getPlayerNameKey()).str()
330329
));
331330
for (Object *obj = player->getFirstOwnedObject(); obj; obj = obj->getNextOwnedObject())
332331
{
333-
DEBUG_LOG(("Obj %08lx is of type %s",obj,obj->getTemplate()->getName().str()));
332+
DEBUG_LOG_RAW(("Obj %08lx is of type %s",obj,obj->getTemplate()->getName().str()));
334333
if (!player->canBuild(obj->getTemplate()))
335334
{
336-
DEBUG_LOG((" (NOT BUILDABLE)"));
335+
DEBUG_LOG_RAW((" (NOT BUILDABLE)"));
337336
}
338-
DEBUG_LOG((""));
337+
DEBUG_LOG_RAW(("\n"));
339338
}
340-
DEBUG_LOG(("\n----------"));
341339
}
342340
#endif
343341

Generals/Code/GameEngine/Source/Common/StateMachine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,14 @@ StateReturnType StateMachine::internalSetState( StateID newStateID )
585585
if (m_currentState) {
586586
curState = m_currentState->getID();
587587
}
588-
DEBUG_LOG(("%d '%s' -- '%s' %x exit ", TheGameLogic->getFrame(), m_owner->getTemplate()->getName().str(), m_name.str(), this));
588+
DEBUG_LOG_RAW(("%d '%s' -- '%s' %x exit ", TheGameLogic->getFrame(), m_owner->getTemplate()->getName().str(), m_name.str(), this));
589589
if (m_currentState) {
590-
DEBUG_LOG((" '%s' ", m_currentState->getName().str()));
590+
DEBUG_LOG_RAW((" '%s' ", m_currentState->getName().str()));
591591
} else {
592-
DEBUG_LOG((" INVALID_STATE_ID "));
592+
DEBUG_LOG_RAW((" INVALID_STATE_ID "));
593593
}
594594
if (newState) {
595-
DEBUG_LOG(("enter '%s' ", newState->getName().str()));
595+
DEBUG_LOG(("enter '%s'", newState->getName().str()));
596596
} else {
597597
DEBUG_LOG(("to INVALID_STATE"));
598598
}
@@ -660,7 +660,7 @@ StateReturnType StateMachine::initDefaultState()
660660
{
661661
#ifdef DEBUG_LOGGING
662662
#ifdef STATE_MACHINE_DEBUG
663-
#define REALLY_VERBOSE_LOG(x) /* */
663+
#define REALLY_VERBOSE_LOG(x) /* DEBUG_LOG_RAW(x) */
664664
// Run through all the transitions and make sure there aren't any transitions to undefined states. jba. [8/18/2003]
665665
std::map<StateID, State *>::iterator i;
666666
REALLY_VERBOSE_LOG(("SM_BEGIN\n"));

Generals/Code/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ const char *TheDebugLevels[DEBUG_LEVEL_MAX] = {
128128
// ----------------------------------------------------------------------------
129129
static const char *getCurrentTimeString(void);
130130
static const char *getCurrentTickString(void);
131-
static const char *prepBuffer(const char* format, char *buffer);
131+
static void prepBuffer(char *buffer);
132132
#ifdef DEBUG_LOGGING
133133
static void doLogOutput(const char *buffer);
134+
static void doLogOutput(const char *buffer, const char *endline);
134135
#endif
135136
#ifdef DEBUG_CRASHING
136137
static int doCrashBox(const char *buffer, Bool logResult);
@@ -206,7 +207,7 @@ static const char *getCurrentTickString(void)
206207
Empty the buffer passed in, then optionally prepend the current TickCount
207208
value in string form, depending on the setting of theDebugFlags.
208209
*/
209-
static const char *prepBuffer(const char* format, char *buffer)
210+
static void prepBuffer(char *buffer)
210211
{
211212
buffer[0] = 0;
212213
#ifdef ALLOW_DEBUG_UTILS
@@ -216,7 +217,6 @@ static const char *prepBuffer(const char* format, char *buffer)
216217
strcat(buffer, " ");
217218
}
218219
#endif
219-
return format;
220220
}
221221

222222
// ----------------------------------------------------------------------------
@@ -227,13 +227,18 @@ static const char *prepBuffer(const char* format, char *buffer)
227227
// ----------------------------------------------------------------------------
228228
#ifdef DEBUG_LOGGING
229229
static void doLogOutput(const char *buffer)
230+
{
231+
doLogOutput(buffer, "\n");
232+
}
233+
234+
static void doLogOutput(const char *buffer, const char *endline)
230235
{
231236
// log message to file
232237
if (theDebugFlags & DEBUG_FLAG_LOG_TO_FILE)
233238
{
234239
if (theLogFile)
235240
{
236-
fprintf(theLogFile, "%s\n", buffer);
241+
fprintf(theLogFile, "%s%s", buffer, endline);
237242
fflush(theLogFile);
238243
}
239244
}
@@ -242,14 +247,14 @@ static void doLogOutput(const char *buffer)
242247
if (theDebugFlags & DEBUG_FLAG_LOG_TO_CONSOLE)
243248
{
244249
::OutputDebugString(buffer);
245-
::OutputDebugString("\n");
250+
::OutputDebugString(endline);
246251
}
247252

248253
#ifdef INCLUDE_DEBUG_LOG_IN_CRC_LOG
249-
addCRCDebugLineNoCounter("%s\n", buffer);
254+
addCRCDebugLineNoCounter("%s%s", buffer, endline);
250255
#endif
251256
}
252-
#endif
257+
#endif // DEBUG_LOGGING
253258

254259
// ----------------------------------------------------------------------------
255260
// doCrashBox
@@ -410,7 +415,7 @@ void DebugInit(int flags)
410415
// ----------------------------------------------------------------------------
411416
#ifdef DEBUG_LOGGING
412417
/**
413-
Print a character string to the logfile and/or console.
418+
Print a string to the log file and/or console.
414419
*/
415420
void DebugLog(const char *format, ...)
416421
{
@@ -421,19 +426,44 @@ void DebugLog(const char *format, ...)
421426
if (theDebugFlags == 0)
422427
MessageBoxWrapper("DebugLog - Debug not inited properly", "", MB_OK|MB_TASKMODAL);
423428

424-
format = prepBuffer(format, theBuffer);
429+
prepBuffer(theBuffer);
425430

426-
va_list arg;
427-
va_start(arg, format);
428-
vsprintf(theBuffer + strlen(theBuffer), format, arg);
429-
va_end(arg);
431+
va_list args;
432+
va_start(args, format);
433+
vsprintf(theBuffer + strlen(theBuffer), format, args);
434+
va_end(args);
430435

431436
if (strlen(theBuffer) >= sizeof(theBuffer))
432437
MessageBoxWrapper("String too long for debug buffer", "", MB_OK|MB_TASKMODAL);
433438

434439
whackFunnyCharacters(theBuffer);
435440
doLogOutput(theBuffer);
436-
}
441+
}
442+
443+
/**
444+
Print a string with no modifications to the log file and/or console.
445+
*/
446+
void DebugLogRaw(const char *format, ...)
447+
{
448+
#ifdef DEBUG_THREADSAFE
449+
ScopedCriticalSection scopedCriticalSection(TheDebugLogCriticalSection);
450+
#endif
451+
452+
if (theDebugFlags == 0)
453+
MessageBoxWrapper("DebugLogRaw - Debug not inited properly", "", MB_OK|MB_TASKMODAL);
454+
455+
theBuffer[0] = 0;
456+
457+
va_list args;
458+
va_start(args, format);
459+
vsprintf(theBuffer, format, args);
460+
va_end(args);
461+
462+
if (strlen(theBuffer) >= sizeof(theBuffer))
463+
MessageBoxWrapper("String too long for debug buffer", "", MB_OK|MB_TASKMODAL);
464+
465+
doLogOutput(theBuffer, "");
466+
}
437467

438468
const char* DebugGetLogFileName()
439469
{
@@ -474,7 +504,7 @@ void DebugCrash(const char *format, ...)
474504
MessageBoxWrapper("DebugCrash - Debug not inited properly", "", MB_OK|MB_TASKMODAL);
475505
}
476506

477-
format = prepBuffer(format, theCrashBuffer);
507+
prepBuffer(theCrashBuffer);
478508
strcat(theCrashBuffer, "ASSERTION FAILURE: ");
479509

480510
va_list arg;

Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ void MemoryPoolFactory::debugMemoryReport(Int flags, Int startCheckpoint, Int en
32033203
{
32043204
const char* nm = (this == TheMemoryPoolFactory) ? "TheMemoryPoolFactory" : "*** UNKNOWN *** MemoryPoolFactory";
32053205

3206-
DEBUG_LOG((""));
3206+
DEBUG_LOG_RAW(("\n"));
32073207
DEBUG_LOG(("------------------------------------------"));
32083208
DEBUG_LOG(("Begin Block Report for %s", nm));
32093209
DEBUG_LOG(("------------------------------------------"));

Generals/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ void WriteStackLine(void*address, void (*callback)(const char*))
473473
//*****************************************************************************
474474
void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
475475
{
476-
DEBUG_LOG(( "\n********** EXCEPTION DUMP ****************" ));
476+
DEBUG_LOG_RAW(("\n"));
477+
DEBUG_LOG(( "********** EXCEPTION DUMP ****************" ));
477478
/*
478479
** List of possible exceptions
479480
*/
@@ -622,8 +623,9 @@ void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
622623
}
623624

624625
DOUBLE_DEBUG ( ( (scrap)));
625-
DEBUG_LOG(( "********** END EXCEPTION DUMP ****************\n" ));
626-
}
626+
DEBUG_LOG(( "********** END EXCEPTION DUMP ****************" ));
627+
DEBUG_LOG_RAW(("\n"));
628+
}
627629

628630

629631
#pragma pack(pop)

Generals/Code/GameEngine/Source/GameClient/GameText.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,17 @@ void GameTextManager::deinit( void )
411411

412412
NoString *noString = m_noStringList;
413413

414-
DEBUG_LOG(("\n*** Missing strings ***"));
414+
DEBUG_LOG_RAW(("\n"));
415+
DEBUG_LOG(("*** Missing strings ***"));
415416
while ( noString )
416417
{
417418
DEBUG_LOG(("*** %ls ***", noString->text.str()));
418419
NoString *next = noString->next;
419420
delete noString;
420421
noString = next;
421422
}
422-
DEBUG_LOG(("*** End missing strings ***\n"));
423+
DEBUG_LOG(("*** End missing strings ***"));
424+
DEBUG_LOG_RAW(("\n"));
423425

424426
m_noStringList = NULL;
425427

Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6746,7 +6746,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
67466746
}
67476747
//DEBUG_LOG(("CELL(%d,%d)L%d CD%d CSF %d, CR%d // ",newCell->getXIndex(), newCell->getYIndex(),
67486748
// newCell->getLayer(), clearDiameter, newCostSoFar, costRemaining));
6749-
//if ((cellCount&7)==0) DEBUG_LOG((""));
6749+
//if ((cellCount&7)==0) DEBUG_LOG_RAW(("\n"));
67506750
newCell->setCostSoFar(newCostSoFar);
67516751
// keep track of path we're building - point back to cell we moved here from
67526752
newCell->setParentCell(parentCell) ;

Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,14 @@ StateReturnType AIStateMachine::setTemporaryState( StateID newStateID, Int frame
926926
if (m_temporaryState) {
927927
curState = m_temporaryState->getID();
928928
}
929-
DEBUG_LOG(("%d '%s' -(TEMP)- '%s' %x exit ", TheGameLogic->getFrame(), getOwner()->getTemplate()->getName().str(), getName().str(), this));
929+
DEBUG_LOG_RAW(("%d '%s' -(TEMP)- '%s' %x exit ", TheGameLogic->getFrame(), getOwner()->getTemplate()->getName().str(), getName().str(), this));
930930
if (m_temporaryState) {
931-
DEBUG_LOG((" '%s' ", m_temporaryState->getName().str()));
931+
DEBUG_LOG_RAW((" '%s' ", m_temporaryState->getName().str()));
932932
} else {
933-
DEBUG_LOG((" INVALID_STATE_ID "));
933+
DEBUG_LOG_RAW((" INVALID_STATE_ID "));
934934
}
935935
if (newState) {
936-
DEBUG_LOG(("enter '%s' ", newState->getName().str()));
936+
DEBUG_LOG(("enter '%s'", newState->getName().str()));
937937
} else {
938938
DEBUG_LOG(("to INVALID_STATE"));
939939
}

0 commit comments

Comments
 (0)