/// <summary> /// Set information about the current thread that can be used for logging in log4j: /// - LLE-thread-name: the current thread name /// - LLE-thread-uid: the current thread UID in the format 0x%X /// - LLE-thread: the current thread name and uid /// /// These values can be used in LogSettings.xml inside a PatternLayout: /// <layout class="org.apache.log4j.PatternLayout"> /// <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %5p %8c - %X{LLE-thread} - %m%n" /> /// </layout> /// </summary> public static void setLog4jMDC() { if (!enableReboot) { return; } Processor processor = Emulator.Processor; bool isInterruptContext = processor.cp0.getControlRegister(13) != 0; if (isInterruptContext) { RuntimeContext.Log4jMDC = "Interrupt"; } else { Memory mem = Memory.Instance; int threadManInfo = unchecked ((int)0x88048740); int currentThread = mem.read32(threadManInfo + 0); if (Memory.isAddressGood(currentThread)) { int uid = mem.read32(currentThread + 8); int cb = SysMemForKernel.getCBFromUid(uid); int nameAddr = mem.read32(cb + 16); string name = Utilities.readStringZ(nameAddr); RuntimeContext.setLog4jMDC(name, uid); } else { RuntimeContext.Log4jMDC = "root"; } } }
private static void dumpThread(Memory mem, int address, string comment) { int uid = mem.read32(address + 8); int status = mem.read32(address + 12); int currentPriority = mem.read32(address + 16); StringBuilder waitInfo = new StringBuilder(); if (SceKernelThreadInfo.isWaitingStatus(status)) { int waitType = mem.read32(address + 88); if (waitType != 0) { waitInfo.Append(string.Format(", waitType=0x{0:X}({1})", waitType, SceKernelThreadInfo.getWaitName(waitType))); } int waitTypeCBaddr = mem.read32(address + 92); if (waitTypeCBaddr != 0) { SceSysmemUidCB waitTypeCB = new SceSysmemUidCB(); waitTypeCB.read(mem, waitTypeCBaddr); waitInfo.Append(string.Format(", waitUid=0x{0:X}({1})", waitTypeCB.uid, waitTypeCB.name)); } if (waitType == SceKernelThreadInfo.PSP_WAIT_DELAY) { int waitDelay = mem.read32(address + 96); waitInfo.Append(string.Format(", waitDelay=0x{0:X}", waitDelay)); } else if (waitType == SceKernelThreadInfo.PSP_WAIT_EVENTFLAG) { int bits = mem.read32(address + 96); waitInfo.Append(string.Format(", waitEventFlagBits=0x{0:X}", bits)); } } int cb = SysMemForKernel.getCBFromUid(uid); SceSysmemUidCB sceSysmemUidCB = new SceSysmemUidCB(); sceSysmemUidCB.read(mem, cb); //if (log.DebugEnabled) { Console.WriteLine(string.Format("{0}: uid=0x{1:X}, name='{2}', status=0x{3:X}({4}), currentPriority=0x{5:X}{6}", comment, uid, sceSysmemUidCB.name, status, SceKernelThreadInfo.getStatusName(status), currentPriority, waitInfo)); if (log.TraceEnabled) { log.trace(Utilities.getMemoryDump(address, 0x140)); } } }