Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] Fix debugger support #97213

Merged
merged 27 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6d25912
Update debug level logic
maraf Jan 19, 2024
64708fe
WBT 1
maraf Jan 19, 2024
7bb059f
Fix build
maraf Jan 19, 2024
89f9dd8
Merge remote-tracking branch 'upstream/main' into BrowserDebuggerSupport
maraf Jan 24, 2024
9871731
Build project. Register tests
maraf Jan 24, 2024
2639ec8
Remove default to -1 from common props. Use separate build and publis…
maraf Jan 24, 2024
ff8622b
Switching between build and publish for run
maraf Jan 25, 2024
30595a7
More tests
maraf Jan 25, 2024
3affa88
Remove WasmDebugLevel defaults from WasmApp.Common.targets. Create si…
maraf Jan 25, 2024
0ffcdfe
Add configuration to generated project name
maraf Jan 26, 2024
39191f6
Expect relinked files when doing publish in Release
maraf Jan 26, 2024
310f641
Merge remote-tracking branch 'upstream/main' into BrowserDebuggerSupport
maraf Feb 7, 2024
fa5c5b1
Auto relink only in publish
maraf Feb 7, 2024
550df31
Switch between dotnet run and webserver for hosting Blazor WBT
maraf Feb 7, 2024
f15dc21
Merge remote-tracking branch 'upstream/main' into BrowserDebuggerSupport
maraf Feb 7, 2024
f5645d6
Merge remote-tracking branch 'upstream/main' into BrowserDebuggerSupport
maraf Feb 8, 2024
78f5403
Fix using run for build in SatelliteLoadingTests
maraf Feb 8, 2024
2dcf713
Explicitly set debug level to 0 to trigger tiering
maraf Feb 8, 2024
713719f
Explicitly set debug level to 0 to trigger tiering (put debug level i…
maraf Feb 9, 2024
9d27cf4
Be sure not to fail download twice for the same asset
maraf Feb 9, 2024
ec563c0
Merge remote-tracking branch 'upstream/main' into BrowserDebuggerSupport
maraf Feb 9, 2024
2f8c92b
Don't let missing debugger support override debug level used for logging
maraf Feb 9, 2024
bb28720
Fallback to count of pdbs
maraf Feb 9, 2024
9401db8
Update src/mono/wasi/build/WasiApp.targets
maraf Feb 10, 2024
67c562e
Feedback
maraf Feb 12, 2024
300d782
Feedback
maraf Feb 12, 2024
8e8d100
Fix build
maraf Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Wasm.Build.Tests.WasmTemplateTests
Wasm.Build.Tests.WorkloadTests
Wasm.Build.Tests.TestAppScenarios.DownloadResourceProgressTests
Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests
Wasm.Build.Tests.TestAppScenarios.DebugLevelTests
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface t_Cwraps {
mono_wasm_load_icu_data(offset: VoidPtr): number;
mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number;
mono_wasm_add_satellite_assembly(name: string, culture: string, data: VoidPtr, size: number): void;
mono_wasm_load_runtime(unused: string, debugLevel: number): void;
mono_wasm_load_runtime(debugLevel: number): void;
mono_wasm_change_debugger_log_level(value: number): void;

mono_wasm_assembly_load(name: string): MonoAssembly;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
}

EMSCRIPTEN_KEEPALIVE void
mono_wasm_load_runtime (const char *unused, int debug_level)
mono_wasm_load_runtime (int debug_level)
{
const char *interp_opts = "";

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/lazyLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function loadLazyAssembly(assemblyNameToLoad: string): Promise<bool
}

const pdbNameToLoad = changeExtension(dllAsset.name, ".pdb");
const shouldLoadPdb = loaderHelpers.hasDebuggingEnabled(loaderHelpers.config) && Object.prototype.hasOwnProperty.call(lazyAssemblies, pdbNameToLoad);
const shouldLoadPdb = loaderHelpers.config.debugLevel != 0 && loaderHelpers.isDebuggingSupported() && Object.prototype.hasOwnProperty.call(lazyAssemblies, pdbNameToLoad);

const dllBytesPromise = loaderHelpers.retrieve_asset_download(dllAsset);

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/loader/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export function prepareAssets() {
}
}

