1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! DWARF debug-info emission for the wasm core module.
//!
//! Gated on the `dwarf` cargo feature.
//!
//! The IR upstream (since `IrSpan { span, file: FileId }` landed)
//! carries source spans on every node and a `file_table` on
//! `IrModule`; this module turns those into `.debug_info` /
//! `.debug_abbrev` / `.debug_line` / `.debug_str` custom sections
//! attached to the emitted module.
//!
//! Granularity is function-level: one subprogram DIE per user
//! function (name, `decl_file`, `decl_line`, `low_pc`, `high_pc`)
//! plus a single `.debug_line` row per function pointing at its
//! first source line. Per-statement line tables can layer on later
//! by recording a `(span, code-section-byte-offset)` pair per
//! emitted instruction during lowering and feeding those into the
//! line program here.
//!
//! DWARF code addresses are byte offsets from the start of the wasm
//! `code` section's payload (i.e. excluding the section-id byte and
//! the section-size LEB). Every `low_pc` / `high_pc` / `.debug_line`
//! address in the output uses that frame.
use Path;
use FileId;
/// Minimum information needed to emit one subprogram DIE plus its
/// line-table row.
///
/// Collected during [`crate::module_lowering::lower_module`] as each
/// user function is added to the [`crate::module::ModuleBuilder`]
/// and handed off to [`emit_debug_sections`] once every function's
/// byte range is known.
/// Encoded `.debug_*` custom sections, ready to attach to the wasm
/// module.
///
/// Each `Vec<u8>` is the raw section payload (no section-id byte,
/// no length prefix — `wasm_encoder::CustomSection` adds those).
/// Build the four `.debug_*` sections from the IR-collected debug
/// info plus the module's file table.
///
/// Returns empty sections when `functions` is empty — callers can
/// still attach the (empty) sections, but typically should skip
/// them in that case.
/// Resolve a [`FileId`] against the module's file table.
///
/// Returns `None` for [`FileId::SYNTHETIC`] or any out-of-range id
/// (defensive — upstream invariants should prevent the latter).