byebug 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/GUIDE.md +231 -0
  4. data/README.md +195 -7
  5. data/bin/byebug +1 -5
  6. data/byebug.gemspec +34 -35
  7. data/lib/byebug.rb +2 -5
  8. data/lib/byebug/command.rb +13 -13
  9. data/lib/byebug/commands/breakpoints.rb +1 -1
  10. data/lib/byebug/commands/control.rb +1 -1
  11. data/lib/byebug/commands/frame.rb +1 -1
  12. data/lib/byebug/commands/info.rb +1 -1
  13. data/lib/byebug/commands/list.rb +5 -5
  14. data/lib/byebug/commands/reload.rb +7 -10
  15. data/lib/byebug/commands/{irb.rb → repl.rb} +49 -13
  16. data/lib/byebug/commands/set.rb +10 -6
  17. data/lib/byebug/commands/show.rb +4 -7
  18. data/lib/byebug/commands/trace.rb +2 -2
  19. data/lib/byebug/context.rb +3 -5
  20. data/lib/byebug/helper.rb +2 -2
  21. data/lib/byebug/interface.rb +3 -0
  22. data/lib/byebug/processor.rb +2 -2
  23. data/lib/byebug/version.rb +1 -1
  24. data/old_doc/byebug.1 +1 -2
  25. data/old_doc/byebug.texi +125 -126
  26. data/old_doc/hanoi.rb +2 -3
  27. data/old_doc/triangle.rb +6 -7
  28. data/test/breakpoints_test.rb +43 -33
  29. data/test/display_test.rb +1 -1
  30. data/test/edit_test.rb +20 -15
  31. data/test/eval_test.rb +32 -26
  32. data/test/examples/list.rb +12 -1
  33. data/test/frame_test.rb +56 -43
  34. data/test/help_test.rb +11 -8
  35. data/test/info_test.rb +18 -13
  36. data/test/list_test.rb +74 -80
  37. data/test/method_test.rb +1 -3
  38. data/test/reload_test.rb +3 -3
  39. data/test/repl_test.rb +112 -0
  40. data/test/restart_test.rb +72 -70
  41. data/test/set_test.rb +43 -27
  42. data/test/show_test.rb +97 -102
  43. data/test/source_test.rb +6 -10
  44. data/test/stepping_test.rb +45 -49
  45. data/test/support/test_dsl.rb +47 -55
  46. data/test/test_helper.rb +2 -2
  47. data/test/trace_test.rb +4 -4
  48. data/test/variables_test.rb +10 -8
  49. metadata +9 -10
  50. data/old_doc/Makefile +0 -20
  51. data/test/examples/edit2.rb +0 -3
  52. data/test/irb_test.rb +0 -85
data/bin/byebug CHANGED
@@ -199,8 +199,7 @@ end
199
199
  opts = process_options(options)
200
200
  begin
201
201
  Byebug::ARGV = ARGV.clone if not defined? Byebug::ARGV
202
- byebug_path = File.expand_path($0)
203
- Byebug::BYEBUG_SCRIPT = byebug_path
202
+ Byebug::BYEBUG_SCRIPT = File.expand_path(__FILE__)
204
203
  Byebug::INITIAL_DIR = Dir.pwd
205
204
  opts.parse! ARGV
206
205
  rescue StandardError => e
@@ -223,9 +222,6 @@ prog_script = ARGV.shift
223
222
  prog_script = whence_file(prog_script) unless File.exist?(prog_script)
224
223
  Byebug::PROG_SCRIPT = File.expand_path prog_script
225
224
 
226
- # install interruption handler
227
- trap('INT') { Byebug.interrupt_last }
228
-
229
225
  # Set up trace hook for byebug
230
226
  Byebug.start
231
227
 
