Show the current thread name in the log file.

This is very useful, although it kinda entwines the logging a bit
more than might be desired.
This commit is contained in:
Unknown W. Brackets 2013-03-10 22:25:03 -07:00
parent f5bb835dcb
commit 118050485f
4 changed files with 44 additions and 7 deletions

View File

@ -26,6 +26,9 @@
#include <e32debug.h>
#endif
// Don't need to savestate this.
const char *hleCurrentThreadName = NULL;
// Unfortunately this is quite slow.
#define LOG_MSC_OUTPUTDEBUG false
// #define LOG_MSC_OUTPUTDEBUG true
@ -169,11 +172,30 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
char formattedTime[13];
Common::Timer::GetTimeFormatted(formattedTime);
#ifdef _WIN32
const char *fileshort = strrchr(file, '\\');
#else
const char *fileshort = strrchr(file, '/');
#endif
if (fileshort != NULL)
file = fileshort + 1;
char *msgPos = msg;
msgPos += sprintf(msgPos, "%s %s:%d %c[%s]: ",
formattedTime,
file, line, level_to_char[(int)level],
log->GetShortName());
if (hleCurrentThreadName != NULL)
{
msgPos += sprintf(msgPos, "%s %-12.12s %c[%s]: %s:%d ",
formattedTime,
hleCurrentThreadName, level_to_char[(int)level],
log->GetShortName(),
file, line);
}
else
{
msgPos += sprintf(msgPos, "%s %s:%d %c[%s]: ",
formattedTime,
file, line, level_to_char[(int)level],
log->GetShortName());
}
msgPos += vsnprintf(msgPos, MAX_MSGLEN, format, args);
// This will include the null terminator.

View File

@ -30,6 +30,7 @@
#define MAX_MESSAGES 8000
#define MAX_MSGLEN 1024
extern const char *hleCurrentThreadName;
// pure virtual interface
class LogListener

View File

@ -20,6 +20,7 @@
#include <queue>
#include <algorithm>
#include "Common/LogManager.h"
#include "HLE.h"
#include "HLETables.h"
#include "../MIPS/MIPSInt.h"
@ -684,6 +685,8 @@ void __KernelThreadingDoState(PointerWrap &p)
p.Do(actionAfterCallback);
__KernelRestoreActionType(actionAfterCallback, ActionAfterCallback::Create);
hleCurrentThreadName = __KernelGetThreadName(currentThread);
p.DoMarker("sceKernelThread");
}
@ -833,6 +836,7 @@ void __KernelThreadingShutdown()
currentThread = 0;
intReturnHackAddr = 0;
curModule = 0;
hleCurrentThreadName = NULL;
}
const char *__KernelGetThreadName(SceUID threadID)
@ -1202,7 +1206,10 @@ u32 __KernelDeleteThread(SceUID threadID, int exitStatus, const char *reason, bo
__KernelTriggerWait(WAITTYPE_THREADEND, threadID, exitStatus, reason, dontSwitch);
if (currentThread == threadID)
{
currentThread = 0;
hleCurrentThreadName = NULL;
}
if (currentCallbackThreadID == threadID)
{
currentCallbackThreadID = 0;
@ -1426,6 +1433,7 @@ void __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int pr
if (prevThread && prevThread->isRunning())
__KernelChangeReadyState(currentThread, true);
currentThread = id;
hleCurrentThreadName = "root";
thread->nt.status = THREADSTATUS_RUNNING; // do not schedule
strcpy(thread->nt.name, "root");
@ -2360,12 +2368,18 @@ void __KernelSwitchContext(Thread *target, const char *reason)
__KernelChangeReadyState(cur, oldUID, true);
}
currentThread = target->GetUID();
if (target)
{
currentThread = target->GetUID();
hleCurrentThreadName = target->nt.name;
__KernelChangeReadyState(target, currentThread, false);
target->nt.status = (target->nt.status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY;
}
else
{
currentThread = 0;
hleCurrentThreadName = NULL;
}
__KernelLoadContext(&target->context);
@ -2374,7 +2388,7 @@ void __KernelSwitchContext(Thread *target, const char *reason)
if (!(fromIdle && toIdle))
{
DEBUG_LOG(HLE,"Context switched: %s -> %s (%s) (%i - pc: %08x -> %i - pc: %08x)",
oldName, target->GetName(),
oldName, hleCurrentThreadName,
reason,
oldUID, oldPC, currentThread, currentMIPS->pc);
}

View File

@ -24,7 +24,6 @@
#include "sceKernelModule.h"
#include "HLE.h"
void sceKernelChangeThreadPriority();
int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr);
int sceKernelCreateThread(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr);
@ -116,6 +115,7 @@ KernelObject *__KernelCallbackObject();
void __KernelScheduleWakeup(int threadnumber, s64 usFromNow);
SceUID __KernelGetCurThread();
const char *__KernelGetThreadName(SceUID threadID);
void __KernelSaveContext(ThreadContext *ctx);
void __KernelLoadContext(ThreadContext *ctx);