From 473f84cbda02e81ccd1fe2bd428aa47265eadda4 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Sat, 3 May 2025 16:17:10 -0700 Subject: [PATCH] flip priority of (handle, id) thread name events; prefer id if it is there, to correctly work with the set-suspended-thread-name-by-ID case --- src/ctrl/ctrl_core.c | 10 +++--- src/lib_raddbg_markup/raddbg_markup.h | 2 +- src/mule/mule_main.cpp | 52 +++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index f38dfc76..c5fce76f 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -1251,15 +1251,15 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) { CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity); - if(thread != &ctrl_entity_nil) - { - ctrl_entity_equip_string(store, thread, event->string); - } - else + if(event->entity_id != 0) { CTRL_Entity *pending_name = ctrl_entity_alloc(store, process, CTRL_EntityKind_PendingThreadName, Arch_Null, ctrl_handle_zero(), event->entity_id); ctrl_entity_equip_string(store, pending_name, event->string); } + else if(thread != &ctrl_entity_nil) + { + ctrl_entity_equip_string(store, thread, event->string); + } }break; case CTRL_EventKind_ThreadColor: { diff --git a/src/lib_raddbg_markup/raddbg_markup.h b/src/lib_raddbg_markup/raddbg_markup.h index 98062318..4b186079 100644 --- a/src/lib_raddbg_markup/raddbg_markup.h +++ b/src/lib_raddbg_markup/raddbg_markup.h @@ -209,7 +209,7 @@ raddbg_encode_utf16(wchar_t *str, unsigned __int32 codepoint) static inline int raddbg_is_attached__impl(void) { - return !!raddbg_is_attached_byte_marker; + return !!raddbg_is_attached_byte_marker[0]; } static inline void diff --git a/src/mule/mule_main.cpp b/src/mule/mule_main.cpp index 36554a68..645ee7cc 100644 --- a/src/mule/mule_main.cpp +++ b/src/mule/mule_main.cpp @@ -451,14 +451,14 @@ type_coverage_eval_tests(void) Has_Enums has_enums = {(Kind)4, (Flag)7}; - Crazy_Union crazy_union = {0}; + Crazy_Union crazy_union = {}; crazy_union.kind = Kind_First; crazy_union.kind = Kind_Second; crazy_union.kind = Kind_Third; crazy_union.kind = Kind_Fourth; - Discriminated_Union discriminated_union = {0}; + Discriminated_Union discriminated_union = {}; discriminated_union.kind = Kind_First; discriminated_union.first.x = 16; @@ -2580,6 +2580,52 @@ debug_string_tests(void) #endif } +//////////////////////////////// +//~ rjf: Thread Name Test + +#if _WIN32 +DWORD dummy_thread(void *p) +{ + Sleep(10); + return 0; +} +#endif + +static void +thread_name_tests(void) +{ +#if _WIN32 + DWORD id = 0; + HANDLE h = CreateThread(0, 0, dummy_thread, 0, CREATE_SUSPENDED, &id); + { +#pragma pack(push, 8) + typedef struct THREADNAME_INFO THREADNAME_INFO; + struct THREADNAME_INFO + { + DWORD dwType; + LPCSTR szName; + DWORD dwThreadID; + DWORD dwFlags; + }; +#pragma pack(pop) + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = "dummy_thread"; + info.dwThreadID = id; + info.dwFlags = 0; + __try + { + RaiseException(0x406D1388, 0, sizeof(info) / sizeof(void *), (const ULONG_PTR *)&info); + } + __except(1) + { + } + } + ResumeThread(h); + WaitForSingleObject(h, INFINITE); +#endif +} + //////////////////////////////// //~ rjf: Interrupt Stepping Tests @@ -2946,6 +2992,8 @@ mule_main(int argc, char** argv) debug_string_tests(); + thread_name_tests(); + jit_stepping_tests(); interrupt_stepping_tests();