@@ -1,35 +1,34 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'rubygems'
3
- require File.dirname(__FILE__) + "/lib/byebug/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = %q{byebug}
7
- s.version = Byebug::VERSION
8
-
9
- s.authors = ["David Rodríguez", "Kent Sibilev", "Mark Moseley"]
10
- s.email = "deivid.rodriguez@mail.com"
11
- s.homepage = "http://github.com/deivid-rodriguez/byebug"
12
- s.summary = %q{Ruby 2.0 fast debugger - base + cli}
13
- s.description = %q{Byebug is a Ruby 2.0 debugger. It's implemented using the
14
- Ruby 2.0 TracePoint C API. The C extension was forked from debase whereas
15
- the rest of the gem was forked from debugger. The core component provides
16
- support that front-ends can build on. It provides breakpoint handling,
17
- bindings for stack frames among other things.}
18
-
19
- s.required_ruby_version = '>= 2.0.0'
20
- s.required_rubygems_version = ">= 2.0.3"
21
-
22
- s.extra_rdoc_files = [ "README.md" ]
23
- s.files = `git ls-files`.split("\n")
24
- s.extensions << "ext/byebug/extconf.rb"
25
- s.executables = ["byebug"]
26
-
27
- s.add_dependency "columnize", "~> 0.3.6"
28
- s.add_dependency "debugger-linecache", '~> 1.2.0'
29
- s.add_development_dependency 'rake', '~> 10.0.4'
30
- s.add_development_dependency 'rake-compiler', '~> 0.8.3'
31
- s.add_development_dependency 'mocha', '~> 0.13.3'
32
- s.add_development_dependency 'minitest', '~> 4.7.4'
33
-
34
- s.license = "BSD"
35
- end
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + "/lib/byebug/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = %q{byebug}
6
+ s.version = Byebug::VERSION
7
+
8
+ s.authors = ["David Rodríguez", "Kent Sibilev", "Mark Moseley"]
9
+ s.email = "deivid.rodriguez@mail.com"
10
+ s.homepage = "http://github.com/deivid-rodriguez/byebug"
11
+ s.summary = %q{Ruby 2.0 fast debugger - base + cli}
12
+ s.description = %q{Byebug is a Ruby 2.0 debugger. It's implemented using the
13
+ Ruby 2.0 TracePoint C API. The C extension was forked from debase whereas
14
+ the rest of the gem was forked from debugger. The core component provides
15
+ support that front-ends can build on. It provides breakpoint handling,
16
+ bindings for stack frames among other things.}
17
+
18
+ s.required_ruby_version = '>= 2.0.0'
19
+ s.required_rubygems_version = ">= 2.0.3"
20
+
21
+ s.extra_rdoc_files = [ "README.md" ]
22
+ s.files = `git ls-files`.split("\n")
23
+ s.extensions << "ext/byebug/extconf.rb"
24
+ s.executables = ["byebug"]
25
+
26
+ s.add_dependency "columnize", "~> 0.3.6"
27
+ s.add_dependency "debugger-linecache", '~> 1.2.0'
28
+ s.add_development_dependency 'rake', '~> 10.0.4'
29
+ s.add_development_dependency 'rake-compiler', '~> 0.8.3'
30
+ s.add_development_dependency 'mocha', '~> 0.14.0'
31
+ s.add_development_dependency 'minitest', '~> 5.0.1'
32
+
33
+ s.license = "BSD"
34
+ end
@@ -18,9 +18,6 @@ module Byebug
18
18
  tracing: nil # Byebug.tracing? value. true/false resets
19
19
  } unless defined?(DEFAULT_START_SETTINGS)
20
20
 
21
- # Port number used for remote debugging
22
- PORT = 8989 unless defined?(PORT)
23
-
24
21
  # Configuration file used for startup commands. Default value is .byebugrc
25
22
  INITFILE = '.byebugrc' unless defined?(INITFILE)
26
23
 
@@ -48,8 +45,8 @@ module Byebug
48
45
  # Get line +line_number+ from file named +filename+.
49
46
  # @return "\n" if there was a problem. Leaking blanks are stripped off.
50
47
  def line_at(filename, line_number)
51
- @@reload_source_on_change = nil unless defined?(@@reload_source_on_change)
52
- line = LineCache::getline(filename, line_number, @@reload_source_on_change)
48
+ @@autoreload = nil unless defined?(@@autoreload)
49
+ line = LineCache::getline filename, line_number, @@autoreload
53
50
  return "\n" unless line
54
51
  return "#{line.gsub(/^\s+/, '').chomp}"
55
52
  end
@@ -151,7 +151,7 @@ module Byebug
151
151
  register_setting_var(:callstyle, :last)
152
152
  register_setting_var(:testing, false)
153
153
  register_setting_var(:force_stepping, false)
154
- register_setting_var(:full_path, true)
154
+ register_setting_var(:frame_fullpath, true)
155
155
  register_setting_var(:listsize, 10)
156
156
  register_setting_var(:stack_trace_on_error, false)
157
157
  register_setting_var(:tracing_plus, false)
@@ -223,18 +223,18 @@ module Byebug
223
223
  # Use Byebug.settings[] and Byebug.settings[]= methods to query and set
