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) {
12431243 ExprLoc: []u8,
12441244 Flag: bool,
12451245 SecOffset: u64,
1246 Ref: []u8,
12471246 RefAddr: u64,
1248 RefSig8: u64,
12491247 String: []u8,
12501248 StrPtr: u64,
12511249};
......@@ -1465,14 +1463,17 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
14651463 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLittle(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLittle(u64) else unreachable;
14661464}
14671465
1468fn parseFormValueRefLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
1469 const buf = try readAllocBytes(allocator, in_stream, size);
1470 return FormValue{ .Ref = buf };
1471}
1472
1473fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, comptime T: type) !FormValue {
1474 const block_len = try in_stream.readIntLittle(T);
1475 return parseFormValueRefLen(allocator, in_stream, block_len);
1466fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, size: i32) !FormValue {
1467 return FormValue{
1468 .RefAddr = switch (size) {
1469 1 => try in_stream.readIntLittle(u8),
1470 2 => try in_stream.readIntLittle(u16),
1471 4 => try in_stream.readIntLittle(u32),
1472 8 => try in_stream.readIntLittle(u64),
1473 -1 => try readULeb128(in_stream),
1474 else => unreachable,
1475 },
1476 };
14761477}
14771478
14781479fn 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
15021503 DW.FORM_flag_present => FormValue{ .Flag = true },
15031504 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_ref2 => parseFormValueRef(allocator, in_stream, u16),
1507 DW.FORM_ref4 => parseFormValueRef(allocator, in_stream, u32),
1508 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, u64),
1509 DW.FORM_ref_udata => {
1510 const ref_len = try readULeb128(in_stream);
1511 return parseFormValueRefLen(allocator, in_stream, ref_len);
1512 },
1506 DW.FORM_ref1 => parseFormValueRef(allocator, in_stream, 1),
1507 DW.FORM_ref2 => parseFormValueRef(allocator, in_stream, 2),
1508 DW.FORM_ref4 => parseFormValueRef(allocator, in_stream, 4),
1509 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, 8),
1510 DW.FORM_ref_udata => parseFormValueRef(allocator, in_stream, -1),
15131511
15141512 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
15171515 DW.FORM_string => FormValue{ .String = try readStringRaw(allocator, in_stream) },
15181516 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },