From 1ef04f8a08d96192a610d580a865b269bf2d9203 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Fri, 24 Apr 2020 06:52:31 -0400 Subject: [PATCH] Prevent a possible assert in the debugger when a thread detaches (#34955) When a new thread is attached to the VM, the debugger will add it to the `thread_to_tls` hash table. When that thread detaches, it will be removed. Once the thread is attached, if a client is debugging, the client can use the `CMD_THREAD_GET_FRAME_INFO` command to ask for details about that thread. This is a possibility that the thread detaches before the `CMD_THREAD_GET_FRAME_INFO` command is processed, so the thread may not exist the the `thread_to_tls` hash table any more. This is a race condition, but is a valid state, so instead of asserting, the debugger agent should indicate to the client that the thread no longer exists, using `ERR_UNLOADED`. --- src/mono/mono/mini/debugger-agent.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/debugger-agent.c b/src/mono/mono/mini/debugger-agent.c index 3742cc0..a46f622 100644 --- a/src/mono/mono/mini/debugger-agent.c +++ b/src/mono/mono/mini/debugger-agent.c @@ -9135,7 +9135,8 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf) mono_loader_lock (); tls = (DebuggerTlsData *)mono_g_hash_table_lookup (thread_to_tls, thread); mono_loader_unlock (); - g_assert (tls); + if (tls == NULL) + return ERR_UNLOADED; compute_frame_info (thread, tls, TRUE); //the last parameter is TRUE to force that the frame info that will be send is synchronised with the debugged thread -- 2.7.4