Project

General

Profile

Actions

Bug #18740

open

Use of rightward assignment changes line number needed for line-targeted TracePoint

Added by hurricup (Alexandr Evstigneev) over 2 years ago. Updated 8 months ago.

Status:
Assigned
Target version:
-
[ruby-core:108281]

Description

Affected ruby 3.1.1

Sample illustrating the problem (test.rb):

def foo
  File.read("test.rb")
      .split("\n")
      .map(&:strip)
      .reject(&:empty?)
      .first(10) => lines

  puts lines
end

TracePoint.new(:line){ puts 'Hi' }.enable(target: RubyVM::InstructionSequence.of(method :foo), target_line: 2)
foo

produces

<internal:trace_point>:212:in `enable': can not enable any hooks (ArgumentError)

iseq for method:

== disasm: #<ISeq:foo@/home/hurricup/test.rb:1 (1,0)-(9,3)> (catch: FALSE)
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] lines@0
0000 putnil                                                           (   6)[LiCa]
0001 putnil
0002 putobject                              false
0004 putnil
0005 putnil
0006 opt_getinlinecache                     15, <is:0>                (   2)
0009 putobject                              true
0011 getconstant                            :File
0013 opt_setinlinecache                     <is:0>
0015 putstring                              "test.rb"
0017 opt_send_without_block                 <calldata!mid:read, argc:1, ARGS_SIMPLE>
0019 putstring                              "\n"                      (   3)
0021 opt_send_without_block                 <calldata!mid:split, argc:1, ARGS_SIMPLE>
0023 putobject                              :strip                    (   4)
0025 send                                   <calldata!mid:map, argc:0, ARGS_BLOCKARG>, nil
0028 putobject                              :empty?                   (   5)
0030 send                                   <calldata!mid:reject, argc:0, ARGS_BLOCKARG>, nil
0033 putobject                              10                        (   6)
0035 opt_send_without_block                 <calldata!mid:first, argc:1, ARGS_SIMPLE>
0037 dup
0038 setlocal_WC_0                          lines@0
0040 jump                                   88
0042 putspecialobject                       1                         (   2)
0044 topn                                   4
0046 branchif                               64
0048 putobject                              NoMatchingPatternError
0050 putspecialobject                       1
0052 putobject                              "%p: %s"
0054 topn                                   4
0056 topn                                   7
0058 opt_send_without_block                 <calldata!mid:core#sprintf, argc:3, ARGS_SIMPLE>
0060 opt_send_without_block                 <calldata!mid:core#raise, argc:2, ARGS_SIMPLE>
0062 jump                                   84
0064 putobject                              NoMatchingPatternKeyError
0066 putspecialobject                       1
0068 putobject                              "%p: %s"
0070 topn                                   4
0072 topn                                   7
0074 opt_send_without_block                 <calldata!mid:core#sprintf, argc:3, ARGS_SIMPLE>
0076 topn                                   7
0078 topn                                   9
0080 opt_send_without_block                 <calldata!mid:new, argc:3, kw:[matchee,key], KWARG>
0082 opt_send_without_block                 <calldata!mid:core#raise, argc:1, ARGS_SIMPLE>
0084 adjuststack                            7
0086 jump                                   90
0088 adjuststack                            6                         (   6)
0090 putself                                                          (   8)[Li]
0091 getlocal_WC_0                          lines@0
0093 opt_send_without_block                 <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>
0095 leave                                                            (   9)[Re]

Works like a charm without => lines

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0