rb8-trepanning 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES +18 -4
  2. data/ChangeLog +100 -87
  3. data/Makefile +23 -4
  4. data/README.textile +3 -3
  5. data/Rakefile +26 -20
  6. data/app/complete.rb +13 -13
  7. data/app/default.rb +8 -8
  8. data/app/display.rb +7 -7
  9. data/app/frame.rb +8 -8
  10. data/app/irb.rb +15 -15
  11. data/app/options.rb +25 -25
  12. data/app/run.rb +16 -8
  13. data/app/util.rb +7 -7
  14. data/bin/trepan8 +2 -2
  15. data/check-filter.rb +21 -0
  16. data/interface.rb +4 -4
  17. data/interface/user.rb +11 -11
  18. data/io.rb +18 -19
  19. data/io/input.rb +14 -12
  20. data/lib/debugger.rb +3 -1
  21. data/lib/trepanning.rb +30 -28
  22. data/processor.rb +41 -38
  23. data/processor/command.rb +9 -9
  24. data/processor/command/alias.rb +6 -6
  25. data/processor/command/down.rb +1 -2
  26. data/processor/command/edit.rb +12 -8
  27. data/processor/command/eval.rb +7 -7
  28. data/processor/command/info_subcmd/macro.rb +6 -6
  29. data/processor/command/info_subcmd/program.rb +5 -1
  30. data/processor/command/macro.rb +6 -6
  31. data/processor/command/show_subcmd/abbrev.rb +2 -2
  32. data/processor/command/up.rb +1 -2
  33. data/processor/complete.rb +120 -0
  34. data/processor/default.rb +13 -9
  35. data/processor/load_cmds.rb +18 -97
  36. data/processor/location.rb +34 -31
  37. data/processor/msg.rb +5 -5
  38. data/processor/validate.rb +44 -35
  39. data/test/data/break_loop_bug.right +2 -2
  40. data/test/data/edit.cmd +1 -1
  41. data/test/data/edit.right +7 -1
  42. data/test/data/printvar.right +2 -2
  43. data/test/data/raise.right +0 -1
  44. data/test/data/trace-mingw.right +28 -0
  45. data/test/integration/.gitignore +1 -0
  46. data/test/integration/test-raise.rb +10 -1
  47. data/test/integration/test-trace.rb +10 -6
  48. data/test/unit/test-app-options.rb +9 -3
  49. data/test/unit/test-app-run.rb +8 -1
  50. data/test/unit/test-cmd-alias.rb +2 -2
  51. data/test/unit/test-proc-default.rb +34 -0
  52. metadata +10 -6
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
1
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
3
  require_relative '../command'
4
4
 
@@ -9,7 +9,7 @@ class Trepan::Command::AliasCommand < Trepan::Command
9
9
  HELP = <<-HELP
10
10
  #{NAME} ALIAS COMMAND
11
11
 
12
- Add alias ALIAS for a debugger command COMMAND.
12
+ Add alias ALIAS for a debugger command COMMAND.
13
13
 
14
14
  Add an alias when you want to use a command abbreviation for a command
15
15
  that would otherwise be ambigous. For example, by default we make 's'
@@ -20,7 +20,7 @@ Example:
20
20
 
21
21
  alias cat list # "cat rubyfile.rb" is the same as "list rubyfile.rb"
22
22
  alias s step # "s" is now an alias for "step".
23
- # The above examples done by default.
23
+ # The above example is done by default.
24
24
 
25
25
  See also 'unalias' and 'show #{NAME}'.
26
26
  HELP
@@ -30,8 +30,8 @@ See also 'unalias' and 'show #{NAME}'.
30
30
  NEED_STACK = true
31
31
  SHORT_HELP = 'Add an alias for a debugger command'
32
32
  end
33
-
34
- # Run command.
33
+
34
+ # Run command.
35
35
  def run(args)
36
36
  if args.size == 1
