| ... | ... | @@ -1163,32 +1163,28 @@ pub fn commitDeclState( |
| 1163 | 1163 | next_padding_size, |
| 1164 | 1164 | ); |
| 1165 | 1165 | }, |
| 1166 | |
| 1166 | 1167 | .macho => { |
| 1167 | 1168 | const macho_file = file.cast(File.MachO).?; |
| 1168 | 1169 | const d_sym = &macho_file.d_sym.?; |
| 1169 | | const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?]; |
| 1170 | 1170 | const debug_line_sect = &d_sym.sections.items[d_sym.debug_line_section_index.?]; |
| 1171 | 1171 | if (needed_size != debug_line_sect.size) { |
| 1172 | 1172 | if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) { |
| 1173 | 1173 | const new_offset = d_sym.findFreeSpace(needed_size, 1); |
| 1174 | 1174 | const existing_size = last_src_fn.off; |
| 1175 | | |
| 1176 | 1175 | log.debug("moving __debug_line section: {} bytes from 0x{x} to 0x{x}", .{ |
| 1177 | 1176 | existing_size, |
| 1178 | 1177 | debug_line_sect.offset, |
| 1179 | 1178 | new_offset, |
| 1180 | 1179 | }); |
| 1181 | | |
| 1182 | | try copyRangeAllOverlappingAlloc( |
| 1183 | | gpa, |
| 1184 | | d_sym.file, |
| 1180 | const amt = try d_sym.file.copyRangeAll( |
| 1185 | 1181 | debug_line_sect.offset, |
| 1182 | d_sym.file, |
| 1186 | 1183 | new_offset, |
| 1187 | 1184 | existing_size, |
| 1188 | 1185 | ); |
| 1189 | | |
| 1186 | if (amt != existing_size) return error.InputOutput; |
| 1190 | 1187 | debug_line_sect.offset = @intCast(u32, new_offset); |
| 1191 | | debug_line_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff; |
| 1192 | 1188 | } |
| 1193 | 1189 | debug_line_sect.size = needed_size; |
| 1194 | 1190 | d_sym.debug_line_header_dirty = true; |
| ... | ... | @@ -1202,6 +1198,7 @@ pub fn commitDeclState( |
| 1202 | 1198 | next_padding_size, |
| 1203 | 1199 | ); |
| 1204 | 1200 | }, |
| 1201 | |
| 1205 | 1202 | .wasm => { |
| 1206 | 1203 | const wasm_file = file.cast(File.Wasm).?; |
| 1207 | 1204 | const atom = wasm_file.debug_line_atom.?; |
| ... | ... | @@ -1462,32 +1459,28 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co |
| 1462 | 1459 | trailing_zero, |
| 1463 | 1460 | ); |
| 1464 | 1461 | }, |
| 1462 | |
| 1465 | 1463 | .macho => { |
| 1466 | 1464 | const macho_file = file.cast(File.MachO).?; |
| 1467 | 1465 | const d_sym = &macho_file.d_sym.?; |
| 1468 | | const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?]; |
| 1469 | 1466 | const debug_info_sect = &d_sym.sections.items[d_sym.debug_info_section_index.?]; |
| 1470 | 1467 | if (needed_size != debug_info_sect.size) { |
| 1471 | 1468 | if (needed_size > d_sym.allocatedSize(debug_info_sect.offset)) { |
| 1472 | 1469 | const new_offset = d_sym.findFreeSpace(needed_size, 1); |
| 1473 | 1470 | const existing_size = last_decl.off; |
| 1474 | | |
| 1475 | 1471 | log.debug("moving __debug_info section: {} bytes from 0x{x} to 0x{x}", .{ |
| 1476 | 1472 | existing_size, |
| 1477 | 1473 | debug_info_sect.offset, |
| 1478 | 1474 | new_offset, |
| 1479 | 1475 | }); |
| 1480 | | |
| 1481 | | try copyRangeAllOverlappingAlloc( |
| 1482 | | gpa, |
| 1483 | | d_sym.file, |
| 1476 | const amt = try d_sym.file.copyRangeAll( |
| 1484 | 1477 | debug_info_sect.offset, |
| 1478 | d_sym.file, |
| 1485 | 1479 | new_offset, |
| 1486 | 1480 | existing_size, |
| 1487 | 1481 | ); |
| 1488 | | |
| 1482 | if (amt != existing_size) return error.InputOutput; |
| 1489 | 1483 | debug_info_sect.offset = @intCast(u32, new_offset); |
| 1490 | | debug_info_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff; |
| 1491 | 1484 | } |
| 1492 | 1485 | debug_info_sect.size = needed_size; |
| 1493 | 1486 | d_sym.debug_info_header_dirty = true; |
| ... | ... | @@ -1502,6 +1495,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co |
| 1502 | 1495 | trailing_zero, |
| 1503 | 1496 | ); |
| 1504 | 1497 | }, |
| 1498 | |
| 1505 | 1499 | .wasm => { |
| 1506 | 1500 | const wasm_file = file.cast(File.Wasm).?; |
| 1507 | 1501 | const info_atom = wasm_file.debug_info_atom.?; |
| ... | ... | @@ -2569,16 +2563,3 @@ fn addDbgInfoErrorSet( |
| 2569 | 2563 | // DW.AT.enumeration_type delimit children |
| 2570 | 2564 | try dbg_info_buffer.append(0); |
| 2571 | 2565 | } |
| 2572 | | |
| 2573 | | fn copyRangeAllOverlappingAlloc( |
| 2574 | | allocator: Allocator, |
| 2575 | | file: std.fs.File, |
| 2576 | | in_offset: u64, |
| 2577 | | out_offset: u64, |
| 2578 | | len: usize, |
| 2579 | | ) !void { |
| 2580 | | const buf = try allocator.alloc(u8, len); |
| 2581 | | defer allocator.free(buf); |
| 2582 | | const amt = try file.preadAll(buf, in_offset); |
| 2583 | | try file.pwriteAll(buf[0..amt], out_offset); |
| 2584 | | } |