224
224
  # byebug settings. These settings are available:
225
225
  #
226
- # :autolist - automatically calls 'list' command on breakpoint
227
- # :autoeval - evaluates input in the current binding if it's
228
- # not recognized as a byebug command
229
- # :autoirb - automatically calls 'irb' command on breakpoint
230
- # :stack_trace_on_error - shows full stack trace if eval command results
231
- # in an exception
232
- # :frame_full_path - displays full paths when showing frame stack
233
- # :frame_class_names - displays method's class name when showing frame
234
- # stack
235
- # :reload_source_on_change - makes 'list' command always display up-to-date
236
- # source code
237
- # :force_stepping - stepping command always move to the new line
226
+ # :autolist - automatically calls 'list' command on breakpoint
227
+ # :autoeval - evaluates input in the current binding if it's not
228
+ # recognized as a byebug command
229
+ # :autoirb - automatically calls 'irb' command on breakpoint
230
+ # :stack_trace_on_error - shows full stack trace if eval command results in
231
+ # an exception
232
+ # :frame_fullpath - displays full paths when showing frame stack
233
+ # :frame_class_names - displays method's class name when showing frame
234
+ # stack
235
+ # :autoreload - makes 'list' command always display up-to-date
236
+ # source code
237
+ # :force_stepping - stepping command always move to the new line
238
238
  #
239
239
  def self.settings
240
240
  Command.settings
@@ -59,7 +59,7 @@ module Byebug
59
59
 
60
60
  if line =~ /^\d+$/
61
61
  line = line.to_i
62
- if LineCache.cache(brkpt_filename, Command.settings[:reload_source_on_change])
62
+ if LineCache.cache(brkpt_filename, Command.settings[:autoreload])
63
63
  last_line = LineCache.size(brkpt_filename)
64
64
  if line > last_line
65
65
  errmsg \
@@ -29,7 +29,7 @@ module Byebug
29
29
  cmd = Byebug::PROG_SCRIPT
30
30
  end
31
31
  else
32
- cmd = Byebug::BYEBUG_SCRIPT
32
+ cmd = "#{Byebug::BYEBUG_SCRIPT} #{Byebug::PROG_SCRIPT}"
33
33
  end
34
34
 
35
35
  begin
@@ -89,7 +89,7 @@ module Byebug
89
89
  line = context.frame_line(pos)
90
90
  klass = context.frame_class(pos)
91
91
 
92
- unless Command.settings[:full_path]
92
+ unless Command.settings[:frame_fullpath]
93
93
  path_components = file.split(/[\\\/]/)
94
94
  if path_components.size > 3
95
95
  path_components[0...-3] = '...'
@@ -189,7 +189,7 @@ module Byebug
189
189
  unless LineCache::cached_script?(file)
190
190
  return print "File #{file} is not cached\n"
191
191
  end
192
- LineCache::cache(file, Command.settings[:reload_source_on_change])
192
+ LineCache::cache(file, Command.settings[:autoreload])
193
193
  end
194
194
 
195
195
  print "File #{file}"
@@ -18,9 +18,8 @@ module Byebug
18
18
  end
19
19
 
20
20
  def execute
21
- Byebug.source_reload if Command.settings[:reload_source_on_change]
22
- lines = LineCache::getlines(@state.file,
23
- Command.settings[:reload_source_on_change])
21
+ Byebug.source_reload if Command.settings[:autoreload]
22
+ lines = LineCache::getlines @state.file, Command.settings[:autoreload]
24
23
  if !lines
25
24
  errmsg "No sourcefile available for #{@state.file}\n"
26
25
  return @state.previous_line
@@ -107,12 +106,13 @@ module Byebug
107
106
  # otherwise we return the previous line @state.previous_line.
108
107
  #
109
108
  def display_list(b, e, lines, current)
109
+ width = e.to_s.size
110
110
  b.upto(e) do |n|
111
111
  if n > 0 && lines[n-1]
112
112
  if n == current
113
- print "=> %d %s\n", n, lines[n-1].chomp
113
+ print "=> %#{width}d: %s\n", n, lines[n-1].chomp
114
114
  else
115
- print " %d %s\n", n, lines[n-1].chomp
115
+ print " %#{width}d: %s\n", n, lines[n-1].chomp
116
116
  end
117
117
  end
118
118
  end
@@ -4,14 +4,14 @@ module Byebug
4
4
  class ReloadCommand < Command
5
5
  self.allow_in_control = true
6
6
 
