| ... | ... | @@ -14,10 +14,18 @@ pub fn deinit(dwarf: *Dwarf, allocator: Allocator) void { |
| 14 | 14 | /// This is new in DWARFv5 and requires the producer to specify DW_FORM_strx* (`index` arg) |
| 15 | 15 | /// but also DW_AT_str_offsets_base with DW_FORM_sec_offset (`base` arg) in the opening header |
| 16 | 16 | /// of a "referencing entity" such as DW_TAG_compile_unit. |
| 17 | | fn getOffset(debug_str_offsets: []const u8, base: u64, index: u64, dw_fmt: DwarfFormat) u64 { |
| 17 | fn getOffset(debug_str_offsets: []const u8, base: u64, index: u64, dw_fmt: DwarfFormat) error{Overflow}!u64 { |
| 18 | const base_as_usize = math.cast(usize, base) orelse return error.Overflow; |
| 19 | const index_as_usize = math.cast(usize, index) orelse return error.Overflow; |
| 18 | 20 | return switch (dw_fmt) { |
| 19 | | .dwarf32 => @as(*align(1) const u32, @ptrCast(debug_str_offsets.ptr + base + index * @sizeOf(u32))).*, |
| 20 | | .dwarf64 => @as(*align(1) const u64, @ptrCast(debug_str_offsets.ptr + base + index * @sizeOf(u64))).*, |
| 21 | .dwarf32 => @as( |
| 22 | *align(1) const u32, |
| 23 | @ptrCast(debug_str_offsets.ptr + base_as_usize + index_as_usize * @sizeOf(u32)), |
| 24 | ).*, |
| 25 | .dwarf64 => @as( |
| 26 | *align(1) const u64, |
| 27 | @ptrCast(debug_str_offsets.ptr + base_as_usize + index_as_usize * @sizeOf(u64)), |
| 28 | ).*, |
| 21 | 29 | }; |
| 22 | 30 | } |
| 23 | 31 | |
| ... | ... | @@ -228,7 +236,10 @@ pub const InfoReader = struct { |
| 228 | 236 | dw.FORM.strx4, |
| 229 | 237 | => { |
| 230 | 238 | const index = try p.readIndex(form); |
| 231 | | const off = getOffset(p.ctx.debug_str_offsets, base, index, cuh.format); |
| 239 | const off = math.cast( |
| 240 | usize, |
| 241 | try getOffset(p.ctx.debug_str_offsets, base, index, cuh.format), |
| 242 | ) orelse return error.Overflow; |
| 232 | 243 | return mem.sliceTo(@as([*:0]const u8, @ptrCast(p.ctx.debug_str.ptr + off)), 0); |
| 233 | 244 | }, |
| 234 | 245 | else => unreachable, |