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

[dart2wasm] Better debugging support #55763

Closed
felix-ht opened this issue May 17, 2024 · 6 comments
Closed

[dart2wasm] Better debugging support #55763

felix-ht opened this issue May 17, 2024 · 6 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler.

Comments

@felix-ht
Copy link

felix-ht commented May 17, 2024

Add debugging capabilities to the dart tooling so we can easily debug wasm code, from within our IDEs.

There doesn't seem to be a good way to debug dart code that has been complied to wasm. I can set break points in the complied wasm code, but because there are no source maps this is quite useless, so i am back to debugging with strings.

@lrhn lrhn added the area-dart2wasm Issues for the dart2wasm compiler. label May 19, 2024
@mkustermann
Copy link
Member

For fast turnaround during development of apps in Dart for web we recommend to use DDC. Dart2wasm is (similar to dart2js) for deploying apps.

That being said if one has to debug issues that only happen with dart2wasm compiled apps, I can recommend using the -O0 flag (flutter build web --wasm -O0 / dart compile wasm -O0 ) which will turn off optimizations and keeps static symbol names, does not minify runtime type names, etc.

Additionally we do plan on offering source maps support (@osa1 is working on it atm)

@felix-ht
Copy link
Author

That was exactly the issue, JS is running fine, but i got lots of issues after compling to wasm.

Thanks for the info on the flags!

@mkustermann
Copy link
Member

That was exactly the issue, JS is running fine, but i got lots of issues after compling to wasm.

If you run into any issues in our compilers, libraries etc, please don't hesitate to reach out!

@uldall
Copy link

uldall commented May 24, 2024

I am trying to build our Flutter application with wasm support:
$ flutter build web --wasm -O0

I am however getting this error:

