deivid-rodriguez / byebug

Debugging in Ruby 2
BSD 2-Clause "Simplified" License
3.34k stars 328 forks source link

problems using the remote debugger connections for a SublimeText Plugin #456

Open canoeberry opened 6 years ago

canoeberry commented 6 years ago

Problem description

I am trying to understand how to build a remote client as a plugin for SublimeText. I am aware there is one already but it's old and I think byebug has changed a lot since it was last updated. E.g., creating a breakpoint from the control connection now seems to require a confirmation but the Sublime plugin doesn't seem to be aware of it.

My problem, after upgrading to 10.0.2 on ruby 2.4.1, is that I cannot get either the client or the client control connections to spit out the prompt. I am sure at least the control connection worked for me with byebug 9.

I also need help understand the difference between the two connections and why there's a requirement for two, when the control connection could seemingly do everything in theory if its command list weren't restricted.

Expected behavior

I start byebug in my Rails app as follows:

  if ENV['BYEBUG']
    require 'byebug/core'
    puts "STARTING DEBUGGER"
    Byebug.start_server('localhost', 5282)
  end

I used to also do Byebug.wait_connection = true but I decided I didn't want to do that, and it didn't seem to make a difference.

Then when I telnet to the application on ports 5282 and 5283, I expected to be greeted with a prompt from at least the 5283 connection, and perhaps the 5282 connection after the program stops for some reason.

Actual behavior

Neither telnet sessions gets any output, and attempts to issue commands are ignored, as though there are no threads reading the accepted connections at all.

However, if I fire up Rails as follows:

BYEBUG=true byebug bin/rails server

the control connection does prompt me and does respond to input.

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
PROMPT (byebug:ctrl) 
help

  break     -- Sets breakpoints in the source code
  delete    -- Deletes breakpoints
  edit      -- Edits source files
  help      -- Helps you using byebug
  info      -- Shows several informations about the program being debugged
  interrupt -- Interrupts the program
  kill      -- Sends a signal to the current process
  quit      -- Exits byebug
  restart   -- Restarts the debugged program
  save      -- Saves current byebug session to a file
  set       -- Modifies byebug settings
  show      -- Shows byebug settings
  source    -- Restores a previously saved byebug session

PROMPT (byebug:ctrl) 

Steps to reproduce the problem

Fire up rails with code to start up the Byebug server, and try to connect to it via telnet.

canoeberry commented 6 years ago

Also another quick question. How does byebug implement breakpoints? Does it use the tracepoint API (as you have indicated) to get notified whenever a line of execution changes, and then check its breakpoints to see if that line matches any?

I looked at tracepoint and I don't see a native ruby mechanism for inserting breakpoint instructions, so, is it done with polling as I described?