From a9f555d91653b0eddabbd46783896d91cd4aaf2d Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Wed, 12 Mar 2025 20:52:02 +0100 Subject: [PATCH] Print source on SIGSEGV --- debugus.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/debugus.c b/debugus.c index 00d35ce..fc72b45 100644 --- a/debugus.c +++ b/debugus.c @@ -54,6 +54,8 @@ int msleep(long msec) #define INIT_SCRIPT ".debugusrc.js" #define MAX_JS_FUNCS 100 +#define SOURCE_EXPANSION 4 + void print_source(const char *file, size_t line) { FILE *src = fopen(file, "r"); @@ -69,7 +71,7 @@ void print_source(const char *file, size_t line) fread(srcbuf, sz, 1, src); srcbuf[sz] = '\0'; - const int expand = 4; + const int expand = SOURCE_EXPANSION; char *p = srcbuf; size_t i = 0; @@ -257,6 +259,11 @@ void dbg_handle_sigsegv(Dbg *dbg, siginfo_t info) AddrInfo *ai = libelfin_wrap_info_from_rip(dbg->plibelfin, (uint64_t)(addr - dbg->program_load_offset)); if (ai != NULL) { LOG_INF("%s:%zu in function %s()\n", ai->file, (size_t)ai->line, dbg->symbols.items[i].name); + AddrInfo *ai2 = libelfin_wrap_info_from_rip(dbg->plibelfin, (uint64_t)(rip - dbg->program_load_offset)); + if (ai2 != NULL) { + print_source(ai2->file, ai2->line); + libelfin_wrap_free_info(ai2); + } libelfin_wrap_free_info(ai); } break;