authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-11 09:53:47+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-11 10:36:15+02:00
log795b3e9b68986a587ac1fc9a2df6d87067d6f955
tree7af57cb85460d70e3f0a1344e40681428aa9e910
parent60e2a04322cb3cb49fdc2c1b28060bc261754302

Fix reading of udata/sdata encoded attributes


1 files changed, 12 insertions(+), 7 deletions(-)

std/debug.zig+12-7
......@@ -1251,13 +1251,12 @@ const FormValue = union(enum) {
12511251};
12521252
12531253const Constant = struct {
1254 payload: []u8,
1254 payload: u64,
12551255 signed: bool,
12561256
12571257 fn asUnsignedLe(self: *const Constant) !u64 {
1258 if (self.payload.len > @sizeOf(u64)) return error.InvalidDebugInfo;
12591258 if (self.signed) return error.InvalidDebugInfo;
1260 return mem.readVarInt(u64, self.payload, builtin.Endian.Little);
1259 return self.payload;
12611260 }
12621261};
12631262
......@@ -1442,11 +1441,18 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !
14421441 return parseFormValueBlockLen(allocator, in_stream, block_len);
14431442}
14441443
1445fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, size: usize) !FormValue {
1444fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, size: i32) !FormValue {
14461445 return FormValue{
14471446 .Const = Constant{
14481447 .signed = signed,
1449 .payload = try readAllocBytes(allocator, in_stream, size),
1448 .payload = switch (size) {
1449 1 => try in_stream.readIntLittle(u8),
1450 2 => try in_stream.readIntLittle(u16),
1451 4 => try in_stream.readIntLittle(u32),
1452 8 => try in_stream.readIntLittle(u64),
1453 -1 => if (signed) try readULeb128(in_stream) else @intCast(u64, try readILeb128(in_stream)),
1454 else => unreachable,
1455 },
14501456 },
14511457 };
14521458}
......@@ -1484,9 +1490,8 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
14841490 DW.FORM_data4 => parseFormValueConstant(allocator, in_stream, false, 4),
14851491 DW.FORM_data8 => parseFormValueConstant(allocator, in_stream, false, 8),
14861492 DW.FORM_udata, DW.FORM_sdata => {
1487 const block_len = try readULeb128(in_stream);
14881493 const signed = form_id == DW.FORM_sdata;
1489 return parseFormValueConstant(allocator, in_stream, signed, block_len);
1494 return parseFormValueConstant(allocator, in_stream, signed, -1);
14901495 },
14911496 DW.FORM_exprloc => {
14921497 const size = try readULeb128(in_stream);