Bug #18740
openUse of rightward assignment changes line number needed for line-targeted TracePoint
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
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
- Subject changed from Unable to set a tracepoint on the code with rightward assignment to Use of rightward assignment changes line number needed for line-targeted TracePoint
You can set a tracepoint, rightward assignment just moves the line you need to target. In your example, you have to use target_line: 6
instead of target_line: 2
. I'm not sure if this is considered a bug or not.
Updated by hurricup (Alexandr Evstigneev) over 2 years ago
jeremyevans0 (Jeremy Evans) wrote in #note-1:
You can set a tracepoint, rightward assignment just moves the line you need to target. In your example, you have to use
target_line: 6
instead oftarget_line: 2
. I'm not sure if this is considered a bug or not.
Yes, I can see that. But his is not intuitive for the debugger user and too big difference for the case without => lines
, where you can use line 2. This is not a bug (like segfault or smth) but more like usability issue.
Feels like you should be able to debug full expression, not only assigning part.
Updated by ko1 (Koichi Sasada) over 2 years ago
FYI: Using debug.gem
[master]$ rdbg target.rb
[1, 10] in target.rb
=> 1| def foo
2| File.read(__FILE__)
3| .split("\n")
4| .map(&:strip)
5| .reject(&:empty?)
6| .first(10) => lines
7|
8| puts lines
9| end
10|
=>#0 <main> at target.rb:1
(rdbg) b 2 # break command
#0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:6 (call)
(rdbg) c # continue command
[1, 10] in target.rb
1| def foo
2| File.read(__FILE__)
3| .split("\n")
4| .map(&:strip)
5| .reject(&:empty?)
=> 6| .first(10) => lines
7|
8| puts lines
9| end
10|
=>#0 Object#foo at target.rb:6
#1 <main> at target.rb:11
Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:6 (call)
(rdbg)
Updated by Eregon (Benoit Daloze) over 2 years ago
Is that the expected result for debug.gem?
Shouldn't it actually stop/break before File.read(__FILE__)
, i.e., on line 2?
How can we be on line 6 already if the File.read(__FILE__)
was not executed? (break should always stop before reaching that line in all debuggers I know)
Updated by mame (Yusuke Endoh) about 2 years ago
- Assignee set to ko1 (Koichi Sasada)
Updated by hsbt (Hiroshi SHIBATA) 8 months ago
- Status changed from Open to Assigned