| ... | ... | @@ -909,20 +909,14 @@ pub fn updateDeclLineNumber(self: *DebugSymbols, module: *Module, decl: *const M |
| 909 | 909 | const node_datas = tree.nodes.items(.data); |
| 910 | 910 | const token_starts = tree.tokens.items(.start); |
| 911 | 911 | |
| 912 | | // TODO Look into improving the performance here by adding a token-index-to-line |
| 913 | | // lookup table. Currently this involves scanning over the source code for newlines. |
| 914 | | const fn_decl = decl.src_node; |
| 915 | | assert(node_tags[fn_decl] == .fn_decl); |
| 916 | | const block = node_datas[fn_decl].rhs; |
| 917 | | const lbrace = tree.firstToken(block); |
| 918 | | const line_delta = std.zig.lineDelta(tree.source, 0, token_starts[lbrace]); |
| 919 | | const casted_line_off = @intCast(u28, line_delta); |
| 912 | const func = decl.val.castTag(.function).?.data; |
| 913 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); |
| 920 | 914 | |
| 921 | 915 | const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment; |
| 922 | 916 | const shdr = &dwarf_segment.sections.items[self.debug_line_section_index.?]; |
| 923 | 917 | const file_pos = shdr.offset + decl.fn_link.macho.off + getRelocDbgLineOff(); |
| 924 | 918 | var data: [4]u8 = undefined; |
| 925 | | leb.writeUnsignedFixed(4, &data, casted_line_off); |
| 919 | leb.writeUnsignedFixed(4, &data, line_off); |
| 926 | 920 | try self.file.pwriteAll(&data, file_pos); |
| 927 | 921 | } |
| 928 | 922 | |
| ... | ... | @@ -952,21 +946,8 @@ pub fn initDeclDebugBuffers( |
| 952 | 946 | // For functions we need to add a prologue to the debug line program. |
| 953 | 947 | try dbg_line_buffer.ensureCapacity(26); |
| 954 | 948 | |
| 955 | | const line_off: u28 = blk: { |
| 956 | | const tree = decl.namespace.file_scope.tree; |
| 957 | | const node_tags = tree.nodes.items(.tag); |
| 958 | | const node_datas = tree.nodes.items(.data); |
| 959 | | const token_starts = tree.tokens.items(.start); |
| 960 | | |
| 961 | | // TODO Look into improving the performance here by adding a token-index-to-line |
| 962 | | // lookup table. Currently this involves scanning over the source code for newlines. |
| 963 | | const fn_decl = decl.src_node; |
| 964 | | assert(node_tags[fn_decl] == .fn_decl); |
| 965 | | const block = node_datas[fn_decl].rhs; |
| 966 | | const lbrace = tree.firstToken(block); |
| 967 | | const line_delta = std.zig.lineDelta(tree.source, 0, token_starts[lbrace]); |
| 968 | | break :blk @intCast(u28, line_delta); |
| 969 | | }; |
| 949 | const func = decl.val.castTag(.function).?.data; |
| 950 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); |
| 970 | 951 | |
| 971 | 952 | dbg_line_buffer.appendSliceAssumeCapacity(&[_]u8{ |
| 972 | 953 | DW.LNS_extended_op, |
| ... | ... | @@ -1162,6 +1143,9 @@ pub fn commitDeclDebugInfo( |
| 1162 | 1143 | else => {}, |
| 1163 | 1144 | } |
| 1164 | 1145 | |
| 1146 | if (dbg_info_buffer.items.len == 0) |
| 1147 | return; |
| 1148 | |
| 1165 | 1149 | // Now we emit the .debug_info types of the Decl. These will count towards the size of |
| 1166 | 1150 | // the buffer, so we have to do it before computing the offset, and we can't perform the actual |
| 1167 | 1151 | // relocations yet. |