authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-30 15:55:27+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-31 10:19:04+01:00
log364691fa1f5a1c7da024cc58b9b3138425a5e475
treeace3c9356e4b6b7d9b38b7137c48d2b59e03f236
parentfa28f7006ddba699048c54a363244dcad49af1e2

macho: add decl line and file info to subprogram


2 files changed, 31 insertions(+), 40 deletions(-)

src/link/MachO.zig+3-1
...@@ -1199,7 +1199,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1199,7 +1199,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
11991199
1200 // .debug_info subprogram1200 // .debug_info subprogram
1201 const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1];1201 const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1];
1202 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 25 + decl_name_with_null.len);1202 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 27 + decl_name_with_null.len);
12031203
1204 const fn_ret_type = typed_value.ty.fnReturnType();1204 const fn_ret_type = typed_value.ty.fnReturnType();
1205 const fn_ret_has_bits = fn_ret_type.hasCodeGenBits();1205 const fn_ret_has_bits = fn_ret_type.hasCodeGenBits();
...@@ -1227,6 +1227,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1227,6 +1227,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1227 dbg_info_buffer.items.len += 4; // DW.AT_type, DW.FORM_ref41227 dbg_info_buffer.items.len += 4; // DW.AT_type, DW.FORM_ref4
1228 }1228 }
1229 dbg_info_buffer.appendSliceAssumeCapacity(decl_name_with_null); // DW.AT_name, DW.FORM_string1229 dbg_info_buffer.appendSliceAssumeCapacity(decl_name_with_null); // DW.AT_name, DW.FORM_string
1230 mem.writeIntLittle(u32, dbg_info_buffer.addManyAsArrayAssumeCapacity(4), line_off + 1); // DW.AT_decl_line, DW.FORM_data4
1231 dbg_info_buffer.appendAssumeCapacity(file_index); // DW.AT_decl_file, DW.FORM_data1
1230 } else {1232 } else {
1231 // TODO implement .debug_info for global variables1233 // TODO implement .debug_info for global variables
1232 }1234 }
src/link/MachO/DebugSymbols.zig+28-39
...@@ -361,52 +361,41 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt...@@ -361,52 +361,41 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
361 // we can simply append these bytes.361 // we can simply append these bytes.
362 const abbrev_buf = [_]u8{362 const abbrev_buf = [_]u8{
363 abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header363 abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header
364 DW.AT_stmt_list, DW.FORM_sec_offset, DW.AT_low_pc,364 DW.AT_stmt_list, DW.FORM_sec_offset, // offset
365 DW.FORM_addr, DW.AT_high_pc, DW.FORM_addr,365 DW.AT_low_pc, DW.FORM_addr,
366 DW.AT_name, DW.FORM_strp, DW.AT_comp_dir,366 DW.AT_high_pc, DW.FORM_addr,
367 DW.FORM_strp, DW.AT_producer, DW.FORM_strp,367 DW.AT_name, DW.FORM_strp,
368 DW.AT_language, DW.FORM_data2, 0,368 DW.AT_comp_dir, DW.FORM_strp,
369 0, // table sentinel369 DW.AT_producer, DW.FORM_strp,
370 abbrev_subprogram,370 DW.AT_language, DW.FORM_data2,
371 DW.TAG_subprogram,371 0, 0, // table sentinel
372 DW.CHILDREN_yes, // header372 abbrev_subprogram, DW.TAG_subprogram, DW.CHILDREN_yes, // header
373 DW.AT_low_pc,373 DW.AT_low_pc, DW.FORM_addr, // start VM address
374 DW.FORM_addr,374 DW.AT_high_pc, DW.FORM_data4,
375 DW.AT_high_pc,375 DW.AT_type, DW.FORM_ref4,
376 DW.FORM_data4,376 DW.AT_name, DW.FORM_string,
377 DW.AT_type,377 DW.AT_decl_line, DW.FORM_data4,
378 DW.FORM_ref4,378 DW.AT_decl_file, DW.FORM_data1,
379 DW.AT_name,
380 DW.FORM_string,
381 0, 0, // table sentinel379 0, 0, // table sentinel
382 abbrev_subprogram_retvoid,380 abbrev_subprogram_retvoid,
383 DW.TAG_subprogram, DW.CHILDREN_yes, // header381 DW.TAG_subprogram, DW.CHILDREN_yes, // header
384 DW.AT_low_pc, DW.FORM_addr,382 DW.AT_low_pc, DW.FORM_addr,
385 DW.AT_high_pc, DW.FORM_data4,383 DW.AT_high_pc, DW.FORM_data4,
386 DW.AT_name, DW.FORM_string,384 DW.AT_name, DW.FORM_string,
387 0,385 DW.AT_decl_line, DW.FORM_data4,
388 0, // table sentinel386 DW.AT_decl_file, DW.FORM_data1,
389 abbrev_base_type,387 0, 0, // table sentinel
390 DW.TAG_base_type,388 abbrev_base_type, DW.TAG_base_type, DW.CHILDREN_no, // header
391 DW.CHILDREN_no, // header389 DW.AT_encoding, DW.FORM_data1, DW.AT_byte_size,
392 DW.AT_encoding,390 DW.FORM_data1, DW.AT_name, DW.FORM_string,
393 DW.FORM_data1,391 0, 0, // table sentinel
394 DW.AT_byte_size,
395 DW.FORM_data1,
396 DW.AT_name,
397 DW.FORM_string, 0, 0, // table sentinel
398 abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header392 abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header
399 0, 0, // table sentinel393 0, 0, // table sentinel
400 abbrev_parameter,394 abbrev_parameter, DW.TAG_formal_parameter, DW.CHILDREN_no, // header
401 DW.TAG_formal_parameter, DW.CHILDREN_no, // header395 DW.AT_location, DW.FORM_exprloc, DW.AT_type,
402 DW.AT_location, DW.FORM_exprloc,396 DW.FORM_ref4, DW.AT_name, DW.FORM_string,
403 DW.AT_type, DW.FORM_ref4,397 0, 0, // table sentinel
404 DW.AT_name, DW.FORM_string,398 0, 0, 0, // section sentinel
405 0,
406 0, // table sentinel
407 0,
408 0,
409 0, // section sentinel
410 };399 };
411400
412 const needed_size = abbrev_buf.len;401 const needed_size = abbrev_buf.len;