37
37
  @proc.commands['show'].run(%W(show #{NAME}))
@@ -43,7 +43,7 @@ See also 'unalias' and 'show #{NAME}'.
43
43
  if @proc.commands.member?(command)
44
44
  @proc.aliases[al] = command
45
45
  if old_command
46
- msg("Alias '#{al}' for command '#{command}' replaced old " +
46
+ msg("Alias '#{al}' for command '#{command}' replaced old " +
47
47
  "alias for '#{old_command}'.")
48
48
  else
49
49
  msg "New alias '#{al}' for command '#{command}' created."
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative 'up'
5
5
 
@@ -19,7 +19,6 @@ is the most recent frame. If no count is given, move down 1.
19
19
  See also 'up' and 'frame'.
20
20
  HELP
21
21
 
22
- ALIASES = %w(d)
23
22
  NAME = File.basename(__FILE__, '.rb')
24
23
  SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
25
24
  }
@@ -1,11 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../command'
5
5
 
6
6
  class Trepan::Command::EditCommand < Trepan::Command
7
7
 
8
- old_verbose = $VERBOSE
8
+ old_verbose = $VERBOSE
9
9
  $VERBOSE = nil
10
10
  NAME = File.basename(__FILE__, '.rb')
11
11
  HELP = <<-HELP
@@ -30,7 +30,7 @@ Examples:
30
30
  NEED_STACK = false
31
31
  SHORT_HELP = 'Invoke an editor on some source code'
32
32
  MAX_ARGS = 2
33
- $VERBOSE = old_verbose
33
+ $VERBOSE = old_verbose
34
34
 
35
35
  # FIXME: redo with locations and kparse.
36
36
  def run(args)
@@ -38,28 +38,32 @@ Examples:
38
38
  when 1
39
39
  unless @proc.context
40
40
  errmsg "We are not in a state that has an associated file."
41
- return
41
+ return
42
42
  end
43
43
  file = @proc.frame.file
44
44
  line = @proc.frame.line
45
45
  when 2
46
46
  line = Integer(args[1]) rescue nil
47
- if line
47
+ if line
48
48
  unless @proc.context
49
49
  errmsg "We are not in a state that has an associated file."
50
- return
50
+ return
51
51
  end
52
52
  file = @proc.frame.file
53
- else
53
+ else
54
54
  file = args[1]
55
55
  line = 1
56
56
  end
57
57
  when 3
58
58
  line, file = args[2], args[1]
59
59
  else
60
- errmsg "edit needs at most 2 args."
60
+ errmsg "edit needs at most 2 args."
61
61
  end
62
62
  editor = ENV['EDITOR'] || '/bin/ex'
63
+ unless File.executable?(editor)
64
+ errmsg "Editor #{editor} is not executable. Trying anyway..."
65
+ end
66
+
63
67
  if File.readable?(file)
64
68
  file = File.basename(file) if settings[:basename]
65
69
  edit_cmd = "#{editor} +#{line} \"#{file}\""
@@ -5,7 +5,7 @@ require_relative '../command'
5
5
 
6
6
  class Trepan::Command::EvalCommand < Trepan::Command
7
7
 
8
- old_verbose = $VERBOSE
8
+ old_verbose = $VERBOSE
9
9
  $VERBOSE = nil
10
10
  NAME = File.basename(__FILE__, '.rb')
11
11
  HELP = <<-HELP
@@ -19,7 +19,7 @@ next to the inspect output of the value.
19
19
 
20
20
  If no string is given, we run the string from the current source code
21
21
  about to be run. If the command ends ? (via an alias) and no string is
22
- given we will the following translations occur:
22
+ given, the following translations occur:
23
23
 
24
24
  {if|elsif|unless} expr [then] => expr
25
25
  {until|while} expr [do] => expr
@@ -38,7 +38,7 @@ Examples:
38
38
  #{NAME} @v
39
39
  #{NAME} # Run current source-code line
40
40
  #{NAME}? # but strips off leading 'if', 'while', ..
41
- # from command
41
+ # from command
42
42
 
43
43
  See also 'set autoeval'. The command helps one predict future execution.
44
44
  See 'set buffer trace' for showing what may have already been run.
@@ -48,14 +48,14 @@ See 'set buffer trace' for showing what may have already been run.
48
48
  CATEGORY = 'data'
49
49
  NEED_STACK = true
50
50
  SHORT_HELP = 'Run code in the current context'
51
- $VERBOSE = old_verbose
51
+ $VERBOSE = old_verbose
52
52
 
53
53
  def complete(prefix)
54
- if prefix.empty?
54
+ if prefix.empty?
55
55
  if @proc.leading_str.start_with?('eval?')
56
56
  Trepan::Util.extract_expression(@proc.current_source_text)
57
57
  else
58
- @proc.current_source_text
58
+ @proc.current_source_text
59
59
  end
60
60
  else
61
61
  prefix
@@ -66,7 +66,7 @@ See 'set buffer trace' for showing what may have already been run.
66
66
  if args.size == 1
67
67
  text = @proc.current_source_text.chomp
68
68
  ## FIXME turn into a subroutine and use in complete.
69
- if '?' == args[0][-1..-1]
69
+ if '?' == args[0][-1..-1]
70
70
  text = Trepan::Util::extract_expression(text)
71
71
  msg "eval: #{text}"
72
72
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../base/subcmd'
5
5
  require_relative '../../../app/complete'
@@ -8,14 +8,14 @@ class Trepan::Subcommand::InfoMacro < Trepan::Subcommand
8
8
  unless defined?(HELP)
9
9
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
10
10
  HELP = <<-HELP
11
- #{CMD}
11
+ #{CMD}
12
12
  #{CMD} *
13
13
  #{CMD} MACRO1 [MACRO2 ..]
14
14
 
15
15
  In the first form a list of the existing macro names are shown
16
16
  in column format.
17
17
 
18
- In the second form, all macro names and their definitions are show.
18
+ In the second form, all macro names and their definitions are shown.
19
19
 
20
20
  In the last form the only definitions of the given macro names is shown.
21
21
  HELP
@@ -29,12 +29,12 @@ In the last form the only definitions of the given macro names is shown.
29
29
 
30
30
  def run(args)
31
31
  if args.size > 2
32
- macro_names =
33
- if args.size == 3 && '*' == args[2]
32
+ macro_names =
33
+ if args.size == 3 && '*' == args[2]
34
34
  @proc.macros.keys
35
35
  else
36
36
  args[2..-1]
37
- end
37
+ end
38
38
  macro_names.each do |macro_name|
39
39
  if @proc.macros.member?(macro_name)
40
40
  section "#{macro_name}:"
@@ -19,7 +19,8 @@ class Trepan::Subcommand::InfoProgram < Trepan::Subcommand
19
19
  return
20
20
  end
21
21
  case @proc.event
22
- when :raise
22
+ when 'raise'
23
+ when 'post-mortem'
23
24
  status = 'crashed'
24
25
  else
25
26
  status = 'stopped'
@@ -36,6 +37,9 @@ class Trepan::Subcommand::InfoProgram < Trepan::Subcommand
36
37
  when :catchpoint
37
38
  msg("Handling an uncaught exception `%s' (%s)." % [event_arg,
38
39
  event_arg.class])
40
+ when :"post-mortem"
41
+ msg("It stopped in post-mortem exception `%s' (%s)." % [event_arg,
42
+ event_arg.class])
39
43
  else
40
44
  msg "unknown reason: %s" % @proc.context.stop_reason.to_s
41
45
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../command'
5
5
  require_relative '../eval'
@@ -37,25 +37,25 @@ could do that this way:
37
37
 
38
38
  macro fin+ Proc.new{|*args| ['finish \#{args[0]}' 'step']}
39
39
 
40
- Invoking with
40
+ Invoking with
41
41
  fin+ 3
42
42
 
43
43
  would expand to ["finish 3", "step"]
44
44
 
45
- If you were to add another parameter for 'step', the note that the
45
+ If you were to add another parameter for 'step', the note that the
46
46
  invocation might be:
47
47
  fin+ 3 2
48
48
 
49
49
  rather than 'fin+(3,2)' or 'fin+ 3, 2'.
50
50
 
51
- See also 'show macro'.
51
+ See also 'alias' and 'info macro'.
52
52
  HELP
53
53
 
54
54
  CATEGORY = 'support'
55
55
  MIN_ARGS = 2 # Need at least this many
56
56
  SHORT_HELP = 'Define a macro'
57
57
  end
58
-
58
+
59
59
  def run(args)
60
60
  cmd_name = args[1]
61
61
  cmd_argstr = @proc.cmd_argstr[cmd_name.size..-1].lstrip
@@ -70,7 +70,7 @@ See also 'show macro'.
70
70
  end
71
71
  end
72
72
  end
73
-
73
+
74
74
  if __FILE__ == $0
75
75
  require_relative '../mock'
76
76
  dbgr, cmd = MockDebugger::setup
@@ -1,12 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../base/subcmd'
5
5
 
6
6
  class Trepan::Subcommand::ShowAbbrev < Trepan::ShowBoolSubcommand
7
7
  unless defined?(HELP)
8
8
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
- HELP = "Show whether we allow abbreviate debugger command names"
9
+ HELP = "Show whether we allow abbreviated debugger command names"
10
10
  MIN_ABBREV = 'ab'.size
11
11
  end
12
12
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
1
+ # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
3
  require_relative '../command'
4
4
 
@@ -18,7 +18,6 @@ the most recent frame. If no count is given, move up 1.
18
18
  See also 'down' and 'frame'.
19
19
  HELP
20
20
 
21
- ALIASES = %w(u)
22
21
  CATEGORY = 'stack'
23
22
  MAX_ARGS = 1 # Need at most this many
24
23
  NEED_STACK = true
@@ -0,0 +1,120 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Part of Trepan::CmdProcess to handle command completion
5
+ require_relative '../app/complete'
6
+ require_relative 'virtual'
7
+
8
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
9
+
10
+ attr_reader :leading_str # leading part of string. Used in
11
+ # command completion
12
+
13
+ # Handle initial completion. We draw from the commands, aliases,
14
+ # and macros for completion. However we won't include aliases which
15
+ # are prefixes of other commands.
16
+ def complete(str, last_token)
17
+ @leading_str = str
18
+ next_blank_pos, token = Trepan::Complete.next_token(str, 0)
19
+ return [''] if token.empty? && !last_token.empty?
20
+ match_pairs = Trepan::Complete.complete_token_with_next(@commands,
21
+ token)
22
+ match_hash = {}
23
+ match_pairs.each do |pair|
24
+ match_hash[pair[0]] = pair[1]
25
+ end
26
+ alias_pairs = Trepan::Complete.
27
+ complete_token_filtered_with_next(@aliases, token, match_hash,
28
+ @commands)
29
+ match_pairs += alias_pairs
30
+
31
+ macro_pairs = Trepan::Complete.
32
+ complete_token_filtered_with_next(@macros, token, match_hash,
33
+ @commands)
34
+ match_pairs += macro_pairs
35
+
36
+ if str[next_blank_pos..-1].empty?
37
+ return match_pairs.map{|pair| pair[0]}.sort
38
+ else
39
+ alias_pairs.each do |pair|
40
+ match_hash[pair[0]] = pair[1]
41
+ end
42
+ end
43
+ if match_pairs.size > 1
44
+ # FIXME: figure out what to do here.
45
+ # Matched multiple items in the middle of the string
46
+ # We can't handle this so do nothing.
47
+ return []
48
+ # return match_pairs.map do |name, cmd|
49
+ # ["#{name} #{args[1..-1].join(' ')}"]
50
+ # end
51
+ end
52
+ # match_pairs.size == 1
53
+ next_complete(str, next_blank_pos, match_pairs[0][1], last_token)
54
+ end
55
+
56
+ def next_complete(str, next_blank_pos, cmd, last_token)
57
+ next_blank_pos, token = Trepan::Complete.next_token(str, next_blank_pos)
58
+ return [] if token.empty? && !last_token.empty?
59
+
60
+ if cmd.respond_to?(:complete_token_with_next)
61
+ match_pairs = cmd.complete_token_with_next(token)
62
+ return [] if match_pairs.empty?
63
+ if str[next_blank_pos..-1].rstrip.empty? &&
64
+ (token.empty? || token == last_token)
65
+ return match_pairs.map { |completion, junk| completion }
66
+ else
67
+ if match_pairs.size == 1
68
+ return next_complete(str, next_blank_pos, match_pairs[0][1],
69
+ last_token)
70
+ else
71
+ # FIXME: figure out what to do here.
72
+ # Matched multiple items in the middle of the string
73
+ # We can't handle this so do nothing.
74
+ return []
75
+ end
76
+ end
77
+ elsif cmd.respond_to?(:complete)
78
+ matches = cmd.complete(token)
79
+ return [] if matches.empty?
80
+ if str[next_blank_pos..-1].rstrip.empty? &&
81
+ (token.empty? || token == last_token)
82
+ return matches
83
+ else
84
+ # FIXME: figure out what to do here.
85
+ # Matched multiple items in the middle of the string
86
+ # We can't handle this so do nothing.
87
+ return []
88
+ end
89
+ else
90
+ return []
91
+ end
92
+ end
93
+ end
94
+
95
+ if __FILE__ == $0
96
+
97
+ require_relative 'load_cmds'
98
+ class Trepan::CmdProcessor
99
+ def initialize(core, settings={})
100
+ end
101
+ end
102
+
103
+
104
+ cmdproc = Trepan::CmdProcessor.new(nil)
105
+
106
+ def cmdproc.errmsg(mess)
107
+ puts "** #{mess}"
108
+ end
109
+
110
+ def cmdproc.msg(mess)
111
+ puts mess
112
+ end
113
+
114
+ cmddir = File.join(File.dirname(__FILE__), 'command')
115
+ cmdproc.instance_variable_set('@settings', {})
116
+ cmdproc.load_cmds_initialize
117
+ p cmdproc.complete("d", 'd')
118
+ p cmdproc.complete("sho d", 'd')
119
+ p cmdproc.complete('', '')
120
+ end
@@ -1,19 +1,23 @@
1
+ # Copyright (C) 2013 Rocky Bernstein <rockyb@rubyforge.net>
1
2
  require 'rubygems'; require 'require_relative'
2
3
  require_relative '../app/default' # for Trepan::HOME_DIR etc.
3
4
  require_relative 'virtual'
4
5
  class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
5
6
 
7
+ computed_displaywidth = (ENV['COLUMNS'] || '80').to_i
8
+ computed_displaywidth = 80 unless computed_displaywidth >= 10
9
+
6
10
  DEFAULT_SETTINGS = {
7
11
  :abbrev => true, # Allow abbreviations of debugger commands?
8
12
  :autoeval => true, # Ruby eval non-debugger commands
9
13
  :autoirb => false, # Go into IRB in debugger command loop
10
- :autolist => false, # Run 'list'
11
-
14
+ :autolist => false, # Run 'list'
15
+
12
16
  :basename => false, # Show basename of filenames only
13
- :callstyle => :last, #
17
+ :callstyle => :last, #
14
18
  :confirm => true, # Confirm potentially dangerous operations?
15
- :different => 'nostack', # stop *only* when different position?
16
-
19
+ :different => 'nostack', # stop *only* when different position?
20
+
17
21
  :debugdbgr => false, # Debugging the debugger
18
22
  :debugexcept => true, # Internal debugging of command exceptions
19
23
  :debugmacro => false, # debugging macros
@@ -26,14 +30,14 @@ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
26
30
  # nil or -1 means compute value. 0
27
31
  # means hide none. Less than 0 means show
28
32
  # all stack entries.
29
- :hightlight => false, # Use terminal highlight?
30
-
31
- :maxlist => 10, # Number of source lines to list
33
+ :hightlight => false, # Use terminal highlight?
34
+
35
+ :maxlist => 10, # Number of source lines to list
32
36
  :maxstack => 10, # backtrace limit
33
37
  :maxstring => 150, # Strings which are larger than this
34
38
  # will be truncated to this length when
35
39
  # printed
36
- :maxwidth => (ENV['COLUMNS'] || '80').to_i,
40
+ :maxwidth => computed_displaywidth,
37
41
  :prompt => 'trepan8', # core part of prompt. Additional info like
38
42
  # debug nesting and thread name is fixed
39
43
  # and added on.