WebAssembly provides a way to run, for example, C/C++ code on the web at near native speed and alongside JavaScript. This document shows how to set up and use Chrome DevTools to better debug such applications.
Once you set up DevTools, you can:
.wasm
binary file.And, while paused, you can:
To enable C/C++ WebAssembly debugging in DevTools:
Compile your application with DWARF debug information included. Run the latest Emscripten compiler and pass it the -g
flag. For example:
emcc-gsource.cc-oapp.html
For more information, see Building projects with debug information.
Install the C/C++ DevTools Support (DWARF) Chrome extension.
With DevTools set up, debug your code:
-g
flag.mandelbrot.cc
.To set a line-of-code breakpoint, click a line number in the column to the left of the Editor, for example, on line 38.
Run the code again. The execution pauses before the line with the breakpoint.
While paused, try the following:
In Console, output variables and objects that are hard to navigate to in Scope:
->
). Expand them to inspect.With DevTools set up and open, the code Chrome runs isn't optimized. It's tiered down to give you better debugging experience.
In this case, you can't rely on console.time()
and performance.now()
in your code to profile performance. Instead, use the Performance panel to profile.
Alternatively, you can run your profiling code without opening DevTools, then open it to inspect the messages in the Console.
To speed up loading but still have a better debugging experience, you can split out the debug information into a separate .wasm
file. For more information, see Debugging WebAssembly Faster.
You can either keep this file locally or host it on a separate server. To do it with Emscripten, pass the -gseparate-dwarf=<filename>
flag and specify the path to the file:
emcc-gsource.cc-oapp.html\-gseparate-dwarf=temp.debug.wasm\-sSEPARATE_DWARF_URL=[file://local/path/to/temp.debug.wasm]|[URL]
If you build on a machine with a different operating system (container, VM, or remote server) than that on the machine you run Chrome on, you may need to manually map the debug file paths.
For example, if your project is at C:\src\project
locally but was built in a Docker container with the path /mnt/c/src/project
, do the following:
chrome://extensions/
, find the C/C++ DevTools Support (DWARF) extension, and click Details > Extension options.Check out the Chrome DevTools engineering blog for more information on WebAssembly debugging:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-06-07 UTC.