From a486adc4e377611f1bcd957afe8c3ff6643e75c4 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 6 Aug 2022 14:13:14 +0200 Subject: vm: don't treat offset 0 special for exceptions Try to resolve the source offset to line and character position and only fall back to report the location as instruction offset if we weren't able to determine the line number. Signed-off-by: Jo-Philipp Wich --- vm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vm.c b/vm.c index 3a6e39e..1cf24ab 100644 --- a/vm.c +++ b/vm.c @@ -902,11 +902,11 @@ uc_vm_capture_stacktrace(uc_vm_t *vm, size_t i) static uc_value_t * uc_vm_get_error_context(uc_vm_t *vm) { + size_t offset, i, byte, line; uc_value_t *stacktrace; uc_callframe_t *frame; uc_stringbuf_t *buf; uc_chunk_t *chunk; - size_t offset, i; /* skip to first non-native function call frame */ for (i = vm->callframes.count; i > 1; i--) @@ -924,7 +924,10 @@ uc_vm_get_error_context(uc_vm_t *vm) buf = ucv_stringbuf_new(); - if (offset) + byte = offset; + line = uc_source_get_line(uc_program_function_source(frame->closure->function), &byte); + + if (line) uc_error_context_format(buf, uc_vm_frame_source(frame), stacktrace, offset); else if (frame->ip != chunk->entries) ucv_stringbuf_printf(buf, "At instruction %zu", (frame->ip - chunk->entries) - 1); -- cgit v1.2.3