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) {...@@ -1251,13 +1251,12 @@ const FormValue = union(enum) {
1251};1251};
12521252
1253const Constant = struct {1253const Constant = struct {
1254 payload: []u8,1254 payload: u64,
1255 signed: bool,1255 signed: bool,
12561256
1257 fn asUnsignedLe(self: *const Constant) !u64 {1257 fn asUnsignedLe(self: *const Constant) !u64 {
1258 if (self.payload.len > @sizeOf(u64)) return error.InvalidDebugInfo;
1259 if (self.signed) return error.InvalidDebugInfo;1258 if (self.signed) return error.InvalidDebugInfo;
1260 return mem.readVarInt(u64, self.payload, builtin.Endian.Little);1259 return self.payload;
1261 }1260 }
1262};1261};
12631262
...@@ -1442,11 +1441,18 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !...@@ -1442,11 +1441,18 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !
1442 return parseFormValueBlockLen(allocator, in_stream, block_len);1441 return parseFormValueBlockLen(allocator, in_stream, block_len);
1443}1442}
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 {
1446 return FormValue{1445 return FormValue{
1447 .Const = Constant{1446 .Const = Constant{
1448 .signed = signed,1447 .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 },
1450 },1456 },
1451 };1457 };
1452}1458}
...@@ -1484,9 +1490,8 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64...@@ -1484,9 +1490,8 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
1484 DW.FORM_data4 => parseFormValueConstant(allocator, in_stream, false, 4),1490 DW.FORM_data4 => parseFormValueConstant(allocator, in_stream, false, 4),
1485 DW.FORM_data8 => parseFormValueConstant(allocator, in_stream, false, 8),1491 DW.FORM_data8 => parseFormValueConstant(allocator, in_stream, false, 8),
1486 DW.FORM_udata, DW.FORM_sdata => {1492 DW.FORM_udata, DW.FORM_sdata => {
1487 const block_len = try readULeb128(in_stream);
1488 const signed = form_id == DW.FORM_sdata;1493 const signed = form_id == DW.FORM_sdata;
1489 return parseFormValueConstant(allocator, in_stream, signed, block_len);1494 return parseFormValueConstant(allocator, in_stream, signed, -1);
1490 },1495 },
1491 DW.FORM_exprloc => {1496 DW.FORM_exprloc => {
1492 const size = try readULeb128(in_stream);1497 const size = try readULeb128(in_stream);