7
- register_setting_get(:reload_source_on_change) do
8
- Byebug.class_variable_get(:@@reload_source_on_change)
7
+ register_setting_get(:autoreload) do
8
+ Byebug.class_variable_get(:@@autoreload)
9
9
  end
10
10
 
11
- register_setting_set(:reload_source_on_change) do |value|
12
- Byebug.class_variable_set(:@@reload_source_on_change, value)
11
+ register_setting_set(:autoreload) do |value|
12
+ Byebug.class_variable_set(:@@autoreload, value)
13
13
  end
14
- Command.settings[:reload_source_on_change] = true
14
+ Command.settings[:autoreload] = true
15
15
 
16
16
  def regexp
17
17
  /^\s*r(?:eload)?$/
@@ -19,15 +19,12 @@ module Byebug
19
19
 
20
20
  def execute
21
21
  Byebug.source_reload
22
- print "Source code is reloaded. Automatic reloading is #{source_reloading}.\n"
22
+ print "Source code is reloaded. Automatic reloading is " \
23
+ "#{Command.settings[:autoreload] ? 'on' : 'off'}.\n"
23
24
  end
24
25
 
25
26
  private
26
27
 
27
- def source_reloading
28
- Command.settings[:reload_source_on_change] ? 'on' : 'off'
29
- end
30
-
31
28
  class << self
32
29
  def names
33
30
  %w(reload)
@@ -1,7 +1,6 @@
1
1
  require 'irb'
2
2
 
3
3
  module IRB
4
-
5
4
  module ExtendCommand
6
5
  class Continue
7
6
  def self.execute(conf)
@@ -33,19 +32,21 @@ module IRB
33
32
  end
34
33
 
35
34
  workspace = WorkSpace.new(binding)
36
-
37
35
  irb = Irb.new(workspace)
38
36
 
39
37
  @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
40
38
  @CONF[:MAIN_CONTEXT] = irb.context
41
39
 
40
+ trap("SIGINT") do
41
+ irb.signal_handle
42
+ end
43
+
42
44
  catch(:IRB_EXIT) do
43
45
  irb.eval_input
44
46
  end
45
47
  end
46
48
  end
47
49
 
48
-
49
50
  module Byebug
50
51
 
51
52
  # Implements byebug's "irb" command.
@@ -70,13 +71,9 @@ module Byebug
70
71
  throw :debug_error
71
72
  end
72
73
 
73
- save_trap = trap("SIGINT") do
74
- throw :IRB_EXIT, :cont if $byebug_in_irb
75
- end
76
-
77
74
  add_debugging = @match.is_a?(MatchData) && '-d' == @match[1]
78
75
  $byebug_state = @state if add_debugging
79
- $byebug_in_irb = true
76
+
80
77
  cont = IRB.start_session(get_binding)
81
78
  case cont
82
79
  when :cont
@@ -95,13 +92,10 @@ module Byebug
95
92
  CommandProcessor.print_location_and_text(file, line)
96
93
  @state.previous_line = nil
97
94
  end
98
-
99
- ensure
100
- $byebug_in_irb = nil
101
95
  $byebug_state = nil if add_debugging
102
- trap("SIGINT", save_trap) if save_trap
103
96
  end
104
97
 
98
+
105
99
  class << self
106
100
  def names
107
101
  %w(irb)
@@ -119,5 +113,47 @@ module Byebug
119
113
  end
120
114
  end
121
115
  end
122
- end
123
116
 
117
+ begin
118
+ require 'pry'
119
+ has_pry = true
120
+ rescue LoadError
121
+ has_pry = false
122
+ end
123
+
124
+ # Implements byebug's "pry" command
125
+ class PryCommand < Command
126
+ def regexp
127
+ /^\s* pry
128
+ (?:\s+(-d))?
129
+ \s*$/x
130
+ end
131
+
132
+ def execute
133
+ unless @state.interface.kind_of?(LocalInterface)
134
+ print "Command is available only in local mode.\n"
135
+ throw :debug_error
136
+ end
137
+
138
+ add_debugging = @match.is_a?(MatchData) && '-d' == @match[1]
139
+ $byebug_state = @state if add_debugging
140
+
141
+ get_binding.pry
142
+
143
+ $byebug_state = nil if add_debugging
144
+ end
145
+
146
+ class << self
147
+ def names
148
+ %w(pry)
149
+ end
150
+
151
+ def description
152
+ %{
153
+ pry[ -d]\tstarts a Pry session.
154
+ }
155
+ end
156
+ end
157
+ end if has_pry
158
+
159
+ end
@@ -20,7 +20,7 @@ module Byebug
20
20
  ['autolist', 4, true, 'Execute "list" command on every breakpoint'],
