From 074113fbb904b9aee042809e2a21ddac912deea3 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Fri, 26 May 2023 14:42:57 -0700 Subject: [PATCH] Fix gcroot test failures The SOS DataReader impl given to clrmd didn't copy the thread context correctly. A future PR will improve the IThread.GetThreadContext() interface method to reduce these kind of bugs. --- .../DataReader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs index 89716bf326..ba1ecc6d21 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs @@ -55,10 +55,10 @@ bool IDataReader.GetThreadContext(uint threadId, uint contextFlags, Span c try { byte[] registerContext = ThreadService.GetThreadFromId(threadId).GetThreadContext(); - context = new Span(registerContext); + registerContext.AsSpan().Slice(0, context.Length).CopyTo(context); return true; } - catch (DiagnosticsException ex) + catch (Exception ex) when (ex is DiagnosticsException or ArgumentException) { Trace.TraceError($"GetThreadContext: {threadId} exception {ex.Message}"); }