authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-11 10:35:35+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-11 10:36:15+02:00
log38492b2ea4b7aac9685ede264701ac0b7bb291c0
tree05f987439c6752a72cf31a8efadca6f2a538c654
parent29ec409b52827ae815564deaecb8f7529bb47444

Fix reading of reference attributes


1 files changed, 17 insertions(+), 19 deletions(-)

std/debug.zig+17-19
...@@ -1243,9 +1243,7 @@ const FormValue = union(enum) {...@@ -1243,9 +1243,7 @@ const FormValue = union(enum) {
1243 ExprLoc: []u8,1243 ExprLoc: []u8,
1244 Flag: bool,1244 Flag: bool,
1245 SecOffset: u64,1245 SecOffset: u64,
1246 Ref: []u8,
1247 RefAddr: u64,1246 RefAddr: u64,
1248 RefSig8: u64,
1249 String: []u8,1247 String: []u8,
1250 StrPtr: u64,1248 StrPtr: u64,
1251};1249};
...@@ -1465,14 +1463,17 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {...@@ -1465,14 +1463,17 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
1465 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLittle(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLittle(u64) else unreachable;1463 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLittle(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLittle(u64) else unreachable;
1466}1464}
14671465
1468fn parseFormValueRefLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {1466fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, size: i32) !FormValue {
1469 const buf = try readAllocBytes(allocator, in_stream, size);1467 return FormValue{
1470 return FormValue{ .Ref = buf };1468 .RefAddr = switch (size) {
1471}1469 1 => try in_stream.readIntLittle(u8),
14721470 2 => try in_stream.readIntLittle(u16),
1473fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, comptime T: type) !FormValue {1471 4 => try in_stream.readIntLittle(u32),
1474 const block_len = try in_stream.readIntLittle(T);1472 8 => try in_stream.readIntLittle(u64),
1475 return parseFormValueRefLen(allocator, in_stream, block_len);1473 -1 => try readULeb128(in_stream),
1474 else => unreachable,
1475 },
1476 };
1476}1477}
14771478
1478fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) anyerror!FormValue {1479fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) anyerror!FormValue {
...@@ -1502,17 +1503,14 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64...@@ -1502,17 +1503,14 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
1502 DW.FORM_flag_present => FormValue{ .Flag = true },1503 DW.FORM_flag_present => FormValue{ .Flag = true },
1503 DW.FORM_sec_offset => FormValue{ .SecOffset = try parseFormValueDwarfOffsetSize(in_stream, is_64) },1504 DW.FORM_sec_offset => FormValue{ .SecOffset = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
15041505
1505 DW.FORM_ref1 => parseFormValueRef(allocator, in_stream, u8),1506 DW.FORM_ref1 => parseFormValueRef(allocator, in_stream, 1),
1506 DW.FORM_ref2 => parseFormValueRef(allocator, in_stream, u16),1507 DW.FORM_ref2 => parseFormValueRef(allocator, in_stream, 2),
1507 DW.FORM_ref4 => parseFormValueRef(allocator, in_stream, u32),1508 DW.FORM_ref4 => parseFormValueRef(allocator, in_stream, 4),
1508 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, u64),1509 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, 8),
1509 DW.FORM_ref_udata => {1510 DW.FORM_ref_udata => parseFormValueRef(allocator, in_stream, -1),
1510 const ref_len = try readULeb128(in_stream);
1511 return parseFormValueRefLen(allocator, in_stream, ref_len);
1512 },
15131511
1514 DW.FORM_ref_addr => FormValue{ .RefAddr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },1512 DW.FORM_ref_addr => FormValue{ .RefAddr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
1515 DW.FORM_ref_sig8 => FormValue{ .RefSig8 = try in_stream.readIntLittle(u64) },1513 DW.FORM_ref_sig8 => FormValue{ .RefAddr = try in_stream.readIntLittle(u64) },
15161514
1517 DW.FORM_string => FormValue{ .String = try readStringRaw(allocator, in_stream) },1515 DW.FORM_string => FormValue{ .String = try readStringRaw(allocator, in_stream) },
1518 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },1516 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },