Project

General

Profile

Bug #15484 ยป tracepoint-docs.patch

zverok (Victor Shepelev), 12/29/2018 11:32 AM

View differences:

prelude.rb
133 133
end
134 134

  
135 135
class TracePoint
136
  # call-seq:
137
  #  trace.enable(target: nil, target_line: nil)    -> true or false
138
  #  trace.enable(target: nil, target_line: nil) { block }  -> obj
139
  #
140
  # Activates the trace
141
  #
142
  # Return +true+ if trace was enabled.
143
  # Return +false+ if trace was disabled.
144
  #
145
  #   trace.enabled?  #=> false
146
  #   trace.enable    #=> false (previous state)
147
  #                   #   trace is enabled
148
  #   trace.enabled?  #=> true
149
  #   trace.enable    #=> true (previous state)
150
  #                   #   trace is still enabled
151
  #
152
  # If a block is given, the trace will only be enabled within the scope of the
153
  # block.
154
  #
155
  #    trace.enabled?
156
  #    #=> false
157
  #
158
  #    trace.enable do
159
  #        trace.enabled?
160
  #        # only enabled for this block
161
  #    end
162
  #
163
  #    trace.enabled?
164
  #    #=> false
165
  #
166
  # <i>target</i> and <i>target_line</i> parameters are used to limit tracing
167
  # only to specified code objects. <i>target</i> should be a code object for
168
  # which RubyVM::InstructionSequence.of will return instruction sequence.
169
  #
170
  #    t = TracePoint.new(:line) { |tp| p tp }
171
  #
172
  #    def m1
173
  #        p 1
174
  #    end
175
  #
176
  #    def m2
177
  #        p 2
178
  #    end
179
  #
180
  #    t.enable(target: method(:m1))
181
  #
182
  #    m1
183
  #    # prints #<TracePoint:line@test.rb:5 in `m1'>
184
  #    m2
185
  #    # prints nothing
186
  #
187
  #
188
  # Note: You cannot access event hooks within the +enable+ block.
189
  #
190
  #    trace.enable { p tp.lineno }
191
  #    #=> RuntimeError: access from outside
192
  #
136 193
  def enable target: nil, target_line: nil, &blk
137 194
    self.__enable target, target_line, &blk
138 195
  end
vm_trace.c
1058 1058
}
1059 1059

  
1060 1060
/*
1061
 * Return the parameters of the method or block that the current hook belongs to
1061
 * Return the parameters definition of the method or block that the
1062
 * current hook belongs to. Format is the same as for Method#parameters
1062 1063
 */
1063 1064
static VALUE
1064 1065
tracepoint_attr_parameters(VALUE tpval)
......
1360 1361
    list->events = events;
1361 1362
}
1362 1363

  
1363
/*
1364
 * call-seq:
1365
 *	trace.enable		-> true or false
1366
 *	trace.enable { block }	-> obj
1367
 *
1368
 * Activates the trace
1369
 *
1370
 * Return true if trace was enabled.
1371
 * Return false if trace was disabled.
1372
 *
1373
 *	trace.enabled?  #=> false
1374
 *	trace.enable    #=> false (previous state)
1375
 *                      #   trace is enabled
1376
 *	trace.enabled?  #=> true
1377
 *	trace.enable    #=> true (previous state)
1378
 *                      #   trace is still enabled
1379
 *
1380
 * If a block is given, the trace will only be enabled within the scope of the
1381
 * block.
1382
 *
1383
 *	trace.enabled?
1384
 *	#=> false
1385
 *
1386
 *	trace.enable do
1387
 *	    trace.enabled?
1388
 *	    # only enabled for this block
1389
 *	end
1390
 *
1391
 *	trace.enabled?
1392
 *	#=> false
1393
 *
1394
 * Note: You cannot access event hooks within the block.
1395
 *
1396
 *	trace.enable { p tp.lineno }
1397
 *	#=> RuntimeError: access from outside
1398
 *
1364
/* :nodoc:
1365
 * Docs for the TracePointe#enable are in prelude.rb
1399 1366
 */
1400 1367
static VALUE
1401 1368
tracepoint_enable_m(VALUE tpval, VALUE target, VALUE target_line)
......
1780 1747
     * +:thread_begin+:: event hook at thread beginning
1781 1748
     * +:thread_end+:: event hook at thread ending
1782 1749
     * +:fiber_switch+:: event hook at fiber switch
1750
     * +:script_compiled+:: new Ruby code compiled (with +eval+, +load+ or +require+)
1783 1751
     *
1784 1752
     */
1785 1753
    rb_cTracePoint = rb_define_class("TracePoint", rb_cObject);