authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-23 10:05:46+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-23 10:05:46+02:00
log374d16793f115a5f35060a972fc5d3b43dac958a
tree4fc296088ba0d058987dcb442306a28d2e68f9f1
parentb095e33667972cb650341e8cfbae7ae41ca9580d

Go one instruction before the return address

The return address may not point to an area covered by the debug infos so we hope for the best and decrement the address so that it points to the caller instruction.

1 files changed, 4 insertions(+), 4 deletions(-)

std/debug.zig+4-4
...@@ -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,