authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-23 10:15:53-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-04-23 10:15:53-04:00
log3bc361178c0f37ee9ffb67698401027a9f656664
tree4fc296088ba0d058987dcb442306a28d2e68f9f1
parent0f8fc3b924ac0d971a800bc6e3b6c931612e06a6
parent374d16793f115a5f35060a972fc5d3b43dac958a
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2344 from LemonBoy/dbg-things

Minor debug things

1 files changed, 16 insertions(+), 15 deletions(-)

std/debug.zig+16-15
...@@ -221,7 +221,7 @@ pub fn writeStackTrace(...@@ -221,7 +221,7 @@ pub fn writeStackTrace(
221 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;221 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;
222 }) {222 }) {
223 const return_address = stack_trace.instruction_addresses[frame_index];223 const return_address = stack_trace.instruction_addresses[frame_index];
224 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);224 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_color);
225 }225 }
226}226}
227227
...@@ -263,7 +263,7 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color...@@ -263,7 +263,7 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color
263 }263 }
264 var it = StackIterator.init(start_addr);264 var it = StackIterator.init(start_addr);
265 while (it.next()) |return_address| {265 while (it.next()) |return_address| {
266 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);266 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_color);
267 }267 }
268}268}
269269
...@@ -689,9 +689,9 @@ pub fn printSourceAtAddressDwarf(...@@ -689,9 +689,9 @@ pub fn printSourceAtAddressDwarf(
689 return;689 return;
690 };690 };
691 const compile_unit_name = try compile_unit.die.getAttrString(debug_info, DW.AT_name);691 const compile_unit_name = try compile_unit.die.getAttrString(debug_info, DW.AT_name);
692 if (getLineNumberInfoDwarf(debug_info, compile_unit.*, address - 1)) |line_info| {692 if (getLineNumberInfoDwarf(debug_info, compile_unit.*, address)) |line_info| {
693 defer line_info.deinit();693 defer line_info.deinit();
694 const symbol_name = getSymbolNameDwarf(debug_info, address - 1) orelse "???";694 const symbol_name = getSymbolNameDwarf(debug_info, address) orelse "???";
695 try printLineInfo(695 try printLineInfo(
696 out_stream,696 out_stream,
697 line_info,697 line_info,
...@@ -1460,7 +1460,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo...@@ -1460,7 +1460,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
1460 2 => try in_stream.readIntLittle(u16),1460 2 => try in_stream.readIntLittle(u16),
1461 4 => try in_stream.readIntLittle(u32),1461 4 => try in_stream.readIntLittle(u32),
1462 8 => try in_stream.readIntLittle(u64),1462 8 => try in_stream.readIntLittle(u64),
1463 -1 => if (signed) @intCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),1463 -1 => if (signed) @bitCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),
1464 else => @compileError("Invalid size"),1464 else => @compileError("Invalid size"),
1465 },1465 },
1466 },1466 },
...@@ -2051,7 +2051,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {...@@ -2051,7 +2051,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
2051 this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;2051 this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
2052 } else if (this_die_obj.getAttr(DW.AT_specification)) |ref| {2052 } else if (this_die_obj.getAttr(DW.AT_specification)) |ref| {
2053 // Follow the DIE it points to and repeat2053 // Follow the DIE it points to and repeat
2054 const ref_offset = try this_die_obj.getAttrRef(DW.AT_abstract_origin);2054 const ref_offset = try this_die_obj.getAttrRef(DW.AT_specification);
2055 if (ref_offset > next_offset) return error.InvalidDebugInfo;2055 if (ref_offset > next_offset) return error.InvalidDebugInfo;
2056 try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset);2056 try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset);
2057 this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;2057 this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
...@@ -2272,14 +2272,15 @@ fn readILeb128Mem(ptr: *[*]const u8) !i64 {...@@ -2272,14 +2272,15 @@ fn readILeb128Mem(ptr: *[*]const u8) !i64 {
2272 const byte = ptr.*[i];2272 const byte = ptr.*[i];
2273 i += 1;2273 i += 1;
22742274
2275 var operand: i64 = undefined;2275 if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
2276 if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
22772276
2278 result |= operand;2277 result |= i64(byte & 0b01111111) << @intCast(u6, shift);
2279 shift += 7;2278 shift += 7;
22802279
2281 if ((byte & 0b10000000) == 0) {2280 if ((byte & 0b10000000) == 0) {
2282 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));2281 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
2282 result |= -(i64(1) << @intCast(u6, shift));
2283 }
2283 ptr.* += i;2284 ptr.* += i;
2284 return result;2285 return result;
2285 }2286 }
...@@ -2323,15 +2324,15 @@ fn readILeb128(in_stream: var) !i64 {...@@ -2323,15 +2324,15 @@ fn readILeb128(in_stream: var) !i64 {
2323 while (true) {2324 while (true) {
2324 const byte = try in_stream.readByte();2325 const byte = try in_stream.readByte();
23252326
2326 var operand: i64 = undefined;2327 if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
23272328
2328 if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;2329 result |= i64(byte & 0b01111111) << @intCast(u6, shift);
2329
2330 result |= operand;
2331 shift += 7;2330 shift += 7;
23322331
2333 if ((byte & 0b10000000) == 0) {2332 if ((byte & 0b10000000) == 0) {
2334 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));2333 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
2334 result |= -(i64(1) << @intCast(u6, shift));
2335 }
2335 return result;2336 return result;
2336 }2337 }
2337 }2338 }