ruby-changes:36777
From: nobu <ko1@a...>
Date: Tue, 16 Dec 2014 10:14:44 +0900 (JST)
Subject: [ruby-changes:36777] nobu:r48858 (trunk): iseq.c: show function name if possible
nobu 2014-12-16 10:14:27 +0900 (Tue, 16 Dec 2014) New Revision: 48858 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48858 Log: iseq.c: show function name if possible * iseq.c (rb_insn_operand_intern): show the name of the nearest run-time symbol if possible. * compile.c (insn_data_to_s_detail): ditto. Modified files: trunk/compile.c trunk/iseq.c Index: iseq.c =================================================================== --- iseq.c (revision 48857) +++ iseq.c (revision 48858) @@ -13,6 +13,10 @@ https://github.com/ruby/ruby/blob/trunk/iseq.c#L13 #include "ruby/util.h" #include "eval_intern.h" +#ifdef HAVE_DLADDR +# include <dlfcn.h> +#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 * https://github.com/ruby/ruby/blob/trunk/iseq.c#L1379 break; case TS_FUNCPTR: - ret = rb_str_new2("<funcptr>"); + { +#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("<funcptr>"); + } break; default: Index: compile.c =================================================================== --- compile.c (revision 48857) +++ compile.c (revision 48858) @@ -18,6 +18,10 @@ https://github.com/ruby/ruby/blob/trunk/compile.c#L18 #include "insns.inc" #include "insns_info.inc" +#ifdef HAVE_DLADDR +# include <dlfcn.h> +#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) https://github.com/ruby/ruby/blob/trunk/compile.c#L5608 rb_str_cat2(str, "<ch>"); 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/