Log sys_lwmutex/sys_lwcond names as strings

Use std::string_view instead of creating a temporary NTS string when reading object name.
This commit is contained in:
Eladash 2020-03-17 09:59:28 +02:00 committed by Ivan
parent a9f492b605
commit 03a6d67c6c
6 changed files with 30 additions and 34 deletions

View File

@ -18,7 +18,7 @@ error_code sys_lwcond_create(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, vm::
attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED; attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attrs->name_u64 = attr->name_u64; attrs->name_u64 = attr->name_u64;
if (auto res = g_cfg.core.hle_lwmutex ? sys_cond_create(ppu, out_id, lwmutex->sleep_queue, attrs) : _sys_lwcond_create(ppu, out_id, lwmutex->sleep_queue, lwcond, attr->name_u64, 0)) if (auto res = g_cfg.core.hle_lwmutex ? sys_cond_create(ppu, out_id, lwmutex->sleep_queue, attrs) : _sys_lwcond_create(ppu, out_id, lwmutex->sleep_queue, lwcond, attr->name_u64))
{ {
return res; return res;
} }

View File

@ -9,11 +9,11 @@
LOG_CHANNEL(sys_lwcond); LOG_CHANNEL(sys_lwcond);
error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmutex_id, vm::ptr<sys_lwcond_t> control, u64 name, u32 arg5) error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmutex_id, vm::ptr<sys_lwcond_t> control, u64 name)
{ {
vm::temporary_unlock(ppu); vm::temporary_unlock(ppu);
sys_lwcond.warning("_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx, arg5=0x%x)", lwcond_id, lwmutex_id, control, name, arg5); sys_lwcond.warning(u8"_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx (“%s”))", lwcond_id, lwmutex_id, control, name, lv2_obj::name64(name));
u32 protocol; u32 protocol;

View File

@ -48,7 +48,7 @@ class ppu_thread;
// Syscalls // Syscalls
error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmutex_id, vm::ptr<sys_lwcond_t> control, u64 name, u32 arg5); error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmutex_id, vm::ptr<sys_lwcond_t> control, u64 name);
error_code _sys_lwcond_destroy(ppu_thread& ppu, u32 lwcond_id); error_code _sys_lwcond_destroy(ppu_thread& ppu, u32 lwcond_id);
error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 ppu_thread_id, u32 mode); error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 ppu_thread_id, u32 mode);
error_code _sys_lwcond_signal_all(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 mode); error_code _sys_lwcond_signal_all(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 mode);

View File

@ -12,7 +12,7 @@ error_code _sys_lwmutex_create(ppu_thread& ppu, vm::ptr<u32> lwmutex_id, u32 pro
{ {
vm::temporary_unlock(ppu); vm::temporary_unlock(ppu);
sys_lwmutex.warning("_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx)", lwmutex_id, protocol, control, has_name, name); sys_lwmutex.warning(u8"_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx (“%s”))", lwmutex_id, protocol, control, has_name, name, lv2_obj::name64(name));
if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_RETRY && protocol != SYS_SYNC_PRIORITY) if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_RETRY && protocol != SYS_SYNC_PRIORITY)
{ {

View File

@ -14,6 +14,7 @@
#include <deque> #include <deque>
#include <thread> #include <thread>
#include <string_view>
// attr_protocol (waiting scheduling policy) // attr_protocol (waiting scheduling policy)
enum enum
@ -75,6 +76,18 @@ private:
public: public:
static std::string_view name64(const u64& name_u64)
{
std::string_view str{reinterpret_cast<const char*>(&name_u64), 7};
if (const auto pos = str.find_first_of('\0'); pos != umax)
{
str.remove_suffix(str.size() - pos);
}
return str;
};
// Find and remove the object from the container (deque or vector) // Find and remove the object from the container (deque or vector)
template <typename T, typename E> template <typename T, typename E>
static bool unqueue(std::deque<T*>& queue, const E& object) static bool unqueue(std::deque<T*>& queue, const E& object)

View File

@ -75,23 +75,6 @@ void kernel_explorer::Update()
root->setText(0, qstr(fmt::format("Process, ID = 0x00000001, Total Memory Usage = 0x%x (%0.2f MB)", total_memory_usage, 1.f * total_memory_usage / (1024 * 1024)))); root->setText(0, qstr(fmt::format("Process, ID = 0x00000001, Total Memory Usage = 0x%x (%0.2f MB)", total_memory_usage, 1.f * total_memory_usage / (1024 * 1024))));
m_tree->addTopLevelItem(root); m_tree->addTopLevelItem(root);
union name64
{
u64 u64_data;
char string[8];
name64(u64 data)
: u64_data(data)
{
string[7] = '\0';
}
const char* operator+() const
{
return string;
}
};
// TODO: FileSystem // TODO: FileSystem
struct lv2_obj_rec struct lv2_obj_rec
@ -149,21 +132,21 @@ void kernel_explorer::Update()
case SYS_MUTEX_OBJECT: case SYS_MUTEX_OBJECT:
{ {
auto& mutex = static_cast<lv2_mutex&>(obj); auto& mutex = static_cast<lv2_mutex&>(obj);
l_addTreeChild(node, qstr(fmt::format("Mutex: ID = 0x%08x \"%s\",%s Owner = 0x%x, Locks = %u, Conds = %u, Wq = %zu", id, +name64(mutex.name), l_addTreeChild(node, qstr(fmt::format(u8"Mutex: ID = 0x%08x “%s”,%s Owner = 0x%x, Locks = %u, Conds = %u, Wq = %zu", id, lv2_obj::name64(mutex.name),
mutex.recursive == SYS_SYNC_RECURSIVE ? " Recursive," : "", mutex.owner >> 1, +mutex.lock_count, +mutex.cond_count, mutex.sq.size()))); mutex.recursive == SYS_SYNC_RECURSIVE ? " Recursive," : "", mutex.owner >> 1, +mutex.lock_count, +mutex.cond_count, mutex.sq.size())));
break; break;
} }
case SYS_COND_OBJECT: case SYS_COND_OBJECT:
{ {
auto& cond = static_cast<lv2_cond&>(obj); auto& cond = static_cast<lv2_cond&>(obj);
l_addTreeChild(node, qstr(fmt::format("Cond: ID = 0x%08x \"%s\", Waiters = %u", id, +name64(cond.name), +cond.waiters))); l_addTreeChild(node, qstr(fmt::format(u8"Cond: ID = 0x%08x “%s”, Waiters = %u", id, lv2_obj::name64(cond.name), +cond.waiters)));
break; break;
} }
case SYS_RWLOCK_OBJECT: case SYS_RWLOCK_OBJECT:
{ {
auto& rw = static_cast<lv2_rwlock&>(obj); auto& rw = static_cast<lv2_rwlock&>(obj);
const s64 val = rw.owner; const s64 val = rw.owner;
l_addTreeChild(node, qstr(fmt::format("RW Lock: ID = 0x%08x \"%s\", Owner = 0x%x(%d), Rq = %zu, Wq = %zu", id, +name64(rw.name), l_addTreeChild(node, qstr(fmt::format(u8"RW Lock: ID = 0x%08x “%s”, Owner = 0x%x(%d), Rq = %zu, Wq = %zu", id, lv2_obj::name64(rw.name),
std::max<s64>(0, val >> 1), -std::min<s64>(0, val >> 1), rw.rq.size(), rw.wq.size()))); std::max<s64>(0, val >> 1), -std::min<s64>(0, val >> 1), rw.rq.size(), rw.wq.size())));
break; break;
} }
@ -182,7 +165,7 @@ void kernel_explorer::Update()
case SYS_EVENT_QUEUE_OBJECT: case SYS_EVENT_QUEUE_OBJECT:
{ {
auto& eq = static_cast<lv2_event_queue&>(obj); auto& eq = static_cast<lv2_event_queue&>(obj);
l_addTreeChild(node, qstr(fmt::format("Event Queue: ID = 0x%08x \"%s\", %s, Key = %#llx, Events = %zu/%d, Waiters = %zu", id, +name64(eq.name), l_addTreeChild(node, qstr(fmt::format(u8"Event Queue: ID = 0x%08x “%s”, %s, Key = %#llx, Events = %zu/%d, Waiters = %zu", id, lv2_obj::name64(eq.name),
eq.type == SYS_SPU_QUEUE ? "SPU" : "PPU", eq.key, eq.events.size(), eq.size, eq.sq.size()))); eq.type == SYS_SPU_QUEUE ? "SPU" : "PPU", eq.key, eq.events.size(), eq.size, eq.sq.size())));
break; break;
} }
@ -222,7 +205,7 @@ void kernel_explorer::Update()
case SYS_LWMUTEX_OBJECT: case SYS_LWMUTEX_OBJECT:
{ {
auto& lwm = static_cast<lv2_lwmutex&>(obj); auto& lwm = static_cast<lv2_lwmutex&>(obj);
l_addTreeChild(node, qstr(fmt::format("LWMutex: ID = 0x%08x \"%s\", Wq = %zu", id, +name64(lwm.name), lwm.sq.size()))); l_addTreeChild(node, qstr(fmt::format(u8"LWMutex: ID = 0x%08x “%s”, Wq = %zu", id, lv2_obj::name64(lwm.name), lwm.sq.size())));
break; break;
} }
case SYS_TIMER_OBJECT: case SYS_TIMER_OBJECT:
@ -234,20 +217,20 @@ void kernel_explorer::Update()
case SYS_SEMAPHORE_OBJECT: case SYS_SEMAPHORE_OBJECT:
{ {
auto& sema = static_cast<lv2_sema&>(obj); auto& sema = static_cast<lv2_sema&>(obj);
l_addTreeChild(node, qstr(fmt::format("Semaphore: ID = 0x%08x \"%s\", Count = %d, Max Count = %d, Waiters = %#zu", id, +name64(sema.name), l_addTreeChild(node, qstr(fmt::format(u8"Semaphore: ID = 0x%08x “%s”, Count = %d, Max Count = %d, Waiters = %#zu", id, lv2_obj::name64(sema.name),
sema.val.load(), sema.max, sema.sq.size()))); sema.val.load(), sema.max, sema.sq.size())));
break; break;
} }
case SYS_LWCOND_OBJECT: case SYS_LWCOND_OBJECT:
{ {
auto& lwc = static_cast<lv2_lwcond&>(obj); auto& lwc = static_cast<lv2_lwcond&>(obj);
l_addTreeChild(node, qstr(fmt::format("LWCond: ID = 0x%08x \"%s\", Waiters = %zu", id, +name64(lwc.name), +lwc.waiters))); l_addTreeChild(node, qstr(fmt::format(u8"LWCond: ID = 0x%08x “%s”, Waiters = %zu", id, lv2_obj::name64(lwc.name), +lwc.waiters)));
break; break;
} }
case SYS_EVENT_FLAG_OBJECT: case SYS_EVENT_FLAG_OBJECT:
{ {
auto& ef = static_cast<lv2_event_flag&>(obj); auto& ef = static_cast<lv2_event_flag&>(obj);
l_addTreeChild(node, qstr(fmt::format("Event Flag: ID = 0x%08x \"%s\", Type = 0x%x, Pattern = 0x%llx, Wq = %zu", id, +name64(ef.name), l_addTreeChild(node, qstr(fmt::format(u8"Event Flag: ID = 0x%08x “%s”, Type = 0x%x, Pattern = 0x%llx, Wq = %zu", id, lv2_obj::name64(ef.name),
ef.type, ef.pattern.load(), +ef.waiters))); ef.type, ef.pattern.load(), +ef.waiters)));
break; break;
} }
@ -271,7 +254,7 @@ void kernel_explorer::Update()
idm::select<named_thread<ppu_thread>>([&](u32 id, ppu_thread& ppu) idm::select<named_thread<ppu_thread>>([&](u32 id, ppu_thread& ppu)
{ {
lv2_types.back().count++; lv2_types.back().count++;
l_addTreeChild(lv2_types.back().node, qstr(fmt::format("PPU Thread: ID = 0x%08x '%s'", id, *ppu.ppu_tname.load()))); l_addTreeChild(lv2_types.back().node, qstr(fmt::format(u8"PPU Thread: ID = 0x%08x “%s”", id, *ppu.ppu_tname.load())));
}); });
lv2_types.emplace_back(l_addTreeChild(root, "SPU Threads")); lv2_types.emplace_back(l_addTreeChild(root, "SPU Threads"));
@ -279,7 +262,7 @@ void kernel_explorer::Update()
idm::select<named_thread<spu_thread>>([&](u32 /*id*/, spu_thread& spu) idm::select<named_thread<spu_thread>>([&](u32 /*id*/, spu_thread& spu)
{ {
lv2_types.back().count++; lv2_types.back().count++;
l_addTreeChild(lv2_types.back().node, qstr(fmt::format("SPU Thread: ID = 0x%08x '%s'", spu.lv2_id, *spu.spu_tname.load()))); l_addTreeChild(lv2_types.back().node, qstr(fmt::format(u8"SPU Thread: ID = 0x%08x “%s”", spu.lv2_id, *spu.spu_tname.load())));
}); });
lv2_types.emplace_back(l_addTreeChild(root, "SPU Thread Groups")); lv2_types.emplace_back(l_addTreeChild(root, "SPU Thread Groups"));
@ -287,7 +270,7 @@ void kernel_explorer::Update()
idm::select<lv2_spu_group>([&](u32 id, lv2_spu_group& tg) idm::select<lv2_spu_group>([&](u32 id, lv2_spu_group& tg)
{ {
lv2_types.back().count++; lv2_types.back().count++;
l_addTreeChild(lv2_types.back().node, qstr(fmt::format("SPU Thread Group: ID = 0x%08x '%s'", id, tg.name))); l_addTreeChild(lv2_types.back().node, qstr(fmt::format(u8"SPU Thread Group: ID = 0x%08x “%s”", id, tg.name)));
}); });
lv2_types.emplace_back(l_addTreeChild(root, "File Descriptors")); lv2_types.emplace_back(l_addTreeChild(root, "File Descriptors"));
@ -295,7 +278,7 @@ void kernel_explorer::Update()
idm::select<lv2_fs_object>([&](u32 id, lv2_fs_object& fo) idm::select<lv2_fs_object>([&](u32 id, lv2_fs_object& fo)
{ {
lv2_types.back().count++; lv2_types.back().count++;
l_addTreeChild(lv2_types.back().node, qstr(fmt::format("FD: ID = 0x%08x '%s'", id, fo.name.data()))); l_addTreeChild(lv2_types.back().node, qstr(fmt::format(u8"FD: ID = 0x%08x “%s”", id, fo.name.data())));
}); });
for (auto&& entry : lv2_types) for (auto&& entry : lv2_types)