Project

General

Profile

Actions

Bug #18974

closed

Wrong line number in the rescue iseq for the exception matching code

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

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.7.5,3.1.2
[ruby-core:109658]

Description

Script for demonstration:

def foo
  begin
    raise 'error'
  rescue => e
    puts e.message
  end
end

puts RubyVM::InstructionSequence.of(method :foo).disasm

Disasm for the catch table:

| catch type: rescue st: 0000 ed: 0005 sp: 0000 cont: 0006
| == disasm: #<ISeq:rescue in foo@/home/hurricup/projects/untitled14/test.rb:4 (4,2)-(5,18)> (catch: TRUE)
| local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
| [ 1] $!@0
| 0000 getlocal_WC_0                          $!@0                      (   5)[Li]
| 0002 putobject                              StandardError
| 0004 checkmatch                             3
| 0006 branchunless                           20
| 0008 getlocal_WC_0                          $!@0                      (   4)
| 0010 setlocal_WC_1                          e@0
| 0012 putself                                                          (   5)
| 0013 getlocal_WC_1                          e@0
| 0015 opt_send_without_block                 <calldata!mid:message, argc:0, ARGS_SIMPLE>
| 0017 opt_send_without_block                 <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>
| 0019 leave
| 0020 getlocal_WC_0                          $!@0
| 0022 throw                                  0
| catch type: retry  st: 0005 ed: 0006 sp: 0000 cont: 0000
|------------------------------------------------------------------------

For some reason first instruction info has line 5, instead of 4.
If rescue block is empty, line number is correct.

The user story is: when debugging and put bp at line 5, it triggers on the first instruction and e is not yet initialized and can't be inspected. This is confusing.

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

I've submitted a pull request to fix this issue: https://github.com/ruby/ruby/pull/6283

Actions #2

Updated by jeremyevans (Jeremy Evans) about 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|f5d73da8062377e5b93100c6ea109a37bd04b4c1.


Fix the position of rescue clause without exc_list

If the rescue clause has only exc_var and not exc_list, use the
exc_var position instead of the rescue body position.

This issue appears to have been introduced in
688169fd83b24564b653c03977c168cea50ccd35 when "opt_list" was split
into "exc_list exc_var".

Fixes [Bug #18974]

Actions

Also available in: Atom PDF

Like0
Like0Like0