Skip to content

Commit

Permalink
Fixing DebuggerDisplayAttribute when using utf16 characters. (#58084)
Browse files Browse the repository at this point in the history
Fixes #58046
  • Loading branch information
thaystg committed Aug 25, 2021
1 parent e910860 commit d40fbf4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp;
using System.Reflection;
using System.Text;

namespace Microsoft.WebAssembly.Diagnostics
{
Expand Down Expand Up @@ -397,9 +398,10 @@ internal static unsafe void PutBytesBE (byte *dest, byte *src, int count)
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()
{
Expand Down
6 changes: 4 additions & 2 deletions src/mono/wasm/debugger/DebuggerTestSuite/CustomViewTests.cs
Expand Up @@ -17,7 +17,7 @@ public class CustomViewTests : DebuggerTestBase
[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",
Expand All @@ -29,12 +29,14 @@ public async Task UsingDebuggerDisplay()
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",
Expand Down
Expand Up @@ -58,6 +58,13 @@ string GetDebuggerDisplay ()
}
}

[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()
Expand All @@ -73,6 +80,9 @@ public static void run()
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");
Expand Down

0 comments on commit d40fbf4

Please sign in to comment.