From 6f7b81c8f34416ba4c0577e8e5d0a0518bf91e21 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 30 Oct 2020 22:55:46 +0000 Subject: [PATCH] Add a section on sourceMappingURL (#151) A follow-up to #149. See #148. --- Debugging.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Debugging.md b/Debugging.md index c894130..2cb7176 100644 --- a/Debugging.md +++ b/Debugging.md @@ -24,3 +24,22 @@ a Wasm container, which includes DWARF in Wasm custom sections, in the same format as they would appear normally in a Wasm file. Note that the container may also contain other sections, such as the code and data sections in the original Wasm file. + +# Source maps + +Adoption of DWARF is a fairly recent addition to WebAssembly, and many toolchains still +support [Source Map](https://sourcemaps.info/spec.html) based debugging as well (or instead). + +Source map is an external JSON file that specifies how to map a (zero-based) line and column +position in generated code to a file, line, and column location in the source. For +WebAssembly binary locations, the line number is always 1, and the column number +is interpreted as a byte offset into the WebAssembly binary content. +Source locations are interpreted as in the source map spec. + +On the WebAssembly side, the URL of such Source Map file is stored in a custom section with the name +`sourceMappingURL`. That section contains: + +| Field | Type | Description | +| ------------ | ----------- | --------------------------------- | +| url_name_len | `varuint32` | Length of `url_name_str` in bytes | +| url_name_str | `bytes` | URL to the Source Map file |