From f4ff60bcbdd43f4a8c6af3c9836a58306a793471 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 25 Aug 2021 10:37:52 -0700 Subject: [PATCH] Fixing DebuggerDisplayAttribute when using utf16 characters. Fixes #58046 (#58087) Co-authored-by: Thays --- src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs | 6 ++++-- src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs | 6 ++++-- .../debugger/tests/debugger-test/debugger-custom-view-test.cs | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index 4182153..eb7d078 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -17,6 +17,7 @@ using System.Text.RegularExpressions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp; using System.Reflection; +using System.Text; namespace Microsoft.WebAssembly.Diagnostics { @@ -397,9 +398,10 @@ namespace Microsoft.WebAssembly.Diagnostics public override string ReadString() { var valueLen = ReadInt32(); - char[] value = new char[valueLen]; + byte[] value = new byte[valueLen]; Read(value, 0, valueLen); - return new string(value); + + return new string(Encoding.UTF8.GetChars(value, 0, valueLen)); } public unsafe long ReadLong() { diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs index fa188b1..3a85823 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs @@ -17,7 +17,7 @@ namespace DebuggerTests [Fact] public async Task UsingDebuggerDisplay() { - var bp = await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.DebuggerCustomViewTest", "run", 12); + var bp = await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.DebuggerCustomViewTest", "run", 15); var pause_location = await EvaluateAndCheck( "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.DebuggerCustomViewTest:run'); }, 1);", "dotnet://debugger-test.dll/debugger-custom-view-test.cs", @@ -29,12 +29,14 @@ namespace DebuggerTests CheckObject(locals, "a", "DebuggerTests.WithDisplayString", description:"Some one Value 2 End"); CheckObject(locals, "c", "DebuggerTests.DebuggerDisplayMethodTest", description: "First Int:32 Second Int:43"); CheckObject(locals, "myList", "System.Collections.Generic.List", description: "Count = 4"); + CheckObject(locals, "person1", "DebuggerTests.Person", description: "FirstName: Anton, SurName: Mueller, Age: 44"); + CheckObject(locals, "person2", "DebuggerTests.Person", description: "FirstName: Lisa, SurName: Müller, Age: 41"); } [Fact] public async Task UsingDebuggerTypeProxy() { - var bp = await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.DebuggerCustomViewTest", "run", 12); + var bp = await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.DebuggerCustomViewTest", "run", 15); var pause_location = await EvaluateAndCheck( "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.DebuggerCustomViewTest:run'); }, 1);", "dotnet://debugger-test.dll/debugger-custom-view-test.cs", diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-custom-view-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-custom-view-test.cs index bd25c49..a218411 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-custom-view-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-custom-view-test.cs @@ -58,6 +58,13 @@ namespace DebuggerTests } } + [DebuggerDisplay("FirstName: {FirstName}, SurName: {SurName}, Age: {Age}")] + public class Person { + public string FirstName { get; set; } + public string SurName { get; set; } + public int Age { get; set; } + } + class DebuggerCustomViewTest { public static void run() @@ -73,6 +80,9 @@ namespace DebuggerTests openWith.Add("txt", "notepad"); openWith.Add("bmp", "paint"); openWith.Add("dib", "paint"); + var person1 = new Person { FirstName = "Anton", SurName="Mueller", Age = 44}; + var person2 = new Person { FirstName = "Lisa", SurName="Müller", Age = 41}; + Console.WriteLine("break here"); Console.WriteLine("break here"); -- 2.7.4