Target dart2wasm failed: ProcessException: Process exited abnormally with exit code 64:
Unhandled exception:
Constant InstanceConstant(const _FfiAbiSpecificMapping{_FfiAbiSpecificMapping.nativeTypes: const <Type?>[Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32,
Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32]}) references field _FfiAbiSpecificMapping.nativeTypes which is not retained
#0      _TreeShakerConstantVisitor.visitInstanceConstant.<anonymous closure> (package:vm/transformations/type_flow/transformer.dart:2274)
#1      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633)
#2      _TreeShakerConstantVisitor.visitInstanceConstant (package:vm/transformations/type_flow/transformer.dart:2272)
#3      InstanceConstant.accept (package:kernel/ast.dart:13982)
#4      _TreeShakerConstantVisitor.analyzeConstant (package:vm/transformations/type_flow/transformer.dart:2207)
#5      _TreeShakerConstantVisitor.visitInstanceConstant.<anonymous closure> (package:vm/transformations/type_flow/transformer.dart:2277)
#6      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633)
#7      _TreeShakerConstantVisitor.visitInstanceConstant (package:vm/transformations/type_flow/transformer.dart:2272)
#8      InstanceConstant.accept (package:kernel/ast.dart:13982)
#9      _TreeShakerConstantVisitor.analyzeConstant (package:vm/transformations/type_flow/transformer.dart:2207)
#10     _TreeShakerPass1.visitConstant (package:vm/transformations/type_flow/transformer.dart:1580)
#11     ConstantExpression.transformOrRemoveChildren (package:kernel/ast.dart:8651)
#12     RemovingTransformer.defaultTreeNode (package:kernel/visitor.dart:2164)
#13     TreeVisitor1Default.defaultExpression (package:kernel/visitor.dart:739)
#14     ExpressionVisitor1DefaultMixin.visitConstantExpression (package:kernel/visitor.dart:2368)
#15     ConstantExpression.accept1 (package:kernel/ast.dart:8635)
#16     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#17     RemovingTransformer.transformList (package:kernel/visitor.dart:2141)
#18     RemovingTransformer.transformExpressionList (package:kernel/visitor.dart:2067)
#19     TreeShaker.addClassUsedInType (package:vm/transformations/type_flow/transformer.dart:897)
#20     _TreeShakerTypeVisitor.visitInterfaceType (package:vm/transformations/type_flow/transformer.dart:1120)
#21     InterfaceType.accept (package:kernel/ast.dart:11473)
#22     visitList (package:kernel/ast.dart:14751)
#23     FunctionType.visitChildren (package:kernel/ast.dart:11583)
#24     RecursiveVisitor.defaultNode (package:kernel/visitor.dart:1725)
#25     VisitorDefaultMixin.visitSupertype (package:kernel/visitor.dart:1501)
#26     DartTypeVisitorDefaultMixin.visitInvalidType (package:kernel/visitor.dart:781)
#27     FunctionType.accept (package:kernel/ast.dart:11574)
#28     visitList (package:kernel/ast.dart:14751)
#29     InterfaceType.visitChildren (package:kernel/ast.dart:11482)
#30     _TreeShakerTypeVisitor.visitInterfaceType (package:vm/transformations/type_flow/transformer.dart:1121)
#31     InterfaceType.accept (package:kernel/ast.dart:11473)
#32     visitList (package:kernel/ast.dart:14751)
#33     InterfaceType.visitChildren (package:kernel/ast.dart:11482)
#34     _TreeShakerTypeVisitor.visitInterfaceType (package:vm/transformations/type_flow/transformer.dart:1121)
#35     InterfaceType.accept (package:kernel/ast.dart:11473)
#36     _TreeShakerPass1.visitDartType (package:vm/transformations/type_flow/transformer.dart:1269)
#37     VariableDeclaration.transformOrRemoveChildren (package:kernel/ast.dart:10745)
#38     RemovingTransformer.defaultTreeNode (package:kernel/visitor.dart:2164)
#39     TreeVisitor1Default.defaultExpression (package:kernel/visitor.dart:739)
#40     StatementVisitor1DefaultMixin.visitVariableDeclaration (package:kernel/visitor.dart:2597)
#41     VariableDeclaration.accept1 (package:kernel/ast.dart:10723)
#42     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#43     RemovingTransformer.transformList (package:kernel/visitor.dart:2141)
#44     RemovingTransformer.transformStatementList (package:kernel/visitor.dart:2095)
#45     AssertBlock.transformOrRemoveChildren (package:kernel/ast.dart:9239)
#46     RemovingTransformer.defaultTreeNode (package:kernel/visitor.dart:2164)
#47     TreeVisitor1Default.defaultExpression (package:kernel/visitor.dart:739)
#48     StatementVisitor1DefaultMixin.visitBlock (package:kernel/visitor.dart:2546)
#49     Block.accept1 (package:kernel/ast.dart:9178)
#50     RemovingTransformer.transform (package:kernel/visitor.dart:1881)
#51     BlockExpression.transformOrRemoveChildren (package:kernel/ast.dart:8781)
#52     RemovingTransformer.defaultTreeNode (package:kernel/visitor.dart:2164)
#53     TreeVisitor1Default.defaultExpression (package:kernel/visitor.dart:739)
#54     ExpressionVisitor1DefaultMixin.visitBlockExpression (package:kernel/visitor.dart:2402)
#55     BlockExpression.accept1 (package:kernel/ast.dart:8763)
#56     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#57     RemovingTransformer.transformOrRemoveExpression (package:kernel/visitor.dart:1890)
#58     Field.transformOrRemoveChildren (package:kernel/ast.dart:2549)
#59     _TreeShakerPass1.visitField (package:vm/transformations/type_flow/transformer.dart:1341)
#60     Field.accept1 (package:kernel/ast.dart:2520)
#61     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#62     RemovingTransformer.transformList (package:kernel/visitor.dart:2141)
#63     RemovingTransformer.transformFieldList (package:kernel/visitor.dart:2041)
#64     _TreeShakerPass1.visitClass (package:vm/transformations/type_flow/transformer.dart:1307)
#65     Class.accept1 (package:kernel/ast.dart:1476)
#66     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#67     RemovingTransformer.transformList (package:kernel/visitor.dart:2141)
#68     RemovingTransformer.transformClassList (package:kernel/visitor.dart:1996)
#69     Library.transformOrRemoveChildren (package:kernel/ast.dart:626)
#70     RemovingTransformer.defaultTreeNode (package:kernel/visitor.dart:2164)
#71     TreeVisitor1DefaultMixin.visitLibrary (package:kernel/visitor.dart:680)
#72     Library.accept1 (package:kernel/ast.dart:592)
#73     RemovingTransformer.transformOrRemove (package:kernel/visitor.dart:1917)
#74     RemovingTransformer.transformList (package:kernel/visitor.dart:2141)
#75     RemovingTransformer.transformLibraryList (package:kernel/visitor.dart:1960)
#76     Component.transformOrRemoveChildren (package:kernel/ast.dart:14617)
#77     _TreeShakerPass1.transformComponent (package:vm/transformations/type_flow/transformer.dart:1178)
#78     TreeShaker.transformComponent (package:vm/transformations/type_flow/transformer.dart:848)
#79     transformComponent (package:vm/transformations/type_flow/transformer.dart:136)
#80     compileToModule (package:dart2wasm/compile.dart:166)
<asynchronous suspension>
#81     generateWasm (package:dart2wasm/generate_wasm.dart:23)
<asynchronous suspension>
#82     main (file:///b/s/w/ir/x/w/sdk/pkg/dart2wasm/bin/dart2wasm.dart:10)
<asynchronous suspension>
  Command: /home/cup/snap/flutter/common/flutter/bin/cache/dart-sdk/bin/dart compile wasm --packages=.dart_tool/package_config.json
  --extra-compiler-option=--dart-sdk=/home/cup/snap/flutter/common/flutter/bin/cache/dart-sdk
  --extra-compiler-option=--platform=/home/cup/snap/flutter/common/flutter/bin/cache/flutter_web_sdk/kernel/dart2wasm_platform.dill
  --extra-compiler-option=--delete-tostring-package-uri=dart:ui --extra-compiler-option=--delete-tostring-package-uri=package:flutter --extra-compiler-option=--import-shared-memory
  --extra-compiler-option=--shared-memory-max-pages=32768 -Ddart.vm.product=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/4ab44247522322094511fbc271fb828bb31bd072/ -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=false
  -DFLUTTER_WEB_USE_SKWASM=true --extra-compiler-option=--depfile=/media/cup/data/git/zoolander/.dart_tool/flutter_build/ce5be2d647610cff5873f737118dcfff/dart2wasm.d -O0 --no-name-section -o
  /media/cup/data/git/zoolander/.dart_tool/flutter_build/ce5be2d647610cff5873f737118dcfff/main.dart.wasm
  /media/cup/data/git/zoolander/.dart_tool/flutter_build/ce5be2d647610cff5873f737118dcfff/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:122:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:318:19)
