• Stars
    star
    165
  • Rank 220,822 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

VSCode Ruby rdbg Debugger

VSCode Ruby rdbg Debugger

Ruby debugger to connect debug library which utilize recent Ruby's debug support features.

Requirement

You need to install latest debug gem and rdbg command should be in $PATH.

$ gem install debug

How to use

Launch without configuration

Without any configuration, you can use this debugger by "Start Debugging" (F5 key) if you activate .rb file.

You will see the "Debug command line" input dialog. Please specify your favorite command line you want to debug.

For example:

  • ruby foo.rb (launch foo.rb)
  • ruby foo.rb 10 20 30 (launch foo.rb with options 10, 20 and 30)
  • rake taskA (launch rake task taskA)
  • bundle exec rspec (launch rspec command with bundle exec)
  • bin/rails s (launch bin/rails s)

When you select a command line, the specified command will run on rdbg debugger, and VSCode will connect to the rdbg debugger with UNIX domain socket.

And new terminal is created (named rdbg). You can see stdout/err outputs and you can input stdin on rdbg terminal.

You can stop the programs

  • by setting breakpoints (F9) on source code.
  • by exception (if you enable "rescue exception").
  • by pushing the Pause button (F6).

When the program stops, you can see "Call stack", "Variables" and you can set "Watch" expressions. On the debug console, you can input valid Ruby program and you will get an evaluation result on selected context ("Call stack").

See also: Debugging in Visual Studio Code

For developers: RUBY_DEBUG_DAP_SHOW_PROTOCOL=1 on rdbg terminal will show the all DAP protocol.

Launch with configurations

You can write your favorite setting in .vscode/launch.json.

To make a .vscode/launch.json with default settings, you only need to click "create a launch.json file" on the "Run and Debug" pane. And you will see the following default configurations.

{
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
                {
                        "type": "rdbg",
                        "name": "Debug current file with rdbg",
                        "request": "launch",
                        "script": "${file}",
                        "args": [],
                        "askParameters": true
                },
                {
                        "type": "rdbg",
                        "name": "Attach with rdbg",
                        "request": "attach"
                }
        ]
}

It contains "Debug current file with rdbg" (launch) configuration and "Attach with rdbg" (attach) configuration. You can modify this configuration, and also you can add your favorite configuration like:

                {
                        "type": "rdbg",
                        "name": "Run rake test",
                        "request": "launch",
                        "command": "rake",
                        "script": "test", // launch rake test with debugger
                        "args": [],
                        "askParameters": false // Do not ask startup parameter any more
                },

You can use the following "launch" configurations.

  • Debuggee settings
    • script
      • A target script file name.
      • default: an active ruby file on VSCode
    • command
      • Executable Ruby command. You can specify bundle exec ruby for example.
      • default: ruby
    • cwd
      • Directory to execute the program in.
      • default: ${workspaceFolder}
    • args
      • Command line arguments passed to the program.
      • default: []
    • env
      • Additional environment variables to pass to the debugging (and debugged) process.
      • default: N/A
    • useBundler:
      • Execute Ruby programs with bundle exec if command configuration is not given. and Gemfile is available in the workspace.
      • Note that you can specify this useBundler by the extension configuration (default: true).
      • default: undefined (and the extension configuration default value is true)
  • Behavior settings
    • askParameters
      • Ask "Debug command line" before debugging. If the MAIN program is always same, set it false.
      • Note that the last invoked command is remembered.
      • default: true
    • rdbgPath
      • Location of the rdbg executable.
      • Note that you can specify this rdbgPath by the extension configuration (default: rdbg).
      • default: rdbg
    • debugPort
      • Without debugPort configuration, open a UNIX Domain Socket (or TCP/IP localhost:0 on Windows) to communicate with debuggee. If you want to use another debug port, set this configuration.
        • Digits (e.g. 12345): open a TCP/IP debug port with port 12345
        • hostname:port (e.g. hostname:12345): open a TCP/IP port 12345 and hostname hostname
        • Otherwise, open a UNIX Domain socket with the filename given by this configuration.
      • Note that you can specify 0 TCP/IP port (choose usable port) with debug.gem v1.5.0 or later.
    • waitLaunchTime
      • If you want to open TCP/IP debug port, you may need to wait for opening debug port. On default, it waits 5000 milliseconds (5 sec) but if it is not enough, please specify more wait time (default: 5000 in milliseconds).
      • With debug.gem 1.5.0 and later you may not need this configuration.
    • useTerminal
      • If the configuration is true, create a new terminal and then execute the debug command line there. It is a bit slower.
      • Otherwise, all outputs to the STDIN/OUT are shown in the DEBUG CONSOLE.
      • If you need to use STDIN, please set this option.
      • default: false
    • showProtocolLog
      • Prints all DAP communication log in "rdbg" output. This is for development of this extension.
      • default: false

