byebug 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,12 +71,12 @@ module Byebug
71
71
  end
72
72
 
73
73
  save_trap = trap("SIGINT") do
74
- throw :IRB_EXIT, :cont if $rdebug_in_irb
74
+ throw :IRB_EXIT, :cont if $byebug_in_irb
75
75
  end
76
76
 
77
77
  add_debugging = @match.is_a?(MatchData) && '-d' == @match[1]
78
78
  $byebug_state = @state if add_debugging
79
- $rdebug_in_irb = true
79
+ $byebug_in_irb = true
80
80
  cont = IRB.start_session(get_binding)
81
81
  case cont
82
82
  when :cont
@@ -97,7 +97,7 @@ module Byebug
97
97
  end
98
98
 
99
99
  ensure
100
- $rdebug_in_irb = nil
100
+ $byebug_in_irb = nil
101
101
  $byebug_state = nil if add_debugging
102
102
  trap("SIGINT", save_trap) if save_trap
103
103
  end
@@ -1,9 +1,10 @@
1
1
  module Byebug
2
+
2
3
  # Implements byebug "list" command.
3
4
  class ListCommand < Command
4
5
 
5
6
  register_setting_get(:autolist) do
6
- ListCommand.always_run
7
+ ListCommand.always_run
7
8
  end
8
9
  register_setting_set(:autolist) do |value|
9
10
  ListCommand.always_run = value
@@ -16,17 +17,17 @@ module Byebug
16
17
  def execute
17
18
  listsize = Command.settings[:listsize]
18
19
  if !@match || !(@match[1] || @match[2])
19
- b = @state.previous_line ?
20
+ b = @state.previous_line ?
20
21
  @state.previous_line + listsize : @state.line - (listsize/2)
21
22
  e = b + listsize - 1
22
23
  elsif @match[1] == '-'
23
24
  b = if @state.previous_line
24
25
  if @state.previous_line > 0
25
- @state.previous_line - listsize
26
+ @state.previous_line - listsize
26
27
  else
27
28
  @state.previous_line
28
29
  end
29
- else
30
+ else
30
31
  @state.line - (listsize/2)
31
32
  end
32
33
  e = b + listsize - 1
@@ -65,30 +66,30 @@ module Byebug
65
66
 
66
67
  private
67
68
 
68
- # Show FILE from line B to E where CURRENT is the current line number.
69
- # If we can show from B to E then we return B, otherwise we return the
70
- # previous line @state.previous_line.
71
- def display_list(b, e, file, current)
72
- print "[%d, %d] in %s\n", b, e, file
73
- lines = LineCache::getlines(file,
74
- Command.settings[:reload_source_on_change])
75
- if lines
76
- return @state.previous_line if b >= lines.size
77
- e = lines.size if lines.size < e
78
- [b, 1].max.upto(e) do |n|
79
- if n > 0 && lines[n-1]
80
- if n == current
81
- print "=> %d %s\n", n, lines[n-1].chomp
82
- else
83
- print " %d %s\n", n, lines[n-1].chomp
69
+ # Show FILE from line B to E where CURRENT is the current line number.
70
+ # If we can show from B to E then we return B, otherwise we return the
71
+ # previous line @state.previous_line.
72
+ def display_list(b, e, file, current)
73
+ print "[%d, %d] in %s\n", b, e, file
74
+ lines = LineCache::getlines(file,
75
+ Command.settings[:reload_source_on_change])
76
+ if lines
77
+ return @state.previous_line if b >= lines.size
78
+ e = lines.size if lines.size < e
79
+ [b, 1].max.upto(e) do |n|
80
+ if n > 0 && lines[n-1]
81
+ if n == current
82
+ print "=> %d %s\n", n, lines[n-1].chomp
83
+ else
84
+ print " %d %s\n", n, lines[n-1].chomp
85
+ end
84
86
  end
85
87
  end
