| ... | @@ -62,6 +62,10 @@ managed_atoms: std.ArrayListUnmanaged(*Atom) = .{}, | ... | @@ -62,6 +62,10 @@ managed_atoms: std.ArrayListUnmanaged(*Atom) = .{}, |
| 62 | /// Represents the index into `segments` where the 'code' section | 62 | /// Represents the index into `segments` where the 'code' section |
| 63 | /// lives. | 63 | /// lives. |
| 64 | code_section_index: ?u32 = null, | 64 | code_section_index: ?u32 = null, |
| | 65 | /// The index of the segment representing the custom '.debug_info' section. |
| | 66 | debug_info_index: ?u32 = null, |
| | 67 | /// The index of the segment representing the custom '.debug_line' section. |
| | 68 | debug_line_index: ?u32 = null, |
| 65 | /// The count of imported functions. This number will be appended | 69 | /// The count of imported functions. This number will be appended |
| 66 | /// to the function indexes as their index starts at the lowest non-extern function. | 70 | /// to the function indexes as their index starts at the lowest non-extern function. |
| 67 | imported_functions_count: u32 = 0, | 71 | imported_functions_count: u32 = 0, |
| ... | @@ -311,6 +315,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -311,6 +315,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 311 | .init = .{ .i32_const = 0 }, | 315 | .init = .{ .i32_const = 0 }, |
| 312 | }; | 316 | }; |
| 313 | } | 317 | } |
| | 318 | |
| 314 | return wasm_bin; | 319 | return wasm_bin; |
| 315 | } | 320 | } |
| 316 | | 321 | |
| ... | @@ -566,6 +571,17 @@ pub fn updateFunc(self: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes | ... | @@ -566,6 +571,17 @@ pub fn updateFunc(self: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes |
| 566 | }, | 571 | }, |
| 567 | }; | 572 | }; |
| 568 | | 573 | |
| | 574 | if (self.dwarf) |*dwarf| { |
| | 575 | try dwarf.commitDeclState( |
| | 576 | &self.base, |
| | 577 | mod, |
| | 578 | decl, |
| | 579 | // Actual value will be written after relocation |
| | 580 | 0, |
| | 581 | code.len, |
| | 582 | &decl_state.?, |
| | 583 | ); |
| | 584 | } |
| 569 | return self.finishUpdateDecl(decl, code); | 585 | return self.finishUpdateDecl(decl, code); |
| 570 | } | 586 | } |
| 571 | | 587 | |
| ... | @@ -1517,6 +1533,35 @@ fn populateErrorNameTable(self: *Wasm) !void { | ... | @@ -1517,6 +1533,35 @@ fn populateErrorNameTable(self: *Wasm) !void { |
| 1517 | try self.parseAtom(names_atom, .data); | 1533 | try self.parseAtom(names_atom, .data); |
| 1518 | } | 1534 | } |
| 1519 | | 1535 | |
| | 1536 | pub fn getDebugInfoIndex(self: *Wasm) !u32 { |
| | 1537 | assert(self.dwarf != null); |
| | 1538 | return self.debug_info_index orelse { |
| | 1539 | self.debug_info_index = @intCast(u32, self.segments.items.len); |
| | 1540 | const segment = try self.segments.addOne(self.base.allocator); |
| | 1541 | segment.* = .{ |
| | 1542 | .size = 0, |
| | 1543 | .offset = 0, |
| | 1544 | // debug sections always have alignment '1' |
| | 1545 | .alignment = 1, |
| | 1546 | }; |
| | 1547 | return self.debug_info_index.?; |
| | 1548 | }; |
| | 1549 | } |
| | 1550 | |
| | 1551 | pub fn getDebugLineIndex(self: *Wasm) !u32 { |
| | 1552 | assert(self.dwarf != null); |
| | 1553 | return self.debug_line_index orelse { |
| | 1554 | self.debug_line_index = @intCast(u32, self.segments.items.len); |
| | 1555 | const segment = try self.segments.addOne(self.base.allocator); |
| | 1556 | segment.* = .{ |
| | 1557 | .size = 0, |
| | 1558 | .offset = 0, |
| | 1559 | .alignment = 1, |
| | 1560 | }; |
| | 1561 | return self.debug_line_index.?; |
| | 1562 | }; |
| | 1563 | } |
| | 1564 | |
| 1520 | fn resetState(self: *Wasm) void { | 1565 | fn resetState(self: *Wasm) void { |
| 1521 | for (self.segment_info.items) |*segment_info| { | 1566 | for (self.segment_info.items) |*segment_info| { |
| 1522 | self.base.allocator.free(segment_info.name); | 1567 | self.base.allocator.free(segment_info.name); |
| ... | @@ -1542,6 +1587,7 @@ fn resetState(self: *Wasm) void { | ... | @@ -1542,6 +1587,7 @@ fn resetState(self: *Wasm) void { |
| 1542 | self.atoms.clearRetainingCapacity(); | 1587 | self.atoms.clearRetainingCapacity(); |
| 1543 | self.symbol_atom.clearRetainingCapacity(); | 1588 | self.symbol_atom.clearRetainingCapacity(); |
| 1544 | self.code_section_index = null; | 1589 | self.code_section_index = null; |
| | 1590 | self.debug_info_index = null; |
| 1545 | } | 1591 | } |
| 1546 | | 1592 | |
| 1547 | pub fn flush(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !void { | 1593 | pub fn flush(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| ... | @@ -1636,6 +1682,9 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -1636,6 +1682,9 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod |
| 1636 | try self.objects.items[object_index].parseIntoAtoms(self.base.allocator, object_index, self); | 1682 | try self.objects.items[object_index].parseIntoAtoms(self.base.allocator, object_index, self); |
| 1637 | } | 1683 | } |
| 1638 | | 1684 | |
| | 1685 | if (self.dwarf) |*dwarf| { |
| | 1686 | try dwarf.flushModule(&self.base, self.base.options.module.?); |
| | 1687 | } |
| 1639 | try self.allocateAtoms(); | 1688 | try self.allocateAtoms(); |
| 1640 | try self.setupMemory(); | 1689 | try self.setupMemory(); |
| 1641 | self.mapFunctionTable(); | 1690 | self.mapFunctionTable(); |