In this section:
- General steps
- Starting remote debug session
- Creating a local copy of a script
- Setting breakpoints
- Configuring run/debug configuration for remote debugging
- Running remote run/debug configuration in the debug mode
RubyMine provides the possibility of remote debugging for Ruby and Rails applications, using the dedicated Ruby remote debug configuration. So doing, RubyMine keeps mapping between the local sources, and the sources on the server side.
Several debug processes can be launched simultaneously. So doing, each remote debug process starts in a separate tab in the Debug tool window, with the name Remote debug for <script name>. You can work with each debugging session as usual.
The common format of the command is as follows:
rdebug-ide --host 0.0.0.0 --port <port number> --dispatcher-port <port number> -- $COMMAND$
You can see this command as a tip in the Ruby remote run/debug configuration dialog.
To debug an application remotely, follow these general steps
- Start remote debug session.
- Create local copy of the script to be debugged, and then set the required breakpoints.
- Create or edit Ruby remote debug configuration.
- Launch the debug server. To do that, type the following command on the server side:
and then press Enter.
rdebug-ide --host <host_name> --port <local port number> --dispatcher-port <remote port number> $COMMAND$
Here <local port number> is local port on the remote host, <remote port number> - is the port on the local machine, where you want to debug, and
$COMMAND$is the name of the script or application to be debugged.
For example, to remotely debug a Rails application, run the following command on the remote host:
rdebug-ide --port 1234 --dispatcher-port 26162 –host 0.0.0.0 – bin/rails s -b 0.0.0.0
Also make sure that the gem
ruby-debug-ideis bundled to the project.
- In RubyMine, select the desired Ruby remote debug configuration, open Ruby script in the editor, and click on the main toolbar.
Starting remote debug session
To launch the remote debug session, follow these steps
- On the main menu, choose .
- Choose Edit Credentials, and specify port number, user name and password, and then click OK:
The remote connection starts in the dedicated tab of the local terminal.
- In the terminal, type the command starting the remote debug session, for example:
rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -/home/user/RubymineProjects/remote-debug-example/math_wiz.rb
Here port is the port number on the remote host.
dispatcher-port is the port number on the local host.
Creating a local copy of a script
In order to open our script in RubyMine to set breakpoints and finally start debugging, we need to copy it to the local host. The fastest way is to switch to the local tab of the Terminal tool window and copy the script to be debugged, for example:
#create a local folder mkdir ~/RubymineProjects/remote-debug-example #copy file to the local folder scp user@remote-host:RubymineProjects/remote-debug-example/math_wiz.rb ~/RubymineProjects/remote-debug-example/
Then open the folder with the copied script in RubyMine. RubyMine creates a new project, and prompts you to configure an interpreter for it.
In the newly created project, open the script in question for editing and set the breakpoints as required.
Configuring run/debug configuration for remote debugging
To configure run/debug configuration for remote debug, follow these steps
- On the main menu, choose .
- In the Run/Debug Configurations dialog box, click and choose
Ruby remote debug configuration. The configuration of the selected type named
- Specify the configuration name, for example, 'Remote debug configuration'.
- Specify the parameters of this configuration:
- The name of the remote host
- The number of the remote port, which should be the same as was used on starting the remote debug session.
- In the Remote root folder specify the remote path to the script, e.g.
- Local port should be the same as the port 'dispatcher'.
- Local root folder should be the folder where the copied script is located on the local host,
/Users/jetbrains/RubymineProjects/remote-debug-example. This folder is the same as the one that contains the copied script.
- Apply changes and save this configuration.
Now we are ready to connect to the remote session and debug the script.
Running remote run/debug configuration in the debug mode
Run 'Remote debug configuration' in the debug mode, which is the only available mode. Local debugger connects to the remote session and stops on the breakpoint that was set locally in our script.
See the detailed instructions in the tutorial.