88
+ else
89
+ errmsg "No sourcefile available for %s\n", file
90
+ return @state.previous_line
86
91
  end
87
- else
88
- errmsg "No sourcefile available for %s\n", file
89
- return @state.previous_line
92
+ return e == lines.size ? @state.previous_line : b
90
93
  end
91
- return e == lines.size ? @state.previous_line : b
92
- end
93
94
  end
94
95
  end
@@ -1,10 +1,10 @@
1
1
  module Byebug
2
- module SaveFunctions # :nodoc:
3
2
 
3
+ module SaveFunctions
4
4
  # Create a temporary file to write in if file is nil
5
5
  def open_save
6
6
  require "tempfile"
7
- file = Tempfile.new("rdebug-save")
7
+ file = Tempfile.new("byebug-save")
8
8
  # We want close to not unlink, so redefine.
9
9
  def file.close
10
10
  @tmpfile.close if @tmpfile
@@ -13,9 +13,9 @@ module Byebug
13
13
  end
14
14
  end
15
15
 
16
- class SaveCommand < Command # :nodoc:
16
+ class SaveCommand < Command
17
17
  self.allow_in_control = true
18
-
18
+
19
19
  def save_breakpoints(file)
20
20
  Byebug.breakpoints.each do |b|
21
21
  file.puts "break #{b.source}:#{b.pos}#{" if #{b.expr}" if b.expr}"
@@ -24,10 +24,10 @@ module Byebug
24
24
 
25
25
  def save_catchpoints(file)
26
26
  Byebug.catchpoints.keys.each do |c|
27
- file.puts "catch #{c}"
27
+ file.puts "catch #{c}"
28
28
  end
29
29
  end
30
-
30
+
31
31
  def save_displays(file)
32
32
  for d in @state.display
33
33
  if d[0]
@@ -35,7 +35,7 @@ module Byebug
35
35
  end
36
36
  end
37
37
  end
38
-
38
+
39
39
  def save_settings(file)
40
40
  # FIXME put routine in set
41
41
  %w(autoeval basename byebugtesting).each do |setting|
@@ -47,13 +47,13 @@ module Byebug
47
47
  file.puts "set #{setting} #{on_off}"
48
48
  end
49
49
  end
50
-
50
+
51
51
  def regexp
52
52
  /^\s* sa(?:ve)?
53
- (?:\s+(.+))?
53
+ (?:\s+(.+))?
54
54
  \s*$/ix
55
55
  end
56
-
56
+
57
57
  def execute
58
58
  if not @match[1] or @match[1].strip.empty?
59
59
  file = open_save()
@@ -75,7 +75,7 @@ module Byebug
75
75
  def help_command
76
76
  'save'
77
77
  end
78
-
78
+
79
79
  def help(cmd)