if (config.debugLevel != 0 && resources.pdb) {
if (config.debugLevel != 0 && loaderHelpers.isDebuggingSupported() && resources.pdb) {
for (const name in resources.pdb) {
assetsToLoad.push({
name,
Expand Down
12 changes: 2 additions & 10 deletions src/mono/browser/runtime/loader/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ export function normalizeConfig() {
config.environmentVariables["MONO_SLEEP_ABORT_LIMIT"] = "5000";
}

// Default values (when WasmDebugLevel is not set)
// - Build (debug) => debugBuild=true & debugLevel=-1 => -1
// - Build (release) => debugBuild=true & debugLevel=0 => 0
// - Publish (debug) => debugBuild=false & debugLevel=-1 => 0
// - Publish (release) => debugBuild=false & debugLevel=0 => 0
config.debugLevel = hasDebuggingEnabled(config) ? config.debugLevel : 0;

if (BuildConfiguration === "Debug" && config.diagnosticTracing === undefined) {
config.diagnosticTracing = true;
}
Expand Down Expand Up @@ -264,14 +257,13 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi
}
}

export function hasDebuggingEnabled(config: MonoConfigInternal): boolean {
export function isDebuggingSupported(): boolean {
maraf marked this conversation as resolved.
Show resolved Hide resolved
// Copied from blazor MonoDebugger.ts/attachDebuggerHotkey
if (!globalThis.navigator) {
return false;
}

const hasReferencedPdbs = !!config.resources!.pdb;
maraf marked this conversation as resolved.
Show resolved Hide resolved
return (hasReferencedPdbs || config.debugLevel != 0) && (loaderHelpers.isChromium || loaderHelpers.isFirefox);
return loaderHelpers.isChromium || loaderHelpers.isFirefox;
}

async function loadBootConfig(module: DotnetModuleInternal): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/loader/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { assertIsControllablePromise, createPromiseController, getPromiseControl
import { mono_download_assets, resolve_single_asset_path, retrieve_asset_download } from "./assets";
import { mono_log_error, set_thread_prefix, setup_proxy_console } from "./logging";
import { invokeLibraryInitializers } from "./libraryInitializers";
import { deep_merge_config, hasDebuggingEnabled } from "./config";
import { deep_merge_config, isDebuggingSupported } from "./config";
import { logDownloadStatsToConsole, purgeUnusedCacheEntriesAsync } from "./assetsCache";

// if we are the first script loaded in the web worker, we are expected to become the sidecar
Expand Down Expand Up @@ -118,9 +118,9 @@ export function setLoaderGlobals(
purgeUnusedCacheEntriesAsync,
installUnhandledErrorHandler,

hasDebuggingEnabled,
retrieve_asset_download,
invokeLibraryInitializers,
isDebuggingSupported,

// from wasm-feature-detect npm package
exceptions,
Expand Down
10 changes: 7 additions & 3 deletions src/mono/browser/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ async function start_runtime() {
if (runtimeHelpers.config.browserProfilerOptions)
mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions);

mono_wasm_load_runtime("unused", runtimeHelpers.config.debugLevel);
mono_wasm_load_runtime();

if (runtimeHelpers.config.interpreterPgo)
setTimeout(maybeSaveInterpPgoTable, (runtimeHelpers.config.interpreterPgoSaveDelay || 15) * 1000);
Expand All @@ -534,17 +534,21 @@ async function maybeSaveInterpPgoTable() {
await interp_pgo_save_data();
}

export function mono_wasm_load_runtime(unused?: string, debugLevel?: number): void {
export function mono_wasm_load_runtime(): void {
mono_log_debug("mono_wasm_load_runtime");
try {
const mark = startMeasure();
let debugLevel = runtimeHelpers.config.debugLevel;
if (debugLevel == undefined) {
debugLevel = 0;
if (runtimeHelpers.config.debugLevel) {
debugLevel = 0 + debugLevel;
}
}
cwraps.mono_wasm_load_runtime(unused || "unused", debugLevel);
if (!loaderHelpers.isDebuggingSupported() || !runtimeHelpers.config.resources!.pdb) {
debugLevel = 0;
}
cwraps.mono_wasm_load_runtime(debugLevel);
endMeasure(mark, MeasuredBlock.loadRuntime);

} catch (err: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export type LoaderHelpers = {
out(message: string): void;
err(message: string): void;

hasDebuggingEnabled(config: MonoConfig): boolean,
retrieve_asset_download(asset: AssetEntry): Promise<ArrayBuffer>;
onDownloadResourceProgress?: (resourcesLoaded: number, totalResources: number) => void;
logDownloadStatsToConsole: () => void;
Expand All @@ -166,6 +165,7 @@ export type LoaderHelpers = {
invokeLibraryInitializers: (functionName: string, args: any[]) => Promise<void>,
libraryInitializers?: { scriptName: string, exports: any }[];

isDebuggingSupported(): boolean,
isChromium: boolean,
isFirefox: boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache)</_BlazorWebAssemblyStartupMemoryCache>
<_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter)</_BlazorWebAssemblyJiterpreter>
<_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions)</_BlazorWebAssemblyRuntimeOptions>
<_WasmDebugLevel>$(WasmDebugLevel)</_WasmDebugLevel>
<_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0</_WasmDebugLevel>
<_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == '0' and ('$(DebuggerSupport)' == 'true' or '$(Configuration)' == 'Debug')">-1</_WasmDebugLevel>

<!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
<PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
Expand Down Expand Up @@ -364,7 +361,7 @@ Copyright (c) .NET Foundation. All rights reserved.
AssemblyPath="@(IntermediateAssembly)"
Resources="@(_WasmOutputWithHash)"
DebugBuild="true"
DebugLevel="$(_WasmDebugLevel)"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="false"
CacheBootResources="$(BlazorCacheBootResources)"
OutputPath="$(_WasmBuildBootJsonPath)"
Expand All @@ -380,7 +377,8 @@ Copyright (c) .NET Foundation. All rights reserved.
Extensions="@(WasmBootConfigExtension)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)"
IsPublish="false" />

<ItemGroup>
<FileWrites Include="$(_WasmBuildBootJsonPath)" />
Expand Down Expand Up @@ -533,7 +531,6 @@ Copyright (c) .NET Foundation. All rights reserved.
</Target>

<Target Name="GeneratePublishWasmBootJson" DependsOnTargets="$(GeneratePublishWasmBootJsonDependsOn)">

<ItemGroup>
<_WasmPublishAsset
Include="@(StaticWebAsset)"
Expand All @@ -549,7 +546,6 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- We remove the extensions since they are added to the list of static web assets but we need to compute the target path for them -->
<_WasmPublishAsset Remove="@(_BlazorExtensionsCandidatesForPublish)" />

</ItemGroup>

<ComputeStaticWebAssetsTargetPaths
Expand All @@ -568,7 +564,7 @@ Copyright (c) .NET Foundation. All rights reserved.
AssemblyPath="@(IntermediateAssembly)"
Resources="@(_WasmPublishBootResourceWithHash)"
DebugBuild="false"
DebugLevel="$(_WasmDebugLevel)"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="$(PublishTrimmed)"
CacheBootResources="$(BlazorCacheBootResources)"
OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json"
Expand All @@ -584,7 +580,8 @@ Copyright (c) .NET Foundation. All rights reserved.
Extensions="@(WasmBootConfigExtension)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)"
IsPublish="true" />

<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)blazor.publish.boot.json" />
Expand Down
7 changes: 6 additions & 1 deletion src/mono/wasi/build/WasiApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
Outputs="$(WasmAppDir)\.stamp"
Condition="'$(WasmGenerateAppBundle)' == 'true'">

<PropertyGroup>
<_WasmOutputSymbolsToAppBundle Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(_IsPublishing)' == 'true'">true</_WasmOutputSymbolsToAppBundle>
<_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == ''">false</_WasmOutputSymbolsToAppBundle>
</PropertyGroup>

<WasiAppBuilder
AppDir="$(WasmAppDir)"
Assemblies="@(_WasmAssembliesInternal)"
Expand All @@ -80,7 +85,7 @@
FilesToIncludeInFileSystem="@(WasmFilesToIncludeInFileSystem)"
ExtraFilesToDeploy="@(WasmExtraFilesToDeploy)"
NativeAssets="@(WasmNativeAsset)"
DebugLevel="$(WasmDebugLevel)"
OutputSymbolsToAppBundle="$(_WasmOutputSymbolsToAppBundle)"
RuntimeConfigJsonPath="$(_WasmRuntimeConfigFilePath)"
/>
</Target>
Expand Down
6 changes: 6 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public string CreateBlazorWasmTemplateProject(string id)
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);

if (options.ExpectSuccess && options.AssertAppBundle)
{
AssertBundle(res.Output, options with { IsPublish = false });
}

return (res, logPath);
}
Expand All @@ -77,6 +79,10 @@ public string CreateBlazorWasmTemplateProject(string id)

if (options.ExpectSuccess && options.AssertAppBundle)
{
// Because we do relink in Release publish by default
if (options.Config == "Release")
options = options with { ExpectedFileType = NativeFilesType.Relinked };

AssertBundle(res.Output, options with { IsPublish = true });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)

string id = $"browser_{config}_{GetRandomId()}";
_testOutput.WriteLine("/// Creating project");
string projectFile = CreateWasmTemplateProject(id, "wasmbrowser");
string projectFile = CreateWasmTemplateProject(id, "wasmbrowser", extraProperties: "<WasmDebugLevel>0</WasmDebugLevel>");

_testOutput.WriteLine("/// Updating JS");
UpdateBrowserMainJs((js) => {
Expand All @@ -53,6 +53,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
// then call INTERNAL.interp_pgo_save_data() to save the interp PGO table
js = js.Replace(
"const text = exports.MyClass.Greeting();",
"console.log(`WASM debug level ${getConfig().debugLevel}`);\n" +
"let text = '';\n" +
$"for (let i = 0; i < {iterationCount}; i++) {{ text = exports.MyClass.Greeting(); }};\n" +
"await INTERNAL.interp_pgo_save_data();"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task LoadAppSettingsBasedOnApplicationEnvironment(string applicatio
CopyTestAsset("WasmBasicTestApp", "AppSettingsTests");
PublishProject("Debug");

var result = await RunSdkStyleApp(new(
var result = await RunSdkStyleAppForPublish(new(
Configuration: "Debug",
TestScenario: "AppSettingsTest",
BrowserQueryString: new Dictionary<string, string> { ["applicationEnvironment"] = applicationEnvironment }
Expand Down
21 changes: 14 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,29 @@ protected void CopyTestAsset(string assetName, string generatedProjectNamePrefix
_projectDir = Path.Combine(_projectDir!, "App");
}

protected void BuildProject(string configuration)
protected void BuildProject(string configuration, params string[] extraArgs)
{
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(Id, configuration));
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(Id, configuration), extraArgs);
result.EnsureSuccessful();
}

protected void PublishProject(string configuration)
protected void PublishProject(string configuration, params string[] extraArgs)
{
(CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(Id, configuration));
(CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(Id, configuration), extraArgs);
result.EnsureSuccessful();
}

protected ToolCommand CreateDotNetCommand() => new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir);

protected async Task<RunResult> RunSdkStyleApp(RunOptions options)
protected Task<RunResult> RunSdkStyleAppForBuild(RunOptions options)
=> RunSdkStyleApp(options, BlazorRunHost.DotnetRun);

protected Task<RunResult> RunSdkStyleAppForPublish(RunOptions options)
=> RunSdkStyleApp(options, BlazorRunHost.WebServer);

private async Task<RunResult> RunSdkStyleApp(RunOptions options, BlazorRunHost host = BlazorRunHost.DotnetRun)
{
string queryString = "?test=" + options.TestScenario;
if (options.BrowserQueryString != null)
Expand All @@ -67,9 +73,10 @@ protected async Task<RunResult> RunSdkStyleApp(RunOptions options)
CheckCounter: false,
Config: options.Configuration,
OnConsoleMessage: OnConsoleMessage,
QueryString: queryString);
QueryString: queryString,
Host: host);

await BlazorRunForBuildWithDotnetRun(blazorRunOptions);
await BlazorRunTest(blazorRunOptions);

void OnConsoleMessage(IConsoleMessage msg)
{
Expand Down
Loading
Loading