diff options
author | Ankit Jain <radical@gmail.com> | 2022-05-13 04:59:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 04:59:59 +0300 |
commit | c26475cd413dc40ce95d57e45795d890b6571760 (patch) | |
tree | 812c814c97423d88eb399b39263b581eacf867e9 /src/mono/wasm/runtime | |
parent | 4751154cea730251d3870e91668bda06a1a2c7ae (diff) |
[wasm] Misc debugger improvements (#68988)
* [wasm] Move the browser provisioning stuff to a new targets file
.. from `DebuggerTestSuite.csproj`. This will allow other projects to
use this too.
* [wasm][debugger] Handle failure to connect to the browser
* [wasm] Improve the browser path lookup
so it can be used outside the debugger tests project too. For example,
with Wasm.Build.Tests+playwright .
* [wasm][debugger] Throw exceptions from tasks correctly
.. using `ExceptionDispatchInfo.Capture` so we get the original stack
trace.
* [wasm][debugger] General improvements in debug proxy
- like logging
- updated API to make it easier to use by other projects, like the
upcoming wasm-app-host .
* [wasm][debugger] Add support for setting an automatic breakpoint
.. on the first line of the entrypoint method (`Main`). This will be
useful for debugging with the upcoming wasm-app-host, along with the use
of `wait-for-debugger`.
Implemented by @thaystg .
* [wasm][debugger] Add support for wait_for_debugger
If requested, then it will cause invocation of `main` to be delayed till
a debugger is attached.
Implemented by @thaystg
* [wasm] Cleanup in Wasm.Build.Tests
.. in the lead up to wasm-app-host tests.
* [wasm] Update the default paths used to trigger builds on CI
.. to include templates, and provisioning props.
* disable non-wasm builds
* [wasm][debugger] Fix path to artifacts dir
* [wasm] Emit message with bundle path
* [wasm][templates] Make the project use the target dir's name as the
.. project name, instead of always creating `browser.dll`, and
`console.dll`.
* [wasm][debugger] Use a single static instance of HttpClient
.. as recommended by the documentation.
* Revert "disable non-wasm builds"
This reverts commit 7b8b60d58c886e7e66cf2fea910f1feb4d6374f1.
* Address review feedback, and improve the autogenerated bpid
Diffstat (limited to 'src/mono/wasm/runtime')
-rw-r--r-- | src/mono/wasm/runtime/debug.ts | 18 | ||||
-rw-r--r-- | src/mono/wasm/runtime/dotnet.d.ts | 1 | ||||
-rw-r--r-- | src/mono/wasm/runtime/exports.ts | 2 | ||||
-rw-r--r-- | src/mono/wasm/runtime/run.ts | 8 | ||||
-rw-r--r-- | src/mono/wasm/runtime/startup.ts | 1 | ||||
-rw-r--r-- | src/mono/wasm/runtime/types.ts | 4 |
6 files changed, 31 insertions, 3 deletions
diff --git a/src/mono/wasm/runtime/debug.ts b/src/mono/wasm/runtime/debug.ts index a6115177040..7a702f2053e 100644 --- a/src/mono/wasm/runtime/debug.ts +++ b/src/mono/wasm/runtime/debug.ts @@ -142,10 +142,26 @@ export function mono_wasm_raise_debug_event(event: WasmEvent, args = {}): void { // Used by the debugger to enumerate loaded dlls and pdbs export function mono_wasm_get_loaded_files(): string[] { - cwraps.mono_wasm_set_is_debugger_attached(true); return MONO.loaded_files; } +export function mono_wasm_wait_for_debugger(): Promise<void> { + return new Promise<void>((resolve) => { + const interval = setInterval(() => { + if (runtimeHelpers.wait_for_debugger != 1) { + return; + } + clearInterval(interval); + resolve(); + }, 100); + }); +} + +export function mono_wasm_debugger_attached(): void { + runtimeHelpers.wait_for_debugger = 1; + cwraps.mono_wasm_set_is_debugger_attached(true); +} + function _create_proxy_from_object_id(objectId: string, details: any) { if (objectId.startsWith("dotnet:array:")) { let ret: Array<any>; diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index 0a4a8d48e8e..e31742188e5 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -153,6 +153,7 @@ declare type MonoConfig = { aot_profiler_options?: AOTProfilerOptions; coverage_profiler_options?: CoverageProfilerOptions; ignore_pdb_load_errors?: boolean; + wait_for_debugger?: number; }; declare type MonoConfigError = { isError: true; diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 064ddcfa214..66fe698af5d 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -27,6 +27,7 @@ import { mono_wasm_change_debugger_log_level, mono_wasm_symbolicate_string, mono_wasm_stringify_as_error_with_stack, + mono_wasm_debugger_attached, } from "./debug"; import { ENVIRONMENT_IS_WEB, ExitStatusError, runtimeHelpers, setImportsAndExports } from "./imports"; import { DotnetModuleConfigImports, DotnetModule } from "./types"; @@ -387,6 +388,7 @@ const INTERNAL: any = { mono_wasm_detach_debugger, mono_wasm_raise_debug_event, mono_wasm_change_debugger_log_level, + mono_wasm_debugger_attached, mono_wasm_runtime_is_ready: runtimeHelpers.mono_wasm_runtime_is_ready, }; diff --git a/src/mono/wasm/runtime/run.ts b/src/mono/wasm/runtime/run.ts index 492188352e9..85c4c8e4dfc 100644 --- a/src/mono/wasm/runtime/run.ts +++ b/src/mono/wasm/runtime/run.ts @@ -1,5 +1,6 @@ -import { ExitStatus, INTERNAL, Module, quit } from "./imports"; +import { ExitStatus, INTERNAL, Module, quit, runtimeHelpers } from "./imports"; import { mono_call_assembly_entry_point } from "./method-calls"; +import { mono_wasm_wait_for_debugger } from "./debug"; import { mono_wasm_set_main_args, runtime_is_initialized_reject } from "./startup"; export async function mono_run_main_and_exit(main_assembly_name: string, args: string[]): Promise<void> { @@ -14,8 +15,13 @@ export async function mono_run_main_and_exit(main_assembly_name: string, args: s } } + export async function mono_run_main(main_assembly_name: string, args: string[]): Promise<number> { mono_wasm_set_main_args(main_assembly_name, args); + if (runtimeHelpers.wait_for_debugger == -1) { + console.log("waiting for debugger..."); + return await mono_wasm_wait_for_debugger().then(() => mono_call_assembly_entry_point(main_assembly_name, [args], "m")); + } return mono_call_assembly_entry_point(main_assembly_name, [args], "m"); } diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts index c183e882391..a24b168e845 100644 --- a/src/mono/wasm/runtime/startup.ts +++ b/src/mono/wasm/runtime/startup.ts @@ -324,6 +324,7 @@ function finalize_startup(config: MonoConfig | MonoConfigError | undefined): voi mono_wasm_globalization_init(config.globalization_mode!, config.diagnostic_tracing!); cwraps.mono_wasm_load_runtime("unused", config.debug_level || 0); + runtimeHelpers.wait_for_debugger = config.wait_for_debugger; } catch (err: any) { Module.printErr("MONO_WASM: mono_wasm_load_runtime () failed: " + err); Module.printErr("MONO_WASM: Stacktrace: \n"); diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts index 2b85e899538..db3834c11c0 100644 --- a/src/mono/wasm/runtime/types.ts +++ b/src/mono/wasm/runtime/types.ts @@ -78,7 +78,8 @@ export type MonoConfig = { runtime_options?: string[], // array of runtime options as strings aot_profiler_options?: AOTProfilerOptions, // dictionary-style Object. If omitted, aot profiler will not be initialized. coverage_profiler_options?: CoverageProfilerOptions, // dictionary-style Object. If omitted, coverage profiler will not be initialized. - ignore_pdb_load_errors?: boolean + ignore_pdb_load_errors?: boolean, + wait_for_debugger ?: number }; export type MonoConfigError = { @@ -152,6 +153,7 @@ export type RuntimeHelpers = { loaded_files: string[]; config: MonoConfig | MonoConfigError; + wait_for_debugger?: number; fetch: (url: string) => Promise<Response>; } |