<asynchronous suspension>
#2      Dart2WasmTarget.build (package:flutter_tools/src/build_system/targets/web.dart:329:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:867:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:805:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:805:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:634:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:92:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:230:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1396:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:372:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:308:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:93:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                             43.2s
Error: Failed to compile application for the Web.

Any ideas on how I can debug this?

@mkustermann
Copy link
Member

@uldall Right now dart:ffi is not really supported in dart2wasm. It was somewhat available but not entirely functional. After cl/368343 lands we'll report an error when user code imports dart:ffi. dart:ffi support for the web is tracked at #46690

@mkustermann
Copy link
Member

I'm going to close this in favor of the older #55229.

copybara-service bot pushed a commit that referenced this issue Jul 19, 2024
This implements generating source maps for the generated Wasm files.

Copying dart2js's command line interface, a source map file with the
name `<program name>.wasm.map` is generated unless `--no-source-maps` is
passed.

When a source map is generated, the generated .wasm file gets a new
section `sourceMappingURL` with the contents `<program name>.wasm.map`.

This section seems to be undocumented, but Chrome and binaryen recognize
it as the URI to the source map file. Chrome is then loads it
automatically in the DevTools.

- `wasm_builder` package is updated with the new `source_map` library,
  which describes the source mapping entries.

- `wasm_builder`'s `InstructionsBuilder` is updated with the new public
  members:

  - `startSourceMapping`: starts mapping the instructions generated to
    the given source code.

  - `stopSourceMapping`: stops mapping the instructions generated to a
    source code. These instructions won't have a mapping in the source
    map.

- `CodeGenerator` sets the source file URI and location in the file
  when:

  - Starting compiling a new member
  - Compiling an expression and statement

Bug: #55763
Change-Id: Ieb24796b4b17a735b846793617664a453f1061ce
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/370500
Cherry-pick-request: #56239
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375660
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler.
Projects
None yet
Development

No branches or pull requests

4 participants