Note that if you have a trouble by launching rdbg, please try to specify rdbgPath. Without this configuration, this extension simply calls rdbg in PATH.

Attach to the running Ruby process

You can attach to a Ruby process which run with an opening debugger port.

The following commands starts the foo.rb with opening debug port. There are more methods to open the port. See more for ruby/debug: Debugging functionality for Ruby.

# With rdbg command
$ rdbg --open foo.rb              # open debug port. -O is short for --open
$ rdbg -n -O foo.rb               # do not stop at the beginning of application
$ rdbg -O -c -- bundle exec rspec # run rspec with remote

# With debug/open lib
$ ruby -r debug/open foo.rb
$ ruby -r debug/open_nonstop foo.rb # do not stop at the beginning of application

# If your application requires debug/open (or debug/open_nonstop) explicitly, of course -r is not needed.
$ ruby foo.rb

# With debug lib with RUBY_DEBUG_OPEN
$ RUBY_DEBUG_OPEN=true ruby -r debug foo.rb

# If your application requires debug explicitly, of course -r is not needed.
$ RUBY_DEBUG_OPEN=true ruby foo.rb

# If your Gemfile has a line `gem 'debug'` with Rails, you only need to launch it with the `RUBY_DEBUG_OPEN` envval.
$ RUBY_DEBUG_OPEN=true raise server

After that, you can connect to the debug port. This extension searches opening debugger port and attach to that port by running Attach with rdbg (select it on the top of "RUN AND DEBUG" pane and push the green "Start Debugging" button).

You can specify the following "attach" configurations.

  • rdbgPath
    • Same as launch request.
  • debugPort
    • Same as launch request.
  • localfs
    • On TCP/IP, if target host is local machine, set true and you can open the file directly
    • default: false
  • localfsMap
    • Specify pairs of remote root path and local root path like /remote_dir:/local_dir if sharing the same source repository with local and remote computers.
    • You can specify multiple pairs like /rem1:/loc1,/rem2:/loc2 by concatenating with ,.
    • default: undefined

Without debugPort configuration, the

With debugPort, you can attach to TCP/IP debug port.

  • Start your debuggee command with a TCP/IP debug port with debug.gem configurations.
    • Using rdbg command like: rdbg --open --port 12345 foo.rb
    • Using debug/open lib: RUBY_DEBUG_PORT=12345 ruby -r debug/open foo.rb
    • Using debug lib with RUBY_DEBUG_OPEN envval: RUBY_DEBUG_OPEN=true RUBY_DEBUG_PORT=12345 ruby -r debug foo.rb
  • On VSCode (debugger-side):
    • Add debugPort: '12345' attach configuration.
    • Choose Attach with rdbg and start attach debugging

localfsMap is helpful if you run the debuggee and share the same file system with another name in debuggee.

For example, running a docker container with -v option (and --network=host to communicate with the host and a docker container) option like that:

$ docker run --network=host -it -v `pwd`:/app/ --rm ruby bash
/:# cd app
/app:# rdbg -O --port=12345 target.rb

In this case, the current directory of host (${workspaceFolder}) is shared with the name /app in a container and VSCode on the host can connect to the debuggee process in a container by TCP/IP port 12345. The launch.json configuration should be:

        {
            "type": "rdbg",
            "name": "Attach with rdbg (tcp 12345)", // Specify your favorite name
            "request": "attach",
            "debugPort": "localhost:12345",
            "localfsMap": "/app:${workspaceFolder}"
        }

Selecting a version manager

In order to launch the debugger using the correct Ruby version, rdbg allows configuring your preferred version manager, which is used to activate the Ruby environment with extension settings (or settings.json).

// Default value is "none" for not using a version manager to activate the environment
// Available managers are shadowenv, chruby, asdf, rbenv and rvm

{
  // User settings
  "rdbg.rubyVersionManager": "none"
}

