Project

General

Profile

Feature #14694

TracePoint#parameters

Added by mame (Yusuke Endoh) almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:86567]

Description

Currently, we cannot get the block parameters' information in TracePoint b_call hooks.
Also, it is (possible but) not easy to get the method parameters in call hooks.

[1] https://speakerdeck.com/valich/automated-type-contracts-generation-1#29

To make it easy, how about adding TracePoint#parameters?

TracePoint.new(:call, :b_call, :c_call) do |tp|
  p [tp.event, tp.parameters]
end

# call
def foo(a, b=1); end; foo(1)
#=> [:call, [[:req, :a], [:opt, :b]]]

# b_call
1.times {|x, y=1| }
#=> [:b_call, [[:req, :x], [:opt, :y]]]

# c_call
"".getbyte(0)
#=> [:c_call, [[:req]]]

A patch is attached.


Files

tracepoint-parameters.patch (4.75 KB) tracepoint-parameters.patch mame (Yusuke Endoh), 04/18/2018 02:06 AM
#1

Updated by mame (Yusuke Endoh) almost 2 years ago

  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN)
  • Tracker changed from Bug to Feature
#2

Updated by mame (Yusuke Endoh) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63562.


Add TracePoint#parameters

It can be used to get the parameters' information of method and block.
There was no way to get block parameters.
It was possible but ineffective to get method parameters via Method
object: tp.defined_class.method(tp.method_id).parameters
TracePoint#parameters allows us to get the information easily.
[Feature #14694]

Also available in: Atom PDF