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 {
11991199
12001200 // .debug_info subprogram
12011201 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
12041204 const fn_ret_type = typed_value.ty.fnReturnType();
12051205 const fn_ret_has_bits = fn_ret_type.hasCodeGenBits();
......@@ -1227,6 +1227,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
12271227 dbg_info_buffer.items.len += 4; // DW.AT_type, DW.FORM_ref4
12281228 }
12291229 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
12301232 } else {
12311233 // TODO implement .debug_info for global variables
12321234 }
src/link/MachO/DebugSymbols.zig+28-39
......@@ -361,52 +361,41 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
361361 // we can simply append these bytes.
362362 const abbrev_buf = [_]u8{
363363 abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header
364 DW.AT_stmt_list, DW.FORM_sec_offset, DW.AT_low_pc,
365 DW.FORM_addr, DW.AT_high_pc, DW.FORM_addr,
366 DW.AT_name, DW.FORM_strp, DW.AT_comp_dir,
367 DW.FORM_strp, DW.AT_producer, DW.FORM_strp,
368 DW.AT_language, DW.FORM_data2, 0,
369 0, // table sentinel
370 abbrev_subprogram,
371 DW.TAG_subprogram,
372 DW.CHILDREN_yes, // header
373 DW.AT_low_pc,
374 DW.FORM_addr,
375 DW.AT_high_pc,
376 DW.FORM_data4,
377 DW.AT_type,
378 DW.FORM_ref4,
379 DW.AT_name,
380 DW.FORM_string,
364 DW.AT_stmt_list, DW.FORM_sec_offset, // offset
365 DW.AT_low_pc, DW.FORM_addr,
366 DW.AT_high_pc, DW.FORM_addr,
367 DW.AT_name, DW.FORM_strp,
368 DW.AT_comp_dir, DW.FORM_strp,
369 DW.AT_producer, DW.FORM_strp,
370 DW.AT_language, DW.FORM_data2,
371 0, 0, // table sentinel
372 abbrev_subprogram, DW.TAG_subprogram, DW.CHILDREN_yes, // header
373 DW.AT_low_pc, DW.FORM_addr, // start VM address
374 DW.AT_high_pc, DW.FORM_data4,
375 DW.AT_type, DW.FORM_ref4,
376 DW.AT_name, DW.FORM_string,
377 DW.AT_decl_line, DW.FORM_data4,
378 DW.AT_decl_file, DW.FORM_data1,
381379 0, 0, // table sentinel
382380 abbrev_subprogram_retvoid,
383381 DW.TAG_subprogram, DW.CHILDREN_yes, // header
384382 DW.AT_low_pc, DW.FORM_addr,
385383 DW.AT_high_pc, DW.FORM_data4,
386384 DW.AT_name, DW.FORM_string,
387 0,
388 0, // table sentinel
389 abbrev_base_type,
390 DW.TAG_base_type,
391 DW.CHILDREN_no, // header
392 DW.AT_encoding,
393 DW.FORM_data1,
394 DW.AT_byte_size,
395 DW.FORM_data1,
396 DW.AT_name,
397 DW.FORM_string, 0, 0, // table sentinel
385 DW.AT_decl_line, DW.FORM_data4,
386 DW.AT_decl_file, DW.FORM_data1,
387 0, 0, // table sentinel
388 abbrev_base_type, DW.TAG_base_type, DW.CHILDREN_no, // header
389 DW.AT_encoding, DW.FORM_data1, DW.AT_byte_size,
390 DW.FORM_data1, DW.AT_name, DW.FORM_string,
391 0, 0, // table sentinel
398392 abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header
399 0, 0, // table sentinel
400 abbrev_parameter,
401 DW.TAG_formal_parameter, DW.CHILDREN_no, // header
402 DW.AT_location, DW.FORM_exprloc,
403 DW.AT_type, DW.FORM_ref4,
404 DW.AT_name, DW.FORM_string,
405 0,
406 0, // table sentinel
407 0,
408 0,
409 0, // section sentinel
393 0, 0, // table sentinel
394 abbrev_parameter, DW.TAG_formal_parameter, DW.CHILDREN_no, // header
395 DW.AT_location, DW.FORM_exprloc, DW.AT_type,
396 DW.FORM_ref4, DW.AT_name, DW.FORM_string,
397 0, 0, // table sentinel
398 0, 0, 0, // section sentinel
410399 };
411400
412401 const needed_size = abbrev_buf.len;