Skip to content

Weird behavior on catch command #609

@st0012

Description

@st0012

Your environment

  • ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin21]
  • rdbg -v: 1.5.0

Description

I spotted a weird behavior when using catch Exception or catch StandardError and then causing an exception in the console. Example:

❯ exe/rdbg -e "catch Exception do: 'debugger spotted an error' ;; raise 'foo' ;; " target.rb
[1, 1] in target.rb
=>   1| puts(123)
=>#0    <main> at target.rb:1
(rdbg:commands) catch Exception do: 'debugger spotted an error'
#0  BP - Catch  "Exception"
(rdbg:commands) raise 'foo'
[1, 1] in (rdbg)/target.rb
=>   1| raise 'foo'
=>#0    <main> at (rdbg)/target.rb:1
  #1    [C] Binding#eval at ~/projects/debug/lib/debug/thread_client.rb:369
  # and 2 frames (use `bt' command for all frames)

Stop by #0  BP - Catch  "Exception"
(rdbg:catch) 'debugger spotted an error'
"debugger spotted an error"
eval error: foo
  (rdbg)/target.rb:1:in `<main>'
nil

# catch breakpoint is triggered and performed command as expected, so far so good.
# let's run some other commands
(rdbg) ls    # outline command
Object.methods: inspect  to_s

# for some reason, the catch bp's command is triggered again
(rdbg:catch) 'debugger spotted an error'
"debugger spotted an error"

# and it exits the current bp for no apparent reason
123

Reproduction

Scripit

puts(123)

Command and output

  1. $ exe/rdbg -e "catch Exception do: 'debugger spotted an error' ;; raise 'foo' ;; " target.rb
  2. Run arbitrary debugger command, like ls

Expected Behavior

  1. The 'debugger spotted an error' message is only printed once.
  2. The arbitrary command doesn't exit the debugging session.

Actual Behavior

  1. The do: command is executed for the second time when no new exception is raised.
  2. When 1 happens, it also tries to leave the current debugging session without being told to do so.

However, if we use a more specific exception name, like catch RuntimeError, neither the problem occurs.

Therefore, I suspect that debugger has some internal exceptions happening between step 1 and 2, which triggered the catch breakpoint unexpectedly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions