Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,33 +456,33 @@ config set no_color true

* UI
* `RUBY_DEBUG_LOG_LEVEL` (`log_level`): Log level same as Logger (default: WARN)
* `RUBY_DEBUG_SHOW_SRC_LINES` (`show_src_lines`): Show n lines source code on breakpoint (default: 10 lines)
* `RUBY_DEBUG_SHOW_FRAMES` (`show_frames`): Show n frames on breakpoint (default: 2 frames)
* `RUBY_DEBUG_USE_SHORT_PATH` (`use_short_path`): Show shorten PATH (like $(Gem)/foo.rb)
* `RUBY_DEBUG_SHOW_SRC_LINES` (`show_src_lines`): Show n lines source code on breakpoint (default: 10)
* `RUBY_DEBUG_SHOW_FRAMES` (`show_frames`): Show n frames on breakpoint (default: 2)
* `RUBY_DEBUG_USE_SHORT_PATH` (`use_short_path`): Show shorten PATH (like $(Gem)/foo.rb) (default: false)
* `RUBY_DEBUG_NO_COLOR` (`no_color`): Do not use colorize (default: false)
* `RUBY_DEBUG_NO_SIGINT_HOOK` (`no_sigint_hook`): Do not suspend on SIGINT (default: false)
* `RUBY_DEBUG_NO_RELINE` (`no_reline`): Do not use Reline library (default: false)

* CONTROL
* `RUBY_DEBUG_SKIP_PATH` (`skip_path`): Skip showing/entering frames for given paths (default: [])
* `RUBY_DEBUG_SKIP_PATH` (`skip_path`): Skip showing/entering frames for given paths
* `RUBY_DEBUG_SKIP_NOSRC` (`skip_nosrc`): Skip on no source code lines (default: false)
* `RUBY_DEBUG_KEEP_ALLOC_SITE` (`keep_alloc_site`): Keep allocation site and p, pp shows it (default: false)
* `RUBY_DEBUG_POSTMORTEM` (`postmortem`): Enable postmortem debug (default: false)
* `RUBY_DEBUG_FORK_MODE` (`fork_mode`): Control which process activates a debugger after fork (both/parent/child) (default: both)
* `RUBY_DEBUG_SIGDUMP_SIG` (`sigdump_sig`): Sigdump signal (default: disabled)
* `RUBY_DEBUG_SIGDUMP_SIG` (`sigdump_sig`): Sigdump signal (default: false)

* BOOT
* `RUBY_DEBUG_NONSTOP` (`nonstop`): Nonstop mode
* `RUBY_DEBUG_STOP_AT_LOAD` (`stop_at_load`): Stop at just loading location
* `RUBY_DEBUG_NONSTOP` (`nonstop`): Nonstop mode (default: false)
* `RUBY_DEBUG_STOP_AT_LOAD` (`stop_at_load`): Stop at just loading location (default: false)
* `RUBY_DEBUG_INIT_SCRIPT` (`init_script`): debug command script path loaded at first stop
* `RUBY_DEBUG_COMMANDS` (`commands`): debug commands invoked at first stop. commands should be separated by ';;'
* `RUBY_DEBUG_NO_RC` (`no_rc`): ignore loading ~/.rdbgrc(.rb)
* `RUBY_DEBUG_NO_RC` (`no_rc`): ignore loading ~/.rdbgrc(.rb) (default: false)
* `RUBY_DEBUG_HISTORY_FILE` (`history_file`): history file (default: ~/.rdbg_history)
* `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10,000)
* `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10000)

* REMOTE
* `RUBY_DEBUG_PORT` (`port`): TCP/IP remote debugging: port
* `RUBY_DEBUG_HOST` (`host`): TCP/IP remote debugging: host (localhost if not given)
* `RUBY_DEBUG_HOST` (`host`): TCP/IP remote debugging: host (default: 127.0.0.1)
* `RUBY_DEBUG_SOCK_PATH` (`sock_path`): UNIX Domain Socket remote debugging: socket path
* `RUBY_DEBUG_SOCK_DIR` (`sock_dir`): UNIX Domain Socket remote debugging: socket directory
* `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation
Expand Down
58 changes: 35 additions & 23 deletions lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@ module DEBUGGER__

CONFIG_SET = {
# UI setting
log_level: ['RUBY_DEBUG_LOG_LEVEL', "UI: Log level same as Logger (default: WARN)", :loglevel],
show_src_lines: ['RUBY_DEBUG_SHOW_SRC_LINES', "UI: Show n lines source code on breakpoint (default: 10 lines)", :int],
show_frames: ['RUBY_DEBUG_SHOW_FRAMES', "UI: Show n frames on breakpoint (default: 2 frames)", :int],
use_short_path: ['RUBY_DEBUG_USE_SHORT_PATH', "UI: Show shorten PATH (like $(Gem)/foo.rb)", :bool],
no_color: ['RUBY_DEBUG_NO_COLOR', "UI: Do not use colorize (default: false)", :bool],
no_sigint_hook: ['RUBY_DEBUG_NO_SIGINT_HOOK', "UI: Do not suspend on SIGINT (default: false)", :bool],
no_reline: ['RUBY_DEBUG_NO_RELINE', "UI: Do not use Reline library (default: false)", :bool],
log_level: ['RUBY_DEBUG_LOG_LEVEL', "UI: Log level same as Logger", :loglevel, "WARN"],
show_src_lines: ['RUBY_DEBUG_SHOW_SRC_LINES', "UI: Show n lines source code on breakpoint", :int, "10"],
show_frames: ['RUBY_DEBUG_SHOW_FRAMES', "UI: Show n frames on breakpoint", :int, "2"],
use_short_path: ['RUBY_DEBUG_USE_SHORT_PATH', "UI: Show shorten PATH (like $(Gem)/foo.rb)", :bool, "false"],
no_color: ['RUBY_DEBUG_NO_COLOR', "UI: Do not use colorize", :bool, "false"],
no_sigint_hook: ['RUBY_DEBUG_NO_SIGINT_HOOK', "UI: Do not suspend on SIGINT", :bool, "false"],
no_reline: ['RUBY_DEBUG_NO_RELINE', "UI: Do not use Reline library", :bool, "false"],

# control setting
skip_path: ['RUBY_DEBUG_SKIP_PATH', "CONTROL: Skip showing/entering frames for given paths (default: [])", :path],
skip_nosrc: ['RUBY_DEBUG_SKIP_NOSRC', "CONTROL: Skip on no source code lines (default: false)", :bool],
keep_alloc_site:['RUBY_DEBUG_KEEP_ALLOC_SITE',"CONTROL: Keep allocation site and p, pp shows it (default: false)", :bool],
postmortem: ['RUBY_DEBUG_POSTMORTEM', "CONTROL: Enable postmortem debug (default: false)", :bool],
fork_mode: ['RUBY_DEBUG_FORK_MODE', "CONTROL: Control which process activates a debugger after fork (both/parent/child) (default: both)", :forkmode],
sigdump_sig: ['RUBY_DEBUG_SIGDUMP_SIG', "CONTROL: Sigdump signal (default: disabled)"],
skip_path: ['RUBY_DEBUG_SKIP_PATH', "CONTROL: Skip showing/entering frames for given paths", :path],
skip_nosrc: ['RUBY_DEBUG_SKIP_NOSRC', "CONTROL: Skip on no source code lines", :bool, "false"],
keep_alloc_site:['RUBY_DEBUG_KEEP_ALLOC_SITE',"CONTROL: Keep allocation site and p, pp shows it", :bool, "false"],
postmortem: ['RUBY_DEBUG_POSTMORTEM', "CONTROL: Enable postmortem debug", :bool, "false"],
fork_mode: ['RUBY_DEBUG_FORK_MODE', "CONTROL: Control which process activates a debugger after fork (both/parent/child)", :forkmode, "both"],
sigdump_sig: ['RUBY_DEBUG_SIGDUMP_SIG', "CONTROL: Sigdump signal", :bool, "false"],

# boot setting
nonstop: ['RUBY_DEBUG_NONSTOP', "BOOT: Nonstop mode", :bool],
stop_at_load: ['RUBY_DEBUG_STOP_AT_LOAD',"BOOT: Stop at just loading location", :bool],
nonstop: ['RUBY_DEBUG_NONSTOP', "BOOT: Nonstop mode", :bool, "false"],
stop_at_load: ['RUBY_DEBUG_STOP_AT_LOAD',"BOOT: Stop at just loading location", :bool, "false"],
init_script: ['RUBY_DEBUG_INIT_SCRIPT', "BOOT: debug command script path loaded at first stop"],
commands: ['RUBY_DEBUG_COMMANDS', "BOOT: debug commands invoked at first stop. commands should be separated by ';;'"],
no_rc: ['RUBY_DEBUG_NO_RC', "BOOT: ignore loading ~/.rdbgrc(.rb)", :bool],
history_file: ['RUBY_DEBUG_HISTORY_FILE',"BOOT: history file (default: ~/.rdbg_history)"],
save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines (default: 10,000)"],
no_rc: ['RUBY_DEBUG_NO_RC', "BOOT: ignore loading ~/.rdbgrc(.rb)", :bool, "false"],
history_file: ['RUBY_DEBUG_HISTORY_FILE',"BOOT: history file", :string, "~/.rdbg_history"],
save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines", :int, "10000"],

# remote setting
port: ['RUBY_DEBUG_PORT', "REMOTE: TCP/IP remote debugging: port"],
host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host (localhost if not given)"],
host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host", :string, "127.0.0.1"],
sock_path: ['RUBY_DEBUG_SOCK_PATH', "REMOTE: UNIX Domain Socket remote debugging: socket path"],
sock_dir: ['RUBY_DEBUG_SOCK_DIR', "REMOTE: UNIX Domain Socket remote debugging: socket directory"],
cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"],
open_frontend: ['RUBY_DEBUG_OPEN_FRONTEND',"REMOTE: frontend used by open command (vscode, chrome, default: rdbg)."],
chrome_path: ['RUBY_DEBUG_CHROME_PATH', "REMOTE: Platform dependent path of Chrome (For more information, See [here](https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64))"],

# obsolete
parent_on_fork: ['RUBY_DEBUG_PARENT_ON_FORK', "OBSOLETE: Keep debugging parent process on fork (default: false)", :bool],
parent_on_fork: ['RUBY_DEBUG_PARENT_ON_FORK', "OBSOLETE: Keep debugging parent process on fork", :bool, "false"],
}.freeze

CONFIG_MAP = CONFIG_SET.map{|k, (ev, _)| [k, ev]}.to_h.freeze
Expand All @@ -66,7 +66,17 @@ def initialize argv
raise 'Can not make multiple configurations in one process'
end

update self.class.parse_argv(argv)
config = self.class.parse_argv(argv)

# apply defaults
CONFIG_SET.each do |k, config_detail|
unless config.key?(k)
default_value = config_detail[3]
config[k] = parse_config_value(k, default_value)
end
end

update config
end

def inspect
Expand Down Expand Up @@ -125,11 +135,13 @@ def update conf
self.class.instance_variable_set(:@config, conf.freeze)

# Post process
if_updated old_conf, conf, :keep_alloc_site do |_, new|
if_updated old_conf, conf, :keep_alloc_site do |old, new|
if new
require 'objspace'
ObjectSpace.trace_object_allocations_start
else
end

if old && !new
ObjectSpace.trace_object_allocations_stop
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/debug/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ def history
end

def history_file
CONFIG[:history_file] || File.expand_path("~/.rdbg_history")
history_file = CONFIG[:history_file]

if !history_file.empty?
File.expand_path(history_file)
else
history_file
end
end

FH = "# Today's OMIKUJI: "
Expand Down Expand Up @@ -202,7 +208,7 @@ def deactivate
if history && @init_history_lines
added_records = history.to_a[@init_history_lines .. -1]
path = history_file
max = CONFIG[:save_history] || 10_000
max = CONFIG[:save_history]

if !added_records.empty? && !path.empty?
orig_records = read_history_file
Expand Down
4 changes: 2 additions & 2 deletions lib/debug/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def vscode_setup debug_port
class UI_TcpServer < UI_ServerBase
def initialize host: nil, port: nil
@local_addr = nil
@host = host || CONFIG[:host] || '127.0.0.1'
@host = host || CONFIG[:host]
@port_save_file = nil
@port = begin
port_str = (port && port.to_s) || CONFIG[:port] || raise("Specify listening port by RUBY_DEBUG_PORT environment variable.")
Expand All @@ -381,7 +381,7 @@ def chrome_setup
With Chrome browser, type the following URL in the address-bar:

devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{@local_addr.inspect_sockaddr}/#{SecureRandom.uuid}

EOS
end
end
Expand Down
27 changes: 16 additions & 11 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,18 @@ def step_command type, arg

def config_show key
key = key.to_sym
if CONFIG_SET[key]
config_detail = CONFIG_SET[key]

if config_detail
v = CONFIG[key]
kv = "#{key} = #{v.nil? ? '(default)' : v.inspect}"
desc = CONFIG_SET[key][1]
line = "%-30s \# %s" % [kv, desc]
kv = "#{key} = #{v.inspect}"
desc = config_detail[1]

if config_default = config_detail[3]
desc += " (default: #{config_default})"
end

line = "%-34s \# %s" % [kv, desc]
if line.size > SESSION.width
@ui.puts "\# #{desc}\n#{kv}"
else
Expand Down Expand Up @@ -2115,7 +2122,7 @@ def self.info msg

def self.check_loglevel level
lv = LOG_LEVELS[level]
config_lv = LOG_LEVELS[CONFIG[:log_level] || :WARN]
config_lv = LOG_LEVELS[CONFIG[:log_level]]
lv <= config_lv
end

Expand Down Expand Up @@ -2211,12 +2218,10 @@ def fork(&given_block)
end

private def __fork_setup_for_debugger
unless fork_mode = CONFIG[:fork_mode]
if CONFIG[:parent_on_fork]
fork_mode = :parent
else
fork_mode = :both
end
fork_mode = CONFIG[:fork_mode]

if fork_mode == :both && CONFIG[:parent_on_fork]
fork_mode = :parent
end

parent_pid = Process.pid
Expand Down
4 changes: 2 additions & 2 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def suspend event, tp = nil, bp: nil, sig: nil, postmortem_frames: nil, replay_f

if event != :pause
show_src
show_frames CONFIG[:show_frames] || 2
show_frames CONFIG[:show_frames]

set_mode :waiting

Expand Down Expand Up @@ -476,7 +476,7 @@ def get_src(frame,
exit!
end

def show_src(frame_index: @current_frame_index, update_line: false, max_lines: CONFIG[:show_src_lines] || 10, **options)
def show_src(frame_index: @current_frame_index, update_line: false, max_lines: CONFIG[:show_src_lines], **options)
if frame = get_frame(frame_index)
start_line, end_line, lines = *get_src(frame, max_lines: max_lines, **options)

Expand Down
4 changes: 2 additions & 2 deletions misc/README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ config set log_level INFO
config set no_color true
```

<% cat = nil; DEBUGGER__::CONFIG_SET.each do |key, (env, desc)| %>
<% cat = nil; DEBUGGER__::CONFIG_SET.each do |key, (env, desc, _, default)| %>
<% /\A(\w+): (.+)/ =~ desc; if cat != $1; cat = 1 %>
* <%= $1 %>
<% cat = $1; end %> * `<%= env %>` (`<%= key %>`): <%= $2 %><% end %>
<% cat = $1; end %> * `<%= env %>` (`<%= key %>`): <%= default ? "#{$2} (default: #{default})" : $2 %><% end %>

### Initial scripts

Expand Down
7 changes: 4 additions & 3 deletions test/console/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ def test_config_show
type 'config'
# show all configurations with descriptions
assert_line_text([
/show_src_lines = \(default\)/,
/show_frames = \(default\)/
/show_src_lines = \d+/,
/show_frames = \d+/
])
# only show this configuration
type 'config show_frames'
assert_no_line_text(/show_src_lines/)
assert_line_text([
/show_frames = \(default\)/
/show_frames = \d+/
])
type 'q!'
end
Expand Down