If you are using rbenv configured with a login shell (on bash or zsh), you do not need to specify this configuration because vscode-rdbg will launch ruby command with login shell setting like bash -lic ruby .... With this configuration, vscode-rdbg will launch simply ruby command. This configuration will be useful if you are using other environment such as chruby and so on.

Acknowledgement

More Repositories

1

ruby

The Ruby Programming Language
Ruby
20,732
star
2

rake

A make-like build utility for Ruby.
Ruby
2,293
star
3

rbs

Type Signature for Ruby
Ruby
1,876
star
4

did_you_mean

The gem that has been saving people from typos since 2014
Ruby
1,870
star
5

debug

Debugging functionality for Ruby
Ruby
1,058
star
6

www.ruby-lang.org

Source of the https://www.ruby-lang.org website.
Ruby
856
star
7

rdoc

RDoc produces HTML and online documentation for Ruby projects.
Ruby
798
star
8

prism

Prism Ruby parser
C
755
star
9

setup-ruby

An action to download a prebuilt Ruby and add it to the PATH in 5 seconds
JavaScript
753
star
10

typeprof

An experimental type-level Ruby interpreter for testing and understanding Ruby code
Ruby
706
star
11

ruby.wasm

ruby.wasm is a collection of WebAssembly ports of the CRuby.
Ruby
614
star
12

spec

The Ruby Spec Suite aka ruby/spec
Ruby
556
star
13

psych

A libyaml wrapper for Ruby
Ruby
543
star
14

racc

Racc is an LALR(1) parser generator. It is written in Ruby itself, and generates ruby programs.
Yacc
530
star
15

irb

interactive Ruby
Ruby
351
star
16

syntax_suggest

Searching for unexpected `end` syntax errors takes a lot of time. Let this gem do it for you!
Ruby
344
star
17

curses

Ruby binding for curses, ncurses, and PDCurses. Formerly part of the ruby standard library.
C
285
star
18

webrick

HTTP server toolkit
Ruby
246
star
19

gem_rbs_collection

A collection of RBS for gems.
Ruby
235
star
20

reline

The compatible library with the API of Ruby's stdlib 'readline'
Ruby
234
star
21

openssl

Provides SSL, TLS and general purpose cryptography.
C
233
star
22

TryRuby

This 4th iteration of TryRuby is a website where you can learn the Ruby language.
Ruby
219
star
23

power_assert

Power Assert for Ruby
Ruby
186
star
24

rss

RSS reading and writing
Ruby
163
star
25

csv

CSV Reading and Writing
Ruby
159
star
26

lrama

Pure Ruby LALR parser generator
Ruby
158
star
27

drb

Distributed object system for Ruby
Ruby
154
star
28

fiddle

A libffi wrapper for Ruby.
Ruby
147
star
29

error_highlight

The gem enhances Exception#message by adding a short explanation where the exception is raised
Ruby
145
star
30

benchmark

The Benchmark module provides methods for benchmarking Ruby code, giving detailed reports on the time taken for each task.
Ruby
136
star
31

timeout

Timeout provides a way to auto-terminate a potentially long-running operation if it hasn't finished in a fixed amount of time.
Ruby
128
star
32

tk

Tk interface module using tcltklib
Ruby
115
star
33

rexml

REXML is an XML toolkit for Ruby
Ruby
110
star
34

bigdecimal

Arbitrary-precision decimal floating-point number library for Ruby
C
108
star
35

ostruct

OpenStruct implementation
Ruby
106
star
36

erb

An easy to use but powerful templating system for Ruby
Ruby
103
star
37

logger

simple logging utility
Ruby
97
star
38

net-http

Net::HTTP provides a rich library which can be used to build HTTP user-agents.
Ruby
84
star
39

open3

Open3 gives you access to stdin, stdout, and stderr when running other programs.
Ruby
79
star
40

dev-meeting-log

78
star
41

uri

URI is a module providing classes to handle Uniform Resource Identifiers
Ruby
69
star
42

ruby-docker-images

Ruby Docker Images
Ruby
69
star
43

pstore

PStore implements a file based persistence mechanism based on a Hash.
Ruby
67
star
44

date

A subclass of Object includes Comparable module for handling dates.
C
66
star
45

strscan

Provides lexical scanning operations on a String.
C
66
star
46

ipaddr

A class to manipulate an IP address
Ruby
62
star
47

ruby2_keywords

Shim library for Module#ruby2_keywords
Ruby
61
star
48

fileutils