80
80
  %{
81
81
  save [FILE]
@@ -4,37 +4,35 @@ module Byebug
4
4
  class SetCommand < Command
5
5
  SubcmdStruct2=Struct.new(:name, :min, :is_bool, :short_help,
6
6
  :long_help) unless defined?(SubcmdStruct2)
7
- Subcommands =
8
- [
9
- ['annotate', 2, false, "Set annotation level",
10
- '0 == normal. ' \
11
- '2 == output annotated suitably for use by programs that control ' \
12
- 'byebug.'],
13
- ['args', 2, false,
14
- 'Set argument list to give program being debugged when it is started'],
15
- ['autoeval', 4, true, "Evaluate every unrecognized command"],
16
- ['autolist', 4, true, "Execute 'list' command on every breakpoint"],
17
- ['autoirb', 4, true, "Invoke IRB on every stop"],
18
- ['autoreload', 4, true, "Reload source code when changed"],
19
- ['basename', 1, true, "Report file basename only showing file names"],
20
- ['callstyle', 2, false, "Set how you want call parameters displayed"],
21
- ['byebugtesting', 8, false, "Used when testing byebug"],
22
- ['forcestep', 2, true,
23
- 'Make sure \'next/step\' commands always move to a new line'],
24
- ['fullpath', 2, true, "Display full file names in frames"],
25
- ['history', 2, false,
26
- 'Generic command for setting command history parameters',
27
- 'set history filename -- Set the filename in which to record the ' \
28
- 'command history. ' \
29
- 'set history save -- Set saving of the history record on exit. ' \
30
- 'set history size -- Set the size of the command history'],
31
- ['linetrace+', 10, true,
32
- 'Set line execution tracing to show different lines'],
33
- ['linetrace', 3, true, "Set line execution tracing"],
34
- ['listsize', 3, false, "Set number of source lines to list by default"],
35
- ['trace', 1, true, "Display stack trace when 'eval' raises exception"],
36
- ['width', 1, false,
37
- 'Number of characters per line for byebug\'s output']
7
+ Subcommands = [
8
+ ['annotate', 2, false, "Set annotation level",
9
+ '0 == normal. ' \
10
+ '2 == output annotated suitably for use by programs that control ' \
11
+ 'byebug.'],
12
+ ['args', 2, false,
13
+ 'Set argument list to give program being debugged when it is started'],
14
+ ['autoeval', 4, true, "Evaluate every unrecognized command"],
15
+ ['autolist', 4, true, "Execute 'list' command on every breakpoint"],
16
+ ['autoirb', 4, true, "Invoke IRB on every stop"],
17
+ ['autoreload', 4, true, "Reload source code when changed"],
18
+ ['basename', 1, true, "Report file basename only showing file names"],
19
+ ['callstyle', 2, false, "Set how you want call parameters displayed"],
20
+ ['byebugtesting', 8, false, "Used when testing byebug"],
21
+ ['forcestep', 2, true,
22
+ 'Make sure \'next/step\' commands always move to a new line'],
23
+ ['fullpath', 2, true, "Display full file names in frames"],
24
+ ['history', 2, false,
25
+ 'Generic command for setting command history parameters',
26
+ 'set history filename -- Set the filename in which to record the ' \
27
+ 'command history. ' \
28
+ 'set history save -- Set saving of the history record on exit. ' \
29
+ 'set history size -- Set the size of the command history'],
30
+ ['linetrace+', 10, true,
31
+ 'Set line execution tracing to show different lines'],
32
+ ['linetrace', 3, true, "Set line execution tracing"],
33
+ ['listsize', 3, false, "Set number of source lines to list by default"],
34
+ ['trace', 1, true, "Display stack trace when 'eval' raises exception"],
35
+ ['width', 1, false, 'Number of characters per line for byebug\'s output']
38
36
  ].map do |name, min, is_bool, short_help, long_help|
39
37
  SubcmdStruct2.new(name, min, is_bool, short_help, long_help)
40
38
  end unless defined?(Subcommands)
@@ -47,11 +45,7 @@ module Byebug
47
45
 
48
46
  def execute
49
47
  if not @match[1]
50
- print "\"set\" must be followed by the name of an set command:\n"
51
- print "List of set subcommands:\n\n"
52
- for subcmd in Subcommands do
53
- print "set #{subcmd.name} -- #{subcmd.short_help}\n"
54
- end
48
+ print_subcommands
55
49
  else
56
50
  args = @match[1].split(/[ \t]+/)
57
51
  subcmd = args.shift
@@ -80,10 +74,10 @@ module Byebug
80
74
  return
81
75
  end
82
76
  if defined?(Byebug::RDEBUG_SCRIPT)
83
- # rdebug was called initially. 1st arg is script name.
77
+ # byebug was called initially. 1st arg is script name.
84
78
  Command.settings[:argv][1..-1] = args
85
79
  else
86
- # rdebug wasn't called initially. 1st arg is not script name.
80
+ # byebug wasn't called initially. 1st arg is not script name.
87
81
  Command.settings[:argv] = args
88
82
  end
89
83
  when /^args$/
@@ -11,10 +11,10 @@ module Byebug
11
11
  when /^args$/
12
12
  if Command.settings[:argv] and Command.settings[:argv].size > 0
13
13
  if defined?(Byebug::RDEBUG_SCRIPT)
14
- # rdebug was called initially. 1st arg is script name.
14
+ # byebug was called initially. 1st arg is script name.
15
15
  args = Command.settings[:argv][1..-1].join(' ')
16
16
  else
17
- # rdebug wasn't called initially. 1st arg is not script name.
17
+ # byebug wasn't called initially. 1st arg is not script name.
18
18
  args = Command.settings[:argv].join(' ')
19
19
  end
20
20
  else
@@ -194,11 +194,7 @@ show history size -- Show the size of the command history"],
194
194
 
195
195
  def execute
196
196
  if not @match[1]
197
- print "\"show\" must be followed by the name of an show command:\n"
198
- print "List of show subcommands:\n\n"
199
- for subcmd in Subcommands do
200
- print "show #{subcmd.name} -- #{subcmd.short_help}\n"
201
- end
197
+ print_subcommands
202
198
  else
203
199
  args = @match[1].split(/[ \t]+/)
204
200
  param = args.shift
@@ -5,8 +5,7 @@ module Byebug
5
5
  ary.sort!
6
6
  for v in ary
7
7
  begin
8
- s = debug_eval(v.to_s, b).inspect unless
9
- v == :$KCODE || v == :$-K || v == :$=
8
+ s = debug_eval(v.to_s, b).inspect
10
9
  rescue
11
10
  begin
12
11
  s = debug_eval(v.to_s, b).to_s
@@ -14,9 +13,7 @@ module Byebug
14
13
  s = "*Error in evaluation*"
15
14
  end
16
15
  end
17
- if s.size > self.class.settings[:width]
18
- s[self.class.settings[:width]-3 .. -1] = "..."
19
- end
16
+ pad_with_dots(s)
20
17
  print "%s = %s\n", v, s
21
18
  end
22
19
  end
@@ -24,6 +21,9 @@ module Byebug
24
21
  obj = debug_eval('self')
25
22
  var_list(obj.class.class_variables, get_binding)
26
23
  end
24
+ def var_global
25
+ var_list(global_variables.reject { |v| [:$=, :$KCODE, :$-K].include?(v) })
26
+ end
27
27
  end
28
28
 
29
29
  # Implements byebug's 'var class' command
@@ -92,7 +92,7 @@ module Byebug
92
92
  end
93
93
 
94
94
  def execute
95
- var_list(global_variables)
95
+ var_global
96
96
  end
97
97
 
98
98
  class << self
@@ -63,7 +63,7 @@ module Byebug
63
63
  eval("BEGIN {return true}\n#{code}", nil, "", 0)
64
64
  rescue Exception
65
65
  false
66
- end
66
+ end
67
67
 
68
68
  end
69
69
  end
@@ -1,6 +1,6 @@
1
1
  module Byebug
2
2
 
3
- class Interface # :nodoc:
3
+ class Interface
4
4
  attr_writer :have_readline
5
5
 
6
6
  def initialize
@@ -31,13 +31,14 @@ module Byebug
31
31
 
32
32
  end
33
33
 
34
- class LocalInterface < Interface # :nodoc:
34
+ class LocalInterface < Interface
35
35
  attr_accessor :command_queue, :history_length, :history_save, :histfile
36
36
  attr_accessor :restart_file
37
37
 
38
38
  unless defined?(FILE_HISTORY)
39
- FILE_HISTORY = ".rdebug_hist"
39
+ FILE_HISTORY = ".byebug_hist"
40
40
  end
41
+
41
42
  def initialize()
42
43
  super
43
44
  @command_queue = []
@@ -126,7 +127,7 @@ module Byebug
126
127
  end
127
128
  end
128
129
 
129
- class RemoteInterface < Interface # :nodoc:
130
+ class RemoteInterface < Interface
130
131
  attr_accessor :command_queue, :history_length, :history_save, :histfile
131
132
  attr_accessor :restart_file
132
133
 
@@ -180,7 +181,7 @@ module Byebug
180
181
  end
181
182
  end
182
183
 
183
- class ScriptInterface < Interface # :nodoc:
184
+ class ScriptInterface < Interface
184
185
  attr_accessor :command_queue, :history_length, :history_save, :histfile
185
186
  attr_accessor :restart_file
186
187
 
@@ -86,7 +86,8 @@ module Byebug
86
86
  end
87
87
 
88
88
  def self.print_location_and_text(file, line)
89
- file_line = "#{canonic_file(file)}:#{line}\n#{Byebug.line_at(file, line)}"
89
+ file_line = "#{canonic_file(file)}:#{line}\n" \
90
+ "#{Byebug.line_at(file, line)}\n"
90
91
 
91
92
  # FIXME: use annotations routines
92
93
  if Byebug.annotate.to_i > 2
@@ -132,7 +133,7 @@ module Byebug
132
133
  aprint 'stopped' if Byebug.annotate.to_i > 2
133
134
  file = CommandProcessor.canonic_file(context.frame_file(0))
134
135
  line = context.frame_line(0)
135
- print afmt("%s:%d" % [file, line]) if ENV['EMACS']
136
+ #print afmt("%s:%d" % [file, line]) if ENV['EMACS']
136
137
  print "Catchpoint at %s:%d: `%s' (%s)\n", file, line, excpt, excpt.class
137
138
  fs = context.stack_size
138
139
  tb = caller(0)[-fs..-1]
@@ -148,10 +149,9 @@ module Byebug
148
149
  # Don't trace ourselves
149
150
  return if defined?(Byebug::RDEBUG_FILE) && Byebug::RDEBUG_FILE == file
150
151
 
151
- #@last_file = CommandProcessor.canonic_file(file)
152
152
  file = CommandProcessor.canonic_file(file)
153
- unless file == @last_file and line == @last_line and
154
- Command.settings[:tracing_plus]
153
+ tracing_plus = Command.settings[:tracing_plus]
154
+ if file != @last_file || line != @last_line || tracing_plus
155
155
  @last_file = file
156
156
  @last_line = line
157
157
  print "Tracing: #{file}:#{line} #{Byebug.line_at(file, line)}"
@@ -356,8 +356,8 @@ module Byebug
356
356
  end
357
357
 
358
358
  class State
359
- attr_accessor :binding, :commands, :context, :display, :file, :frame_pos
360
- attr_accessor :interface, :line, :previous_line
359
+ attr_accessor :binding, :commands, :context, :display, :file
360
+ attr_accessor :frame_pos, :interface, :line, :previous_line
361
361
 
362
362
  def initialize
363
363
  super()
@@ -382,7 +382,7 @@ module Byebug
382
382
  end # end class CommandProcessor
383
383
 
384
384
 
385
- class ControlCommandProcessor < Processor # :nodoc:
385
+ class ControlCommandProcessor < Processor
386
386
 
387
387
  def initialize(interface)
388
388
  super()
@@ -426,7 +426,7 @@ module Byebug
426
426
  # The prompt shown before reading a command.
427
427
  # Note: have an unused 'context' parameter to match the local interface.
428
428
  def prompt(context)
429
- p = '(rdb:ctrl) '
429
+ p = '(byebug:ctrl) '
430
430
  p = afmt("pre-prompt")+p+"\n"+afmt("prompt") if
431
431
  Byebug.annotate.to_i > 2
432
432
  return p
@@ -1,4 +1,4 @@
1
1
  module Byebug
2
2
  # Current version of the gem
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end