Feature #578
add method to disassemble Proc objects
| Status: | Closed | Start date: | 09/21/2008 | |
|---|---|---|---|---|
| Priority: | Low | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | core | |||
| Target version: | 1.9.2 |
Description
Currently RubyVM::InstructionSequence.disassemble works only for methods. I wasn't sure how to patch RubyVM::InstructionSequence.disassemble to work with proc objects AND methods, so added a new method RubyVM::InstructionSequence.disassemble_proc which works for proc objects, in the accompanying patch. Either way would work. Hope this can be included before the feature freeze, if possible :) -=R
Associated revisions
* iseq.c (iseq_s_disasm): accept proc objects. [ruby-core:18762]
History
Updated by Koichi Sasada over 3 years ago
- Assignee set to Koichi Sasada
Updated by Yuki Sonoda over 3 years ago
- Target version set to 2.0.0
Updated by Roger Pack over 3 years ago
Question: any chance of getting this [or something like it] included before feature freezing all the way? Thanks all. Ruby rox :)
Updated by Koichi Sasada about 3 years ago
- Priority changed from Normal to Low
I want to fix it with modifying ISeq#disasm to receive Proc object on 1.9.2. Sorry for late response.
Updated by Roger Pack about 3 years ago
thanks for looking into that :) -=R
Updated by Roger Pack almost 3 years ago
Any progress on this? any way I can help? Thanks! -=r
Updated by Nobuyoshi Nakada over 2 years ago
Hi, At Sun, 21 Sep 2008 03:02:44 +0900, Roger Pack wrote in [ruby-core:18762]: > I wasn't sure how to patch > RubyVM::InstructionSequence.disassemble > to work with proc objects AND methods, so added a new method > RubyVM::InstructionSequence.disassemble_proc > which works for proc objects, in the accompanying patch. > Either way would work. It's pretty easy. Index: iseq.c =================================================================== --- iseq.c (revision 23974) +++ iseq.c (working copy) @@ -1007,4 +1007,13 @@ iseq_s_disasm(VALUE klass, VALUE body) } } + else { + rb_proc_t *proc; + VALUE iseqval; + GetProcPtr(body, proc); + iseqval = proc->block.iseq->self; + if (RUBY_VM_NORMAL_ISEQ_P(iseqval)) { + ret = rb_iseq_disasm(iseqval); + } + } return ret; -- Nobu Nakada
Updated by Rocky Bernstein over 2 years ago
Another possiblility would be to add an instruction-sequence method (iseq) into Proc. Off of the instruction sequence, one could use the methods like disasm or to_a.
The actual additional code (put in the right place) for this seems pretty small:
VALUE
proc_iseq(VALUE self)
{
rb_proc_t *proc;
rb_iseq_t *iseq;
VALUE rb_iseq;
GetProcPtr(self, proc);
iseq = proc->block.iseq;
if (!iseq) return Qnil;
rb_iseq = iseq_alloc_shared(rb_cISeq);
RDATA(rb_iseq)->data = iseq;
return rb_iseq;
}
rb_define_method(rb_cProc, "iseq", proc_iseq, 0);
Warning: the above may have flaws in it.
Updated by Roger Pack over 2 years ago
Would it be possible for somebody to commit this? Do we need more approval? Thanks. -r
Updated by Yukihiro Matsumoto over 2 years ago
Hi,
In message "Re: [ruby-core:25962] [Feature #578] add method to disassemble Proc objects"
on Tue, 6 Oct 2009 20:55:57 +0900, Roger Pack <redmine@ruby-lang.org> writes:
|Would it be possible for somebody to commit this? Do we need more approval?
Yea, a patch from Nobu in [ruby-core:24169] needs permission from
Koichi.
matz.
Updated by Koichi Sasada over 2 years ago
Roger Pack wrote:: >> Yea, a patch from Nobu in [ruby-core:24169] needs permission from >> Koichi. > > Ok. Koichi do you have any feedback on the patch? no. go ahead. -- // SASADA Koichi at atdot dot net
Updated by Nobuyoshi Nakada over 2 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r25258.
Updated by Roger Pack over 2 years ago
The fact that we can get backtraces from the VM easily almost makes me wonder if the following API is possible: Thread#backtrace_with_bindings => [[file, line, method, [[:arg1_name, current_value], [:arg2_name, current_value]] or [[file, line, method, binding]] # so you can lookup argument values if so desired mostly inspired by http://barelyenough.org/blog/2005/04/ruby-backtraces/ -- not sure if it's actually necessary/high priority since you can get somewhat higher quality backtraces using ruby-debug already (http://github.com/rdp/backtracer) Thoughts? -r
Updated by Marc-Andre Lafortune about 2 years ago
- Category set to core
- Status changed from Closed to Open
- Target version changed from 2.0.0 to 1.9.2
I didn't check the code, but isn't it supposed to make the following work?
$ rubydev -e 'RubyVM::InstructionSequence.disassemble(Proc.new{40+2})'
-e:1:in `disassemble': wrong argument type proc (expected method) (TypeError)
from -e:1:in `<main>'
Updated by Roger Pack about 2 years ago
- File iseq.diff added
This diff appears to fix it, if somebody could take a look at it. Thanks. -r
Updated by Roger Pack about 2 years ago
- Status changed from Open to Closed
Appears fixed now. Thanks! r26363