Project

General

Profile

Actions

Feature #578

closed

add method to disassemble Proc objects

Added by rogerdpack (Roger Pack) about 16 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
[ruby-core:18762]

Description

=begin
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
=end


Files

add_disassemble_proc.diff (889 Bytes) add_disassemble_proc.diff rogerdpack (Roger Pack), 09/21/2008 03:10 AM
iseq.diff (786 Bytes) iseq.diff rogerdpack (Roger Pack), 01/20/2010 05:14 AM
Actions #1

Updated by ko1 (Koichi Sasada) about 16 years ago

  • Assignee set to ko1 (Koichi Sasada)

=begin

=end

Actions #2

Updated by yugui (Yuki Sonoda) about 16 years ago

  • Target version set to 2.0.0

=begin

=end

Actions #3

Updated by rogerdpack (Roger Pack) about 16 years ago

=begin
Question: any chance of getting this [or something like it] included before feature freezing all the way?
Thanks all. Ruby rox :)
=end

Actions #4

Updated by ko1 (Koichi Sasada) almost 16 years ago

  • Priority changed from Normal to 3

=begin
I want to fix it with modifying ISeq#disasm to receive Proc object on 1.9.2. Sorry for late response.
=end

Actions #5

Updated by rogerdpack (Roger Pack) almost 16 years ago

=begin
thanks for looking into that :)
-=R
=end

Actions #6

Updated by rogerdpack (Roger Pack) over 15 years ago

=begin
Any progress on this? any way I can help?
Thanks!
-=r
=end

Actions #7

Updated by nobu (Nobuyoshi Nakada) over 15 years ago

=begin
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

=end

Actions #8

Updated by rocky (Rocky Bernstein) over 15 years ago

=begin
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.
=end

Actions #9

Updated by rogerdpack (Roger Pack) about 15 years ago

=begin
Would it be possible for somebody to commit this? Do we need more approval?
Thanks.
-r
=end

Actions #10

Updated by matz (Yukihiro Matsumoto) about 15 years ago

=begin
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 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.

=end

Actions #11

Updated by ko1 (Koichi Sasada) about 15 years ago

=begin
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

=end

Actions #12

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r25258.
=end

Actions #13

Updated by rogerdpack (Roger Pack) almost 15 years ago

=begin
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
=end

Actions #14

Updated by marcandre (Marc-Andre Lafortune) almost 15 years ago

  • Category set to core
  • Status changed from Closed to Open
  • Target version changed from 2.0.0 to 1.9.2

=begin
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 '

=end

Actions #15

Updated by rogerdpack (Roger Pack) almost 15 years ago

=begin
This diff appears to fix it, if somebody could take a look at it.
Thanks.
-r

=end

Actions #16

Updated by rogerdpack (Roger Pack) almost 15 years ago

  • Status changed from Open to Closed

=begin
Appears fixed now. Thanks!

r26363
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0