Skip to content

Commit

Permalink
Ruby debugger integration (CircuitVerse#3760)
Browse files Browse the repository at this point in the history
* feat: byebug removed and debug gem added

* feat(debug): rdbg script added

* feat(debug): procfile added

* feat(debug): .gitignore file updated for vscode configurations

* fix(rdbg): version fixed

* feat(rdbg): procfile update

* feat(rdbg): rdbg script added

* fix(rdbg): set web_concurrency to zero to resolve duplicate socket creation by worker process

* feat(rdbg): gitignore updated for vscode configuration

* feat(rdbg): attach debugger configuration added

* feat(rdbg): dev script configured to accept chrome_debug option from cmd

* feat(rdbg): procfile for chrome based ruby debugging

* feat(rdbg_docker): update vscode configuration

* feat(rdbg_docker): update docker-compose file for using rdbg

* feat(rdbg_docker): docker_run script updated to use rdb remote debugging

* feat(rdbg): documentation updated

* feat(rdbg): gitignore updated

* Update launch.json

* feat(rdbg): remove version debug

* Update rdbg

---------

Co-authored-by: Tanmoy Sarkar <57363826+Tanmoy741127@users.noreply.github.com>
  • Loading branch information
tanmoysrt and tanmoysrt authored Jun 3, 2023
1 parent 199bfb3 commit b71f58b
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 15 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/.bundle
/.idea
test_results
tmp

public/assets/

Expand Down Expand Up @@ -48,7 +49,6 @@ dump.rdb

public/sitemap.xml.gz
coverage
.vscode

solr/data
solr/test/data
Expand Down Expand Up @@ -76,3 +76,8 @@ config/private.pem
yosys2digitaljs-server
*/**/node_modules
*/**/yarn-error.log


# Ignore all files of .vscode except launch.json
.vscode/*
!.vscode/launch.json
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.1.0",
"configurations": [
{
"type": "rdbg",
"name": "Attach Debugger",
"request": "attach"
},
{
"type": "rdbg",
"name": "(Docker) Attach debugger [:3001]",
"request": "attach",
"debugPort": "localhost:3001",
"showProtocolLog": true,
"localfsMap": "/circuitverse:${workspaceFolder}"
}
]
}
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ gem "strong_migrations"
gem 'rails-data-migrations'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: %i[mri mingw x64_mingw]
# Adds support for debug
gem "debug"
# Adds support for Capybara system testing and selenium driver
gem "coveralls_reborn", "~> 0.26.0", require: false
gem "erb_lint", require: false
Expand Down
13 changes: 11 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ GEM
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
capybara (3.38.0)
addressable
matrix
Expand Down Expand Up @@ -190,6 +189,9 @@ GEM
css_parser (1.7.1)
addressable
date (3.3.3)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
device_detector (1.0.7)
devise (4.8.1)
bcrypt (~> 3.0)
Expand Down Expand Up @@ -287,6 +289,9 @@ GEM
nokogiri (>= 1.6)
invisible_captcha (2.0.0)
rails (>= 5.0)
io-console (0.6.0)
irb (1.6.4)
reline (>= 0.3.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -364,6 +369,8 @@ GEM
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.2-x64-mingw32)
racc (~> 1.4)
noticed (1.6.0)
http (>= 4.0.0)
rails (>= 5.2.0)
Expand Down Expand Up @@ -489,6 +496,8 @@ GEM
redcarpet (3.5.1)
redis (4.6.0)
regexp_parser (2.7.0)
reline (0.3.4)
io-console (~> 0.5)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
Expand Down Expand Up @@ -685,13 +694,13 @@ DEPENDENCIES
bootsnap
bugsnag (~> 6.24)
bundler-audit (~> 0.9.1)
byebug
capybara (~> 3.36)
carrierwave (~> 2.2)
coffee-rails (~> 5.0)
commontator (~> 7.0.0)
country_select (~> 8.0)
coveralls_reborn (~> 0.26.0)
debug
devise
devise_saml_authenticatable
disposable_mail!
Expand Down
3 changes: 3 additions & 0 deletions Procfile.chrome.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: bundle exec rdbg -n --open=chrome --command -- bundle exec rails server -p 3000
js: yarn build --watch
worker: bundle exec sidekiq
4 changes: 2 additions & 2 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: bundle exec rails server -p 3000
web: bundle exec rdbg --open --nonstop --command -- bundle exec rails server -p 3000
js: yarn build --watch
worker: bundle exec sidekiq
worker: bundle exec sidekiq
26 changes: 26 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ Additional instructions can be found [here](https://www.howtoforge.com/tutorial/
- If you are facing difficulties installing RVM, most probably it is because of an older version of rvm shipped with Ubuntu's desktop edition and updating the same resolves the problem.
- [Run Terminal as a login shell](https://rvm.io/integration/gnome-terminal/) so ruby and rails will be available.

#### Additional instructions for Debugging
[debug](https://github.com/ruby/debug) gem has been used fro debuggin purpose.

**Debugging with VSCode**
1. Install [VSCode rdbg Ruby Debugger](VSCode rdbg Ruby Debugge) extenstion.
> Use v1.0.0 of this extenstion
2. Run the app by `./bin/dev`
3. Go to Debug Menu
4. Choose `Attach Debugger`
5. Now you can set breakpoint and debug

**Debugging with Chrome**

1. Run the app by `./bin/dev chrome_debug`
2. Chrome Devtools will be open
3. In Chrome, Move to `Filesystem` and add `CircuitVerse` folder to workspace
4. Now you can open any file and set breakpoint to debug

**Debugging with VSCode (Docker)**
1. Install [VSCode rdbg Ruby Debugger](VSCode rdbg Ruby Debugge) extenstion.
> Use v1.0.0 of this extenstion
2. Run by `docker compose up`
3. Go to Debug Menu
4. Choose `(Docker) Attach Debugger[:3001]`
5. Now you can set breakpoint and debug from VSCode

#### (Optional) yosys installation for Verilog RTL Synthesis
If you wish to do Verilog RTL Synthesis/create CircuitVerse Verilog Circuits in your local development environment, you need to:
1. Install yosys
Expand Down
8 changes: 7 additions & 1 deletion bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ then
gem install foreman
fi

foreman start -f Procfile.dev
if [[ "$1" == "chrome_debug" ]]; then
echo "Starting foreman with Procfile.chrome.dev..."
foreman start -f Procfile.chrome.dev
else
echo "Starting foreman with Procfile.dev..."
foreman start -f Procfile.dev
fi
3 changes: 2 additions & 1 deletion bin/docker_run
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ bundle exec rails db:seed
rm -f /circuitverse/tmp/pids/server.pid

echo "Starting on 127.0.0.1:3000"
bundle exec rails s -p 3000 -b '0.0.0.0'
echo "Remote debugging on 127.0.0.1:3001"
bundle exec rdbg --nonstop --open --host 0.0.0.0 --port 3001 -c -- bundle exec rails s -p 3000 -b '0.0.0.0'
20 changes: 20 additions & 0 deletions bin/rdbg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("debug", "rdbg")
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
workers ENV.fetch("WEB_CONCURRENCY") { 0 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
Expand Down
11 changes: 6 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ services:
volumes:
- /circuitverse/.bundle
- /circuitverse/node_modules
- .:/circuitverse
- ./config/database.docker.yml:/circuitverse/config/database.yml
- .:/circuitverse:rw
- ./config/database.docker.yml:/circuitverse/config/database.yml:rw
environment:
REDIS_URL: "redis://redis:6379/0"
web:
Expand All @@ -25,10 +25,11 @@ services:
volumes:
- /circuitverse/.bundle
- /circuitverse/node_modules
- .:/circuitverse
- ./config/database.docker.yml:/circuitverse/config/database.yml
- .:/circuitverse:rw
- ./config/database.docker.yml:/circuitverse/config/database.yml:rw
ports:
- "3000:3000"
- "3001:3001"
depends_on:
- db
- redis
Expand All @@ -46,7 +47,7 @@ services:
- RAILS_ENV=development
command: yarn build --watch
volumes:
- .:/circuitverse
- .:/circuitverse:rw
- /circuitverse/.bundle
- /circuitverse/node_modules
ports:
Expand Down

0 comments on commit b71f58b

Please sign in to comment.