From bf85d3db3f281971a5a274e25c90e782a8b692a7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 3 Aug 2020 00:34:12 -0700 Subject: [PATCH] downgrade .debug_line to DWARFv4 apparently gdb 8.3.1 which is still a commonly distributed version of gdb, does not support v5. --- src-self-hosted/link.zig | 46 +++++++++------------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig index c680bb47d5..b49c17e09d 100644 --- a/src-self-hosted/link.zig +++ b/src-self-hosted/link.zig @@ -1071,7 +1071,7 @@ pub const File = struct { }, } // Write the form for the compile unit, which must match the abbrev table above. - const name_strp = try self.makeDebugString(self.base.options.root_name); + const name_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_path); const comp_dir_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_dir_path); const producer_strp = try self.makeDebugString("zig (TODO version here)"); // Currently only one compilation unit is supported, so the address range is simply @@ -1225,11 +1225,7 @@ pub const File = struct { }, } - mem.writeInt(u16, di_buf.addManyAsArrayAssumeCapacity(2), 5, target_endian); // version - di_buf.appendSliceAssumeCapacity(&[_]u8{ - ptr_width_bytes, // address_size - 0, // segment_selector_size - }); + mem.writeInt(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4, target_endian); // version // Empirically, debug info consumers do not respect this field, or otherwise // consider it to be an error when it does not point exactly to the end of the header. @@ -1263,39 +1259,17 @@ pub const File = struct { 0, // `DW.LNS_set_epilogue_begin` 1, // `DW.LNS_set_isa` - 1, // directory_entry_format_count - DW.LNCT_path, DW.FORM_string, // directory_entry_format - - // For now we only support one compilation unit, which has one directory. - 1, // directories_count (this is a ULEB128) + 0, // include_directories (none except the compilation unit cwd) }); - // Empirically, some tools do not understand DW.FORM_strp yet. readelf 2.31.1 gives the bogus - // error and gdb 8.3.1 crashes. Both programs seem to work fine with - // DW.FORM_string however. - di_buf.appendSliceAssumeCapacity(self.base.options.root_pkg.root_src_dir_path); - di_buf.appendAssumeCapacity(0); - + // file_names[0] + di_buf.appendSliceAssumeCapacity(self.base.options.root_pkg.root_src_path); // relative path name di_buf.appendSliceAssumeCapacity(&[_]u8{ - 2, // file_name_entry_format_count - DW.LNCT_path, DW.FORM_string, // file_name_entry_format[0] - DW.LNCT_directory_index, DW.FORM_data1, // file_name_entry_format[1] - // TODO Look into adding the file size here. Maybe even the mtime and MD5. - //DW.LNCT_size, DW.FORM_udata, // file_name_entry_format[2] - - // For now we only put the root file name here. Once more source files - // are supported, this will need to be improved. - 2, // file_names_count (this is a ULEB128) + 0, // null byte for the relative path name + 0, // directory_index + 0, // mtime (TODO supply this) + 0, // file size bytes (TODO supply this) + 0, // file_names sentinel }); - // See note above with directories about why we use DW.FORM_string here. - di_buf.appendSliceAssumeCapacity(self.base.options.root_pkg.root_src_path); - di_buf.appendAssumeCapacity(0); - di_buf.appendAssumeCapacity(0); // LNCT_directory_index, FORM_data1 - - // We add the root file twice because according to DWARF, the state machine - // starts out with file index 1. - di_buf.appendSliceAssumeCapacity(self.base.options.root_pkg.root_src_path); - di_buf.appendAssumeCapacity(0); - di_buf.appendAssumeCapacity(0); // LNCT_directory_index, FORM_data1 const header_len = di_buf.items.len - after_header_len; switch (self.ptr_width) {