Skip to content

Commit e05de8f

Browse files
committed
Creating a test case for PR dotnet#59773
But I'm not using Uint8Array to set the content on memory allocated using malloc as @lewing suggested in the same PR.
1 parent 3e79767 commit e05de8f

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,47 @@ await EvaluateAndCheck(
860860
);
861861
}
862862

863+
[Fact]
864+
public async Task MallocUntilReallocate() //https://github.com/xamarin/xamarin-android/issues/6161
865+
{
866+
string eval_expr = "window.setTimeout(function() { malloc_to_reallocate_test (); }, 1)";
867+
868+
var result = await cli.SendCommand("Runtime.evaluate", JObject.FromObject(new { expression = eval_expr }), token);
869+
870+
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
871+
872+
var eval_req = JObject.FromObject(new
873+
{
874+
expression = "window.setTimeout(function() { invoke_add(); }, 1);",
875+
});
876+
877+
await EvaluateAndCheck(
878+
"window.setTimeout(function() { invoke_add(); }, 1);",
879+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
880+
"IntAdd",
881+
wait_for_event_fn: (pause_location) =>
882+
{
883+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
884+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
885+
886+
var top_frame = pause_location["callFrames"][0];
887+
Assert.Equal("IntAdd", top_frame["functionName"].Value<string>());
888+
Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
889+
890+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, top_frame["functionLocation"]);
891+
892+
//now check the scope
893+
var scope = top_frame["scopeChain"][0];
894+
Assert.Equal("local", scope["type"]);
895+
Assert.Equal("IntAdd", scope["name"]);
896+
897+
Assert.Equal("object", scope["object"]["type"]);
898+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, scope["startLocation"]);
899+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 14, 4, scripts, scope["endLocation"]);
900+
return Task.CompletedTask;
901+
}
902+
);
903+
}
863904
//TODO add tests covering basic stepping behavior as step in/out/over
864905
}
865906
}

src/mono/wasm/debugger/tests/debugger-test/other.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ function get_properties_test () {
9595

9696
console.log(`break here`);
9797
}
98+
99+
function malloc_to_reallocate_test () {
100+
var _debugger_buffer = Module._malloc(500000000);
101+
}

src/mono/wasm/runtime/base64.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,4 @@ function _makeByteReader(bytes: Uint8Array, index?: number, count?: number): {
107107
});
108108

109109
return result;
110-
}
111-
112-
// FIXME: improve
113-
export function _base64_to_uint8(base64String: string):Uint8Array {
114-
const byteCharacters = atob(base64String);
115-
const byteNumbers = new Array(byteCharacters.length);
116-
for (let i = 0; i < byteCharacters.length; i++) {
117-
byteNumbers[i] = byteCharacters.charCodeAt(i);
118-
}
119-
120-
return new Uint8Array(byteNumbers);
121110
}

src/mono/wasm/runtime/debug.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import { Module, runtimeHelpers } from "./modules";
5-
import { toBase64StringImpl, _base64_to_uint8 } from "./base64";
5+
import { toBase64StringImpl } from "./base64";
66
import cwraps from "./cwraps";
77

88
let commands_received: CommandResponse;
99
let _call_function_res_cache: any = {};
1010
let _next_call_function_res_id = 0;
1111
let _debugger_buffer_len = -1;
1212
let _debugger_buffer: VoidPtr;
13-
let _debugger_heap_bytes: Uint8Array;
1413

1514
export function mono_wasm_runtime_ready(): void {
1615
runtimeHelpers.mono_wasm_runtime_is_ready = true;
@@ -52,9 +51,10 @@ function mono_wasm_malloc_and_set_debug_buffer(command_parameters: string) {
5251
_debugger_buffer_len = Math.max(command_parameters.length, _debugger_buffer_len, 256);
5352
_debugger_buffer = Module._malloc(_debugger_buffer_len);
5453
}
55-
//reset _debugger_heap_bytes because Module.HEAPU8.buffer can be reallocated
56-
_debugger_heap_bytes = new Uint8Array(Module.HEAPU8.buffer, <any>_debugger_buffer, _debugger_buffer_len);
57-
_debugger_heap_bytes.set(_base64_to_uint8(command_parameters));
54+
const byteCharacters = atob(command_parameters);
55+
for (let i = 0; i < byteCharacters.length; i++) {
56+
Module.setValue(<any>_debugger_buffer + i, byteCharacters.charCodeAt(i), "i8");
57+
}
5858
}
5959

6060
export function mono_wasm_send_dbg_command_with_parms(id: number, command_set: number, command: number, command_parameters: string, length: number, valtype: number, newvalue: number): CommandResponseResult {

0 commit comments

Comments
 (0)