Skip to content

Commit 6870616

Browse files
authored
[Docs] Improve split/separate DWARF and other debugging docs (#20463)
1 parent 99a5f81 commit 6870616

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

docs/emcc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ Options that are modified or new in *emcc* are listed below:
173173
customize that location (this is useful if you want to host it on a
174174
different server, for example).
175175

176+
"-gsplit-dwarf"
177+
Enable debug fission, which creates split DWARF object files
178+
alongside the wasm object files. This option must be used together
179+
with "-c".
180+
176181
"-gsource-map"
177182
[link] Generate a source map using LLVM debug information (which
178183
must be present in object files, i.e., they should have been

site/source/docs/porting/Debugging.rst

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,49 @@ This article describes the main tools and settings provided by Emscripten for de
1919

2020
.. _debugging-debug-information-g:
2121

22-
Debug information
23-
=================
24-
25-
:ref:`Emcc <emccdoc>` strips out most of the debug information from :ref:`optimized builds <Optimizing-Code>` by default. The higher the optimization level, the more degraded the quality of DWARF debug information is, so we recommend using :ref:`-O0 <emcc-O0>` or :ref:`-O1 <emcc-O1>` for debugging purposes. :ref:`-O1 <emcc-O1>` and above also disable runtime :ref:`ASSERTIONS <debugging-ASSERTIONS>` checks. From optimization level :ref:`-O2 <emcc-O2>` the JavaScript code is minified by the :term:`Closure Compiler` and becomes virtually unreadable.
26-
27-
The *emcc* :ref:`-g flag <emcc-g>` can be used to preserve debug information in the compiled output. By default, this option includes Clang / LLVM debug information in a DWARF format in the generated WebAssembly code and preserves white-space, function names and variable names in the generated JavaScript code.
28-
29-
The flag can also be specified with an integer level: :ref:`-g0 <emcc-g0>`, :ref:`-g1 <emcc-g1>`, :ref:`-g2 <emcc-g2>`, and :ref:`-g3 <emcc-g3>` (default level when setting ``-g``). Each level builds on the last to provide progressively more debug information in the compiled output. See :ref:`Compiler debug information flags <emcc-gN>` for more details.
30-
31-
The :ref:`-gsource-map <emcc-gsource-map>` option is similar to ``-g2`` but also generates source maps that allow you to view and debug the *C/C++ source code* in your browser's debugger. Source maps are not as powerful as DWARF which was mentioned earlier (they contain only source location info), but they are currently more widely supported.
22+
Debugging in the browser
23+
========================
24+
25+
:ref:`Emcc <emccdoc>` can ouptut debug information in two formats, either as
26+
DWARF symbols or as source maps. Both allow you to view and debug the
27+
*C/C++ source code* in a browser's debugger. DWARF offers the most precise and
28+
detailed debugging experience and is supported as an experiment in Chrome 88
29+
with an `extension <https://goo.gle/wasm-debugging-extension>`. See
30+
`here <https://developer.chrome.com/blog/wasm-debugging-2020/>` for a detailed
31+
usage guide. Source maps are more widely supported in Firefox, Chrome, and
32+
Safari, but unlike DWARF they cannot be used to inspect variables, for example.
33+
34+
:ref:`Emcc <emccdoc>` strips out most of the debug information from
35+
:ref:`optimized builds <Optimizing-Code>` by default. DWARF can be produced with
36+
the *emcc* :ref:`-g flag <emcc-g>`, and source maps can be emitted with the
37+
:ref:`-gsource-map <emcc-gsource-map>` option. Be aware that optimisation levels
38+
:ref:`-O1 <emcc-O1>` and above increasingly remove LLVM debug information, and
39+
also disable runtime :ref:`ASSERTIONS <debugging-ASSERTIONS>` checks. Passing a
40+
``-g`` flag also affects the generated JavaScript code and preserves
41+
white-space, function names, and variable names,
42+
43+
.. tip:: Even for medium-sized projects, DWARF debug information can be of
44+
substantial size and negatively impact the page performance, particularly
45+
compiling and loading of the module. Debug information can also be emitted in
46+
a file on the side instead with the
47+
:ref:`-gseparate-dwarf <emcc-gseparate-dwarf>` option! The debug information
48+
size also affects the linking time, because the debug information in all
49+
object files needs to be linked as well. Passing the
50+
:ref:`-gsplit-dwarf <emcc-gsplit-dwarf>` option can help here, which causes
51+
clang to leave debug information scattered across object files. That debug
52+
information needs to be linked into a DWARF package file (``.dwp``) using the
53+
``emdwp`` tool then, but that could happen in parallel to the linking of
54+
the compiled output! When running it
55+
after linking, it's as simple as ``emdwp -e foo.wasm -o foo.wasm.dwp``, or
56+
``emdwp -e foo.debug.wasm -o foo.debug.wasm.dwp`` when used together with
57+
``-gseparate-dwarf`` (the dwp file should have the same file name as the main
58+
symbol file with an extra ``.dwp`` extension).
59+
60+
The ``-g`` flag can also be specified with an integer levels:
61+
:ref:`-g0 <emcc-g0>`, :ref:`-g1 <emcc-g1>`, :ref:`-g2 <emcc-g2>` (default with
62+
``-gsource-map``), and :ref:`-g3 <emcc-g3>` (default with ``-g``). Each level
63+
builds on the last to provide progressively more debug information in the
64+
compiled output.
3265

3366
.. note:: Because Binaryen optimization degrades the quality of DWARF info further, ``-O1 -g`` will skip running the Binaryen optimizer (``wasm-opt``) entirely unless required by other options. You can also throw in ``-sERROR_ON_WASM_CHANGES_AFTER_LINK`` option if you want to ensure the debug info is preserved. See `Skipping Binaryen <https://developer.chrome.com/blog/faster-wasm-debugging/#skipping-binaryen>`_ for more details.
3467

site/source/docs/tools_reference/emcc.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ Options that are modified or new in *emcc* are listed below:
149149
adds DWARF debug information to the object files.
150150
- When linking, this is equivalent to :ref:`-g3 <emcc-g3>`.
151151

152+
.. _emcc-gseparate-dwarf:
153+
152154
``-gseparate-dwarf[=FILENAME]``
153155
[same as -g3 if passed at compile time, otherwise applies at link]
154156
Preserve debug information, but in a separate file on the side. This is the
@@ -160,6 +162,12 @@ Options that are modified or new in *emcc* are listed below:
160162
``-sSEPARATE_DWARF_URL=URL`` to customize that location (this is useful if
161163
you want to host it on a different server, for example).
162164

165+
.. _emcc-gsplit-dwarf:
166+
167+
``-gsplit-dwarf``
168+
Enable debug fission, which creates split DWARF object files alongside the
169+
wasm object files. This option must be used together with ``-c``.
170+
163171
.. _emcc-gsource-map:
164172

165173
``-gsource-map``

0 commit comments

Comments
 (0)