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
@@ -12,21 +12,21 @@ module Trepan
12
12
  def complete_token(complete_ary, prefix)
13
13
  complete_ary.select { |cmd| cmd.to_s.start_with?(prefix) }.sort
14
14
  end
15
-
15
+
16
16
  def complete_token_with_next(complete_hash, prefix, cmd_prefix='')
17
17
  result = []
18
- complete_hash.each do |cmd_name, cmd_obj|
19
- result << [cmd_name.to_s[cmd_prefix.size..-1], cmd_obj] if
18
+ complete_hash.each do |cmd_name, cmd_obj|
19
+ result << [cmd_name.to_s[cmd_prefix.size..-1], cmd_obj] if
20
20
  cmd_name.to_s.start_with?(cmd_prefix + prefix)
21
21
  end
22
22
  result.sort{|a, b| a[0] <=> b[0]}
23
23
  end
24
-
24
+
25
25
  # Find all starting matches in Hash +aliases+ that start with +prefix+,
26
26
  # but filter out any matches already in +expanded+.
27
27
  def complete_token_filtered(aliases, prefix, expanded)
28
28
  complete_ary = aliases.keys
29
- complete_ary.select { |cmd|
29
+ complete_ary.select { |cmd|
30
30
  cmd.to_s.start_with?(prefix) && ! expanded.member?(aliases[cmd])}.sort
31
31
  end
32
32
 
@@ -37,31 +37,31 @@ module Trepan
37
37
  complete_ary = aliases.keys
38
38
  expanded_ary = expanded.keys
39
39
  result = []
40
- complete_ary.each do |cmd|
41
- if cmd.to_s.start_with?(prefix) &&
40
+ complete_ary.each do |cmd|
41
+ if cmd.to_s.start_with?(prefix) &&
42
42
  !expanded_ary.member?(aliases[cmd])
43
- result << [cmd, commands[aliases[cmd]]]
43
+ result << [cmd, commands[aliases[cmd]]]
44
44
  end
45
45
  end
46
- result
46
+ result.sort
47
47
  end
48
48
 
49
49
  # Find the next token in str string from start_pos, we return
50
- # the token and the next blank position after the token or
50
+ # the token and the next blank position after the token or
51
51
  # str.size if this is the last token. Tokens are delimited by
52
52
  # white space.
53
53
  def next_token(str, start_pos)
54
54
  look_at = str[start_pos..-1]
55
55
  next_nonblank_pos = start_pos + (look_at =~ /\S/ || 0)
56
- next_blank_pos =
56
+ next_blank_pos =
57
57
  if next_match = str[next_nonblank_pos..-1] =~ /\s/
58
- next_nonblank_pos + next_match
58
+ next_nonblank_pos + next_match
59
59
  else
60
60
  str.size
61
61
  end
62
62
  return [next_blank_pos, str[next_nonblank_pos...next_blank_pos]]
63
63
  end
64
-
64
+
65
65
  end
66
66
  end
67
67
 
@@ -2,8 +2,8 @@
2
2
  require 'rubygems'; require 'require_relative'
3
3
  module Trepan
4
4
  # Default options to Trepan.start
5
- DEFAULT_START_SETTINGS = {
6
- :init => true, # Set $0 and save ARGV?
5
+ DEFAULT_START_SETTINGS = {
6
+ :init => true, # Set $0 and save ARGV?
7
7
  :post_mortem => false, # post-mortem debugging on uncaught exception?
8
8
  :tracing => nil # Debugger.tracing value. true/false resets,
9
9
  # nil keeps the prior value
@@ -14,10 +14,10 @@ module Trepan
14
14
 
15
15
  # What file is used for debugger startup commands.
16
16
  unless defined?(CMD_INITFILE_BASE)
17
- CMD_INITFILE_BASE =
17
+ CMD_INITFILE_BASE =
18
18
  if RUBY_PLATFORM =~ /mswin/
19
19
  # Of course MS Windows has to be different
20
- HOME_DIR = (ENV['HOME'] ||
20
+ HOME_DIR = (ENV['HOME'] ||
21
21
  ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
22
22
  'trepan8.ini'
23
23
  else
@@ -28,12 +28,12 @@ module Trepan
28
28
 
29
29
  CMD_INITFILE = File.join(HOME_DIR, CMD_INITFILE_BASE) unless
30
30
  defined?(CMD_INITFILE)
31
-
31
+
32
32
  # Default settings for a Trepan class object
33
33
  DEFAULT_SETTINGS = {
34
34
  :cmdproc_opts => {}, # Default Trepan::CmdProcessor settings
35
35
  :core_opts => {}, # Default Trepan::Core settings
36
- :delete_restore => true, # Delete restore profile after reading?
36
+ :delete_restore => true, # Delete restore profile after reading?
37
37
  :initial_dir => nil, # If --cd option was given, we save it here.
38
38
  :nx => false, # Don't run user startup file (e.g. .trepanxrc)
39
39
  :offset => 0, # skipping back +offset+ frames. This lets you start
@@ -42,7 +42,7 @@ module Trepan
42
42
  # Default values used only when 'server' or 'client'
43
43
  # (out-of-process debugging)
44
44
  :port => 1955,
45
- :host => 'localhost',
45
+ :host => 'localhost',
46
46
 
47
47
  :restart_argv => [],
48
48
  :server => false # Out-of-process debugging?
@@ -79,7 +79,7 @@ module Trepan
79
79
  # If start_sentinal is set, it is a string to look for in caller()
80
80
  # and is used to see if the call stack is truncated. Is also
81
81
  # defined in lib/trepanning.rb
82
- start_sentinal = nil;
82
+ start_sentinal = nil;
83
83
  end
84
84
  end
85
85
 
@@ -13,14 +13,14 @@ end
13
13
 
14
14
  # Manage a list of display expressions.
15
15
  class DisplayMgr
16
-
16
+
17
17
  def initialize
18
18
  @next = 0
19
19
  @list = []
20
20
  end
21
-
21
+
22
22
  def [](index)
23
- raise TypeError,
23
+ raise TypeError,
24
24
  "index #{index} should be a Fixnum, is #{index.class}" unless
25
25
  index.is_a?(Fixnum)
26
26
  @list.detect {|disp| disp.number == index }
@@ -108,7 +108,7 @@ class Display
108
108
  attr_reader :number
109
109
  attr_reader :signature
110
110
  attr_accessor :enabled
111
-
111
+
112
112
  def initialize(frame, arg, fmt, number)
113
113
  @signature = display_signature(frame)
114
114
  @fmt = fmt
@@ -135,7 +135,7 @@ class Display
135
135
 
136
136
  def to_s(frame)
137
137
  return 'No symbol "' + @arg + '" in current context.' unless frame
138
-
138
+
139
139
  begin
140
140
  val = eval(@arg, frame.binding)
141
141
  rescue
@@ -148,7 +148,7 @@ class Display
148
148
  # format display item
149
149
  def format(show_enabled=true)
150
150
  what = ''
151
- what += @enabled ? ' y ' : ' n ' if
151
+ what += @enabled ? ' y ' : ' n ' if
152
152
  show_enabled
153
153
  what += (@fmt + ' ') if @fmt
154
154
  what += @arg if @arg
@@ -167,7 +167,7 @@ if __FILE__ == $0
167
167
  mgr.all.each {|line| puts line}
168
168
  puts '=' * 40
169
169
  end
170
-
170
+
171
171
  frame = Debugger.current_context
172
172
 
173
173
  x = 1
@@ -12,7 +12,7 @@ module Trepan
12
12
  end
13
13
 
14
14
  def reset
15
- @binding = @klass = @file = @line =
15
+ @binding = @klass = @file = @line =
16
16
  @local_variables = @method_name = @thread = nil
17
17
  end
18
18
 
@@ -42,19 +42,19 @@ module Trepan
42
42
  if opts[:callstyle] == :tracked
43
43
  arg_info = @context.frame_args_info(@index)
44
44
  end
45
- call_str << "#{klass}."
45
+ call_str << "#{klass}."
46
46
  end
47
47
  call_str << method_name
48
48
  if args.any?
49
49
  call_str << "("
50
50
  args.each_with_index do |name, i|
51
- case opts[:callstyle]
51
+ case opts[:callstyle]
52
52
  when :short
53
53
  call_str += "%s, " % [name]
54
54
  when :last
55
55
  klass = locals[name].class
56
56
  if klass.inspect.size > 20+3
57
- klass = klass.inspect[0..20]+"..."
57
+ klass = klass.inspect[0..20]+"..."
58
58
  end
59
59
  call_str += "%s#%s, " % [name, klass]
60
60
  when :tracked
@@ -70,7 +70,7 @@ module Trepan
70
70
  break
71
71
  end
72
72
  end
73
- call_str[-2..-1] = ")" # Strip off trailing ', ' if any
73
+ call_str[-2..-1] = ")" # Strip off trailing ', ' if any
74
74
  end
75
75
  end
76
76
  return call_str
@@ -149,12 +149,12 @@ if __FILE__ == $0
149
149
  def foo(str, num)
150
150
  x = 1
151
151
  context = Debugger.current_context
152
- Debugger.skip do
152
+ Debugger.skip do
153
153
  0.upto(Debugger.current_context.stack_size-1) do |i|
154
154
  frame = Trepan::Frame.new(context)
155
155
  frame.index = i
156
- puts "Frame #{i}: #{frame.file}, line #{frame.line}, " +
157
- "class #{frame.klass}, thread: #{frame.thread}, " +
156
+ puts "Frame #{i}: #{frame.file}, line #{frame.line}, " +
157
+ "class #{frame.klass}, thread: #{frame.thread}, " +
158
158
  "method: #{frame.method_name}"
159
159
  p frame.local_variables
160
160
  puts frame.describe(:maxwidth => 80, :callstyle=>:tracked)
data/app/irb.rb CHANGED
@@ -3,49 +3,49 @@
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative 'util'
5
5
 
6
- Trepan::Util.suppress_warnings {
6
+ Trepan::Util.suppress_warnings {
7
7
  require 'irb'
8
8
  }
9
9
 
10
10
  module IRB # :nodoc:
11
11
  module ExtendCommand # :nodoc:
12
- # FIXME: should we read these out of a directory to
13
- # make this more user-customizable?
12
+ # FIXME: should we read these out of a directory to
13
+ # make this more user-customizable?
14
14
 
15
15
  unless defined? TContinue
16
16
 
17
17
  # A base command class that resume execution
18
18
  class TrepanResumeCommand
19
19
  def self.execute(conf, *opts)
20
- name =
20
+ name =
21
21
  if self.name =~ /IRB::ExtendCommand::(\S+)/
22
22
  $1[1..-1].downcase
23
23
  else
24
24
  'unknown'
25
25
  end
26
26
  $trepan_args = opts
27
- $trepan_command =
28
- if $trepan_irb_statements
27
+ $trepan_command =
28
+ if $trepan_irb_statements
29
29
  $trepan_irb_statements
30
30
  else
31
31
  ([name] + opts).join(' ')
32
32
  end
33
-
33
+
34
34
  throw :IRB_EXIT, name.to_sym
35
35
  end
36
36
  end
37
-
37
+
38
38
  class TContinue < TrepanResumeCommand ; end
39
39
  class TFinish < TrepanResumeCommand ; end
40
40
  class TNext < TrepanResumeCommand ; end
41
41
  class TQuit < TrepanResumeCommand ; end
42
42
  class TStep < TrepanResumeCommand ; end
43
-
43
+
44
44
  # Issues a comamnd to the debugger without continuing
45
- # execution.
45
+ # execution.
46
46
  class TDbgr
47
47
  def self.execute(conf, *opts)
48
- $trepan_command =
48
+ $trepan_command =
49
49
  if opts.size == 1 && opts[0].is_a?(String)
50
50
  $trepan_args = opts[0]
51
51
  else
@@ -79,7 +79,7 @@ module IRB # :nodoc:
79
79
  unless @__initialized
80
80
 
81
81
  # Set to run the standard trepan IRB profile
82
- irbrc = File.expand_path(File.join(File.dirname(__FILE__),
82
+ irbrc = File.expand_path(File.join(File.dirname(__FILE__),
83
83
  %w(.. data irbrc)))
84
84
  ENV['IRBRC'] = irbrc
85
85
 
@@ -87,7 +87,7 @@ module IRB # :nodoc:
87
87
  ARGV.replace([])
88
88
  IRB.setup(nil)
89
89
  ARGV.replace(args)
90
-
90
+
91
91
  # If the user has a IRB profile, run that now.
92
92
  if ENV['TREPANX_IRB']
93
93
  ENV['IRBRC'] = ENV['TREPANX_IRB']
@@ -97,7 +97,7 @@ module IRB # :nodoc:
97
97
 
98
98
  @__initialized = true
99
99
  end
100
-
100
+
101
101
  workspace = WorkSpace.new(binding)
102
102
 
103
103
  irb = Irb.new(workspace)
@@ -105,7 +105,7 @@ module IRB # :nodoc:
105
105
  @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
106
106
  @CONF[:MAIN_CONTEXT] = irb.context
107
107
  conf.each {|k, v| @CONF[k] = v}
108
- # A copy of this back_trace_limit is already active. How?
108
+ # A copy of this back_trace_limit is already active. How?
109
109
  IRB.CurrentContext.back_trace_limit = @CONF[:BACK_TRACE_LIMIT]
110
110
 
111
111
  catch(:IRB_EXIT) do
@@ -2,14 +2,14 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
4
4
  #=== Summary
5
- # Parses command-line options.
5
+ # Parses command-line options.
6
6
 
7
7
  require 'optparse'
8
8
  module Trepan
9
9
  require 'rubygems'; require 'require_relative'
10
10
  require_relative 'default'
11
11
 
12
- VERSION = '0.1.5' unless defined? Trepan::VERSION
12
+ VERSION = '0.1.6' unless defined? Trepan::VERSION
13
13
  PROGRAM = 'trepan8' unless defined? Trepan::PROGRAM
14
14
 
15
15
  module_function
@@ -21,7 +21,7 @@ module Trepan
21
21
  def copy_default_options
22
22
  options = {}
23
23
  DEFAULT_CMDLINE_SETTINGS.each do |key, value|
24
- begin
24
+ begin
25
25
  options[key] = value.clone
26
26
  rescue TypeError
27
27
  options[key] = value
@@ -46,8 +46,8 @@ EOB
46
46
  options[:client] = true
47
47
  end
48
48
  end
49
- opts.on('-c', '--command FILE', String,
50
- 'Execute debugger commands from FILE') do |cmdfile|
49
+ opts.on('-c', '--command FILE', String,
50
+ 'Execute debugger commands from FILE') do |cmdfile|
51
51
  if File.readable?(cmdfile)
52
52
  options[:cmdfiles] << cmdfile
53
53
  elsif File.exists?(cmdfile)
@@ -56,7 +56,7 @@ EOB
56
56
  stderr.puts "Command file '#{cmdfile}' does not exist."
57
57
  end
58
58
  end
59
- opts.on('--cd DIR', String, 'Change current directory to DIR') do |dir|
59
+ opts.on('--cd DIR', String, 'Change current directory to DIR') do |dir|
60
60
  if File.directory?(dir)
61
61
  if File.executable?(dir)
62
62
  options[:chdir] = dir
@@ -67,14 +67,14 @@ EOB
67
67
  stderr.puts "\"#{dir}\" is not a directory. Option --cd ignored."
68
68
  end
69
69
  end
70
- opts.on('--basename',
71
- 'Show only file basename in file locations') do
70
+ opts.on('--basename',
71
+ 'Show only file basename in file locations') do
72
72
  options[:basename] = true
73
73
  end
74
- opts.on('-d', '--debug', 'Set $DEBUG=true') do
74
+ opts.on('-d', '--debug', 'Set $DEBUG=true') do
75
75
  $DEBUG = true
76
76
  end
77
- opts.on('--cport PORT', Integer, 'Port used for control commands') do
77
+ opts.on('--cport PORT', Integer, 'Port used for control commands') do
78
78
  |cport|
79
79
  options[:cport] = cport
80
80
  end
@@ -89,23 +89,23 @@ EOB
89
89
  end
90
90
  unless LineCache.respond_to?(:clear_file_format_cache)
91
91
  stderr.puts "Your version of LineCache doesn't support terminal highlight"
92
- options[:higlight] = false
92
+ options[:higlight] = false
93
93
  end
94
94
  end
95
95
  end
96
- opts.on('-h', '--host NAME', String,
97
- 'Host or IP used in TCP connections for --server or --client. ' +
98
- "Default is #{DEFAULT_SETTINGS[:host].inspect}.") do
99
- |name_or_ip|
96
+ opts.on('-h', '--host NAME', String,
97
+ 'Host or IP used in TCP connections for --server or --client. ' +
98
+ "Default is #{DEFAULT_SETTINGS[:host].inspect}.") do
99
+ |name_or_ip|
100
100
  options[:host] = name_or_ip
101
101
  end
102
102
  opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
103
103
  $LOAD_PATH.unshift(path)
104
104
  end
105
- opts.on('--keep-frame-binding', 'Keep frame bindings') do
105
+ opts.on('--keep-frame-binding', 'Keep frame bindings') do
106
106
  options[:frame_bind] = true
107
107
  end
108
- opts.on('-m', '--post-mortem', 'Activate post-mortem mode') do
108
+ opts.on('-m', '--post-mortem', 'Activate post-mortem mode') do
109
109
  options[:post_mortem] = true
110
110
  end
111
111
  opts.on('--nx',
@@ -115,10 +115,10 @@ EOB
115
115
  opts.on('--[no-]control', 'Start [not] control thread') do |v|
116
116
  options[:control] = v
117
117
  end
118
- opts.on('-p', '--port NUMBER', Integer,
119
- 'Port number used in TCP connections for --server or --client. ' +
120
- "Default is #{DEFAULT_SETTINGS[:port]}.") do
121
- |num|
118
+ opts.on('-p', '--port NUMBER', Integer,
119
+ 'Port number used in TCP connections for --server or --client. ' +
120
+ "Default is #{DEFAULT_SETTINGS[:port]}.") do
121
+ |num|
122
122
  options[:port] = num
123
123
  end
124
124
  opts.on('--[no-]quit', 'Do [not] quit when script finishes') do |v|
@@ -143,7 +143,7 @@ EOB
143
143
  opts.on('--[no-]stop', 'Do not stop when script is loaded') do |v|
144
144
  options[:stop] = v
145
145
  end
146
- opts.on('--script FILE', String, 'Name of the script file to run') do
146
+ opts.on('--script FILE', String, 'Name of the script file to run') do
147
147
  |script|
148
148
  options[:script] = script
149
149
  unless File.exists?(options[:script])
@@ -162,7 +162,7 @@ EOB
162
162
  opts.on('-w', '--wait', 'Wait for a client connection; implies -s option') do
163
163
  options[:wait] = true
164
164
  end
165
- opts.on('-x', '--trace', 'Turn on line tracing') do
165
+ opts.on('-x', '--trace', 'Turn on line tracing') do
166
166
  options[:traceprint] = true
167
167
  options[:nx] = true
168
168
  end
@@ -170,9 +170,9 @@ EOB
170
170
  opts.on_tail('-?', '--help', 'Show this message') do
171
171
  options[:help] = true
172
172
  stdout.puts opts
173
- exit
173
+ exit
174
174
  end
175
- opts.on_tail('-v', '--version',
175
+ opts.on_tail('-v', '--version',
176
176
  'print the version') do
177
177
  options[:version] = true
178
178
  stdout.puts show_version