diff --git a/compile.c b/compile.c index a6ce631513..b25edcb8d2 100644 --- a/compile.c +++ b/compile.c @@ -18,6 +18,10 @@ #include "insns.inc" #include "insns_info.inc" +#ifdef HAVE_DLADDR +# include +#endif + #define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG)) #define FIXNUM_OR(n, i) ((n)|INT2FIX(i)) @@ -5604,7 +5608,17 @@ insn_data_to_s_detail(INSN *iobj) rb_str_cat2(str, ""); break; case TS_FUNCPTR: - rb_str_catf(str, "<%p>", (rb_insn_func_t)OPERAND_AT(iobj, j)); + { + rb_insn_func_t func = (rb_insn_func_t)OPERAND_AT(iobj, j); +#ifdef HAVE_DLADDR + Dl_info info; + if (dladdr(func, &info) && info.dli_sname) { + rb_str_cat2(str, info.dli_sname); + break; + } +#endif + rb_str_catf(str, "<%p>", func); + } break; default:{ rb_raise(rb_eSyntaxError, "unknown operand type: %c", type); diff --git a/iseq.c b/iseq.c index 297299e00a..7e1ac877c1 100644 --- a/iseq.c +++ b/iseq.c @@ -13,6 +13,10 @@ #include "ruby/util.h" #include "eval_intern.h" +#ifdef HAVE_DLADDR +# include +#endif + /* #define RUBY_MARK_FREE_DEBUG 1 */ #include "gc.h" #include "vm_core.h" @@ -1375,7 +1379,16 @@ rb_insn_operand_intern(const rb_iseq_t *iseq, break; case TS_FUNCPTR: - ret = rb_str_new2(""); + { +#ifdef HAVE_DLADDR + Dl_info info; + if (dladdr((void *)op, &info) && info.dli_sname) { + ret = rb_str_new_cstr(info.dli_sname); + break; + } +#endif + ret = rb_str_new2(""); + } break; default: