|
| 1 | +# Debugging |
| 2 | + |
| 3 | +Debugging is one of the most important parts of application development. This section describes debugging tools compatible with SwiftWasm. |
| 4 | + |
| 5 | +These tools are DWARF-based, so you need to build your application with DWARF sections enabled. |
| 6 | +If you are using `carton bundle`, you can use the `--debug-info` flag to enable debugging with optimized application. |
| 7 | +If you are using `swift build`, it is enabled by default. |
| 8 | + |
| 9 | +## Chrome DevTools |
| 10 | + |
| 11 | +When you are debugging a web browser application, Chrome DevTools is a good tool to use. It allows you to |
| 12 | +put breakpoints, step through at Swift source code level. |
| 13 | + |
| 14 | +Please follow the steps below to configure Chrome DevTools for SwiftWasm: |
| 15 | + |
| 16 | +1. Install [`C/C++ DevTools Support (DWARF)`](https://goo.gle/wasm-debugging-extension) extension in your Chrome |
| 17 | +2. Enable `WebAssembly Debugging: Enable DWARF support` in `Experiments` pane of DevTools settings |
| 18 | + |
| 19 | +See [the DevTools team's official introduction](https://developer.chrome.com/blog/wasm-debugging-2020) for more details about the extension. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +Note that the function names in the stack trace are mangled. You can demangle them using `swift demangle` command. |
| 24 | + |
| 25 | +Unfortunately, variable inspection is unavailable since Swift depends on its own mechanisms to do that instead of DWARF's structure type feature. (See [this thread](https://github.com/swiftwasm/swift/issues/593) for more details) |
| 26 | + |
| 27 | +## [wasminspect](https://github.com/kateinoigakukun/wasminspect) |
| 28 | + |
| 29 | +[wasminspect](https://github.com/kateinoigakukun/wasminspect) |
| 30 | +can help in the investigation if the debugged binary does not rely on integration with JavaScript. |
| 31 | +We recommend splitting your packages into separate executable targets, most of which shouldn't |
| 32 | +assume the availability of JavaScript to make debugging easier. |
| 33 | + |
| 34 | + |
0 commit comments