VERY experimental Nintendo Switch 2 emulator
C++
Kernel: Introduce unique Object ids for debugging
Yuri Kunde Schlesner869ec46683c5
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex d7fa4dcea0..a2459e7b10 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -14,6 +14,8 @@namespace Kernel {+unsigned int Object::next_object_id = 0;+SharedPtr<Thread> g_main_thread = nullptr;HandleTable g_handle_table;u64 g_program_id = 0;diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex 9860479ac7..5567780fe5 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -67,6 +67,9 @@ public:virtual ~Object() {}Handle GetHandle() const { return handle; }+ /// Returns a unique identifier for the object. For debugging purposes only.+ unsigned int GetObjectId() const { return object_id; }+virtual std::string GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; }virtual std::string GetName() const { return "[UNKNOWN KERNEL OBJECT]"; }virtual Kernel::HandleType GetHandleType() const = 0;@@ -101,7 +104,10 @@ private:friend void intrusive_ptr_add_ref(Object*);friend void intrusive_ptr_release(Object*);+ static unsigned int next_object_id;+unsigned int ref_count = 0;+ unsigned int object_id = next_object_id++;};// Special functions used by boost::instrusive_ptr to do automatic ref-countingdiff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cppindex eff68d4816..b586c99030 100644--- a/src/core/hle/kernel/shared_memory.cpp+++ b/src/core/hle/kernel/shared_memory.cpp@@ -23,8 +23,8 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,MemoryPermission other_permissions) {if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) {- LOG_ERROR(Kernel, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!",- GetHandle(), address);+ LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!",+ GetObjectId(), address);// TODO: Verify error code with hardwarereturn ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,ErrorSummary::InvalidArgument, ErrorLevel::Permanent);@@ -41,7 +41,7 @@ ResultVal<u8*> SharedMemory::GetPointer(u32 offset) {if (base_address != 0)return MakeResult<u8*>(Memory::GetPointer(base_address + offset));- LOG_ERROR(Kernel_SVC, "memory block handle=0x%08X not mapped!", GetHandle());+ LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId());// TODO(yuriks): Verify error code.return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,ErrorSummary::InvalidState, ErrorLevel::Permanent);diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 72a14bfac6..2fae1b3bc8 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -326,11 +326,11 @@ static void DebugThreadQueue() {if (!thread) {return;}- LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle());+ LOG_DEBUG(Kernel, "0x%02X %u (current)", thread->current_priority, GetCurrentThread()->GetObjectId());for (auto& t : thread_list) {s32 priority = thread_ready_queue.contains(t.get());if (priority != -1) {- LOG_DEBUG(Kernel, "0x%02X 0x%08X", priority, t->GetHandle());+ LOG_DEBUG(Kernel, "0x%02X %u", priority, t->GetObjectId());}}}@@ -459,13 +459,13 @@ void Reschedule() {HLE::g_reschedule = false;if (next != nullptr) {- LOG_TRACE(Kernel, "context switch 0x%08X -> 0x%08X", prev->GetHandle(), next->GetHandle());+ LOG_TRACE(Kernel, "context switch %u -> %u", prev->GetObjectId(), next->GetObjectId());SwitchContext(next);} else {- LOG_TRACE(Kernel, "cannot context switch from 0x%08X, no higher priority thread!", prev->GetHandle());+ LOG_TRACE(Kernel, "cannot context switch from %u, no higher priority thread!", prev->GetObjectId());for (auto& thread : thread_list) {- LOG_TRACE(Kernel, "\thandle=0x%08X prio=0x%02X, status=0x%08X", thread->GetHandle(),+ LOG_TRACE(Kernel, "\tid=%u prio=0x%02X, status=0x%08X", thread->GetObjectId(),thread->current_priority, thread->status);}}