summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-06 14:13:14 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-06 23:25:11 +0200
commita486adc4e377611f1bcd957afe8c3ff6643e75c4 (patch)
tree989043281622c7bfe13f60b247fcc92f61632fc7
parent41ccd193acceb1532ab1372433351c0a1eac59c2 (diff)
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 <jo@mein.io>
-rw-r--r--vm.c7
1 files 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);