Fixing DebuggerDisplayAttribute when using utf16 characters. Fixes #58046 (#58087)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Wed, 25 Aug 2021 17:37:52 +0000 (10:37 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Aug 2021 17:37:52 +0000 (10:37 -0700)
Co-authored-by: Thays <thaystg@gmail.com>
src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs
src/mono/wasm/debugger/tests/debugger-test/debugger-custom-view-test.cs

index 4182153..eb7d078 100644 (file)
@@ -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()
         {
index fa188b1..3a85823 100644 (file)
@@ -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<int>", 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",
index bd25c49..a218411 100644 (file)
@@ -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");