21
21
  ['autoirb', 4, true, 'Invoke IRB on every stop'],
22
22
  ['autoreload', 4, true, 'Reload source code when changed'],
23
- ['basename', 1, true, 'Report file basename only showing file names'],
23
+ ['basename', 1, true, 'Set filename display style.'],
24
24
  ['callstyle', 2, false, 'Set how you want call parameters displayed'],
25
25
  ['testing', 2, false, 'Used when testing byebug'],
26
26
  ['forcestep', 2, true,
@@ -67,7 +67,11 @@ module Byebug
67
67
  # Subcommand not found...
68
68
  return print "Unknown set command \"#{try_subcmd}\"\n" unless subcmd
69
69
 
70
- set_on = get_onoff(args[0]) if subcmd.is_bool and args.size > 0
70
+ begin
71
+ set_on = get_onoff(args[0]) if subcmd.is_bool and args.size > 0
72
+ rescue RuntimeError
73
+ return
74
+ end
71
75
 
72
76
  case subcmd.name
73
77
  when /^annotate$/
@@ -103,14 +107,14 @@ module Byebug
103
107
  when /^trace$/
104
108
  Command.settings[:stack_trace_on_error] = set_on
105
109
  when /^fullpath$/
106
- Command.settings[:full_path] = set_on
110
+ Command.settings[:frame_fullpath] = set_on
107
111
  when /^autoreload$/
108
- Command.settings[:reload_source_on_change] = set_on
112
+ Command.settings[:autoreload] = set_on
109
113
  when /^autoirb$/
110
114
  Command.settings[:autoirb] = (set_on ? 1 : 0)
111
115
  when /^testing$/
112
116
  Command.settings[:testing] = set_on
113
- Command.settings[:basename] = true if set_on
117
+ Command.settings[:basename] = set_on
114
118
  when /^forcestep$/
115
119
  self.class.settings[:force_stepping] = set_on
116
120
  when /^history$/
@@ -137,7 +141,7 @@ module Byebug
137
141
  when /^linetrace\+$/
138
142
  self.class.settings[:tracing_plus] = set_on
139
143
  when /^linetrace$/
140
- Command.settings[:tracing] = set_on
144
+ Byebug.tracing = set_on
141
145
  when /^listsize$/
142
146
  listsize = get_int(args[0], "Set listsize", 1, nil, 10)
143
147
  return unless listsize
@@ -28,7 +28,7 @@ module Byebug
28
28
  on_off = Command.settings[:autoeval]
29
29
  return "autoeval is #{show_onoff(on_off)}."
30
30
  when /^autoreload$/
31
- on_off = Command.settings[:reload_source_on_change]
31
+ on_off = Command.settings[:autoreload]
32
32
  return "autoreload is #{show_onoff(on_off)}."
33
33
  when /^autoirb$/
34
34
  on_off = Command.settings[:autoirb] > 0
@@ -80,7 +80,7 @@ module Byebug
80
80
  on_off = self.class.settings[:force_stepping]
81
81
  return "force-stepping is #{show_onoff(on_off)}."
82
82
  when /^fullpath$/
83
- on_off = Command.settings[:full_path]
83
+ on_off = Command.settings[:frame_fullpath]
84
84
  return "Displaying frame's full file names is #{show_onoff(on_off)}."
85
85
  when /^history(:?\s+(filename|save|size))?$/
86
86
  args = @match[1].split
@@ -101,9 +101,8 @@ module Byebug
101
101
  end
102
102
  s = []
103
103
  if show_filename
104
- msg = (prefix ? "filename: " : "") +
105
- "The filename in which to record the command history is " +
106
- "#{interface.histfile.inspect}"
104
+ msg = "#{prefix ? 'filename:' : ''} The command history file is " \
105
+ "#{interface.histfile.inspect}"
107
106
  s << msg
108
107
  end
109
108
  if show_save
@@ -130,8 +129,6 @@ module Byebug
130
129
  when /^listsize$/
131
130
  listlines = Command.settings[:listsize]
132
131
  return "Number of source lines to list is #{listlines}."
133
- when /^port$/
134
- return "server port is #{Byebug::PORT}."
135
132
  when /^trace$/
136
133
  on_off = Command.settings[:stack_trace_on_error]
137
134
  return "Displaying stack trace is #{show_onoff(on_off)}."