macho: move updateDeclLineNumber logic to DebugSymbols

This commit is contained in:
Jakub Konka 2020-12-30 21:49:06 +01:00
parent 60b3c4ae3c
commit d189614647
2 changed files with 25 additions and 19 deletions

View File

@ -1460,25 +1460,9 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
}
pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl: *const Module.Decl) !void {
const tracy = trace(@src());
defer tracy.end();
const container_scope = decl.scope.cast(Module.Scope.Container).?;
const tree = container_scope.file_scope.contents.tree;
const file_ast_decls = tree.root_node.decls();
// TODO Look into improving the performance here by adding a token-index-to-line
// lookup table. Currently this involves scanning over the source code for newlines.
const fn_proto = file_ast_decls[decl.src_index].castTag(.FnProto).?;
const block = fn_proto.getBodyNode().?.castTag(.Block).?;
const line_delta = std.zig.lineDelta(tree.source, 0, tree.token_locs[block.lbrace].start);
const casted_line_off = @intCast(u28, line_delta);
const dwarf_segment = &self.d_sym.?.load_commands.items[self.d_sym.?.dwarf_segment_cmd_index.?].Segment;
const shdr = &dwarf_segment.sections.items[self.d_sym.?.debug_line_section_index.?];
const file_pos = shdr.offset + decl.fn_link.macho.off + DebugSymbols.getRelocDbgLineOff();
var data: [4]u8 = undefined;
leb.writeUnsignedFixed(4, &data, casted_line_off);
try self.d_sym.?.file.pwriteAll(&data, file_pos);
if (self.d_sym) |*ds| {
try ds.updateDeclLineNumber(module, decl);
}
}
pub fn updateDeclExports(

View File

@ -1239,3 +1239,25 @@ pub fn pwriteDbgInfoNops(
try self.file.pwritevAll(vecs[0..vec_index], offset - prev_padding_size);
}
pub fn updateDeclLineNumber(self: *DebugSymbols, module: *Module, decl: *const Module.Decl) !void {
const tracy = trace(@src());
defer tracy.end();
const container_scope = decl.scope.cast(Module.Scope.Container).?;
const tree = container_scope.file_scope.contents.tree;
const file_ast_decls = tree.root_node.decls();
// TODO Look into improving the performance here by adding a token-index-to-line
// lookup table. Currently this involves scanning over the source code for newlines.
const fn_proto = file_ast_decls[decl.src_index].castTag(.FnProto).?;
const block = fn_proto.getBodyNode().?.castTag(.Block).?;
const line_delta = std.zig.lineDelta(tree.source, 0, tree.token_locs[block.lbrace].start);
const casted_line_off = @intCast(u28, line_delta);
const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment;
const shdr = &dwarf_segment.sections.items[self.debug_line_section_index.?];
const file_pos = shdr.offset + decl.fn_link.macho.off + getRelocDbgLineOff();
var data: [4]u8 = undefined;
leb.writeUnsignedFixed(4, &data, casted_line_off);
try self.file.pwriteAll(&data, file_pos);
}