Several file utility methods for copying, moving, removing, etc.
Ruby
60
star
49

mspec

RSpec-like test runner for the Ruby Spec Suite
Ruby
57
star
50

shell

Shell implements an idiomatic Ruby interface for common UNIX shell commands
Ruby
57
star
51

matrix

An implementation of Matrix and Vector classes
Ruby
56
star
52

net-telnet

Provides telnet client functionality.
Ruby
56
star
53

iconv

iconv wrapper
C
54
star
54

tracer

Outputs a source level execution trace of a Ruby program.
Ruby
52
star
55

io-console

add console capabilities to IO instance
Ruby
51
star
56

docs.ruby-lang.org

Source of the docs.ruby-lang.org site
Ruby
48
star
57

digest

Provides a framework for message digest libraries.
C
48
star
58

optparse

OptionParser is a class for command-line option analysis.
Ruby
47
star
59

zlib

Ruby interface for the zlib compression/decompression library
C
43
star
60

securerandom

Interface for secure random number generator
Ruby
42
star
61

open-uri

OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
Ruby
41
star
62

net-imap

Ruby client api for Internet Message Access Protocol
Ruby
41
star
63

forwardable

Provides delegation of specified methods to a designated object
Ruby
40
star
64

chkbuild

Continuous Integration tool, mainly for Ruby
Ruby
40
star
65

net-smtp

This library provides functionality to send internet mail via SMTP, the Simple Mail Transfer Protocol.
Ruby
36
star
66

xmlrpc

The Ruby standard library package 'xmlrpc'
Ruby
35
star
67

resolv

A thread-aware DNS resolver library written in Ruby
Ruby
32
star
68

prime

Prime numbers and factorization library.
Ruby
32
star
69

cgi

CGI is a large class, providing several categories of methods, many of which are mixed in from other modules.
Ruby
32
star
70

stringio

Pseudo `IO` class from/to `String`.
Java
31
star
71

rubyci

The Ruby CI for chkbuild
Ruby
31
star
72

gserver

GServer implements a generic server
Ruby
31
star
73

observer

The Observer pattern provides a simple mechanism for one object to inform a set of interested third-party objects when its state changes.
Ruby
29
star
74

snap.ruby

Ruby snap
HTML
29
star
75

ruby-builder

A repository building Ruby/JRuby/TruffleRuby releases to be used in GitHub Actions
Ruby
28
star
76

tempfile

A utility class for managing temporary files.
Ruby
26
star
77

etc

Provides access to information typically stored in UNIX /etc directory.
C
26
star
78

profile

Ruby
26
star
79

net-ftp

This class implements the File Transfer Protocol.
Ruby
24
star
80

singleton

The Singleton module implements the Singleton pattern.
Ruby
24
star
81

yaml

This module provides a Ruby interface for data serialization in YAML format.
Ruby
24
star
82

net-protocol

The abstruct interface for net-* client.
Ruby
24
star
83

actions

Ruby
22
star
84

pathname

Pathname represents the name of a file or directory on the filesystem, but not the file itself.
Ruby
22
star
85

sdbm

Provides a simple file-based key-value store with String keys and values.
C
22
star
86

un

Utilities to replace common UNIX commands
Ruby
21
star
87

set

This library provides the Set class, which deals with a collection of unordered values with no duplicates.
Ruby
21
star
88

syck

Syck from stdlib turned in to a gem
C
20
star
89

ruby-dev-builder

CRuby Dev Builds for GitHub Actions
Ruby
19
star
90

pp

Provides a PrettyPrinter for Ruby objects
Ruby
19
star
91

English

Ruby
19
star
92

play-ruby

Ruby Playground Website
TypeScript
19
star
93

base64

Support for encoding and decoding binary data using a Base64 representation
Ruby
18
star
94

git.ruby-lang.org

Manifest for the Ruby git server
Ruby
17
star
95

net-pop

This library provides functionality for retrieving email via POP3, the Post Office Protocol version 3. For details of POP3
Ruby
17
star
96

repl_type_completor

Ruby
17
star
97

delegate

This library provides three different ways to delegate method calls to an object.
Ruby
17
star
98

rbs_json_schema

Generate RBS files from JSON Schema
Ruby
16
star
99

redmine_rd_formatter

A redmine plugin for supporting RD as a wiki format
Ruby
15
star
100

b.r-l.o

[Fork] Redmine for b.r-l.o
Ruby
14
star