trepanning 0.1.3 → 0.1.4

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 (134) hide show
  1. data/ChangeLog +465 -0
  2. data/NEWS +26 -1
  3. data/README.textile +1 -1
  4. data/app/cmd_parse.kpeg +2 -1
  5. data/app/cmd_parser.rb +30 -3
  6. data/app/core.rb +1 -1
  7. data/app/display.rb +39 -1
  8. data/app/frame.rb +1 -1
  9. data/app/irb.rb +42 -40
  10. data/app/options.rb +3 -2
  11. data/app/run.rb +21 -7
  12. data/app/util.rb +12 -2
  13. data/app/yarv.rb +0 -2
  14. data/bin/trepan +2 -3
  15. data/data/perldb.bindings +17 -0
  16. data/interface/script.rb +1 -1
  17. data/interface/server.rb +1 -1
  18. data/interface/user.rb +3 -1
  19. data/{interface/base_intf.rb → interface.rb} +1 -1
  20. data/io/input.rb +1 -3
  21. data/io/null_output.rb +1 -1
  22. data/io/string_array.rb +1 -2
  23. data/io/tcpclient.rb +1 -1
  24. data/io/tcpserver.rb +1 -1
  25. data/{io/base_io.rb → io.rb} +0 -0
  26. data/lib/trepanning.rb +2 -1
  27. data/processor/command/alias.rb +15 -4
  28. data/processor/command/backtrace.rb +2 -2
  29. data/processor/command/base/subcmd.rb +1 -5
  30. data/processor/command/base/submgr.rb +1 -1
  31. data/processor/command/base/subsubcmd.rb +1 -1
  32. data/processor/command/base/subsubmgr.rb +4 -4
  33. data/processor/command/break.rb +1 -1
  34. data/processor/command/complete.rb +1 -1
  35. data/processor/command/condition.rb +2 -2
  36. data/processor/command/continue.rb +1 -1
  37. data/processor/command/debug.rb +1 -1
  38. data/processor/command/delete.rb +10 -7
  39. data/processor/command/directory.rb +1 -1
  40. data/processor/command/disable.rb +25 -19
  41. data/processor/command/disassemble.rb +1 -1
  42. data/processor/command/display.rb +35 -28
  43. data/processor/command/down.rb +8 -8
  44. data/processor/command/edit.rb +1 -1
  45. data/processor/command/enable.rb +10 -12
  46. data/processor/command/eval.rb +1 -1
  47. data/processor/command/exit.rb +1 -1
  48. data/processor/command/finish.rb +1 -1
  49. data/processor/command/frame.rb +2 -2
  50. data/processor/command/help.rb +6 -8
  51. data/processor/command/info.rb +2 -0
  52. data/processor/command/info_subcmd/files.rb +17 -11
  53. data/processor/command/info_subcmd/frame.rb +0 -1
  54. data/processor/command/info_subcmd/locals.rb +6 -73
  55. data/processor/command/info_subcmd/source.rb +10 -4
  56. data/processor/command/info_subcmd/variables.rb +34 -0
  57. data/processor/command/info_subcmd/variables_subcmd/.gitignore +1 -0
  58. data/processor/command/info_subcmd/variables_subcmd/class.rb +40 -0
  59. data/processor/command/info_subcmd/variables_subcmd/constant.rb +41 -0
  60. data/processor/command/info_subcmd/{globals.rb → variables_subcmd/globals.rb} +21 -16
  61. data/processor/command/info_subcmd/variables_subcmd/instance.rb +41 -0
  62. data/processor/command/info_subcmd/variables_subcmd/locals.rb +99 -0
  63. data/processor/command/kill.rb +9 -8
  64. data/processor/command/list.rb +9 -107
  65. data/processor/command/macro.rb +27 -9
  66. data/processor/command/next.rb +1 -1
  67. data/processor/command/nocache.rb +2 -2
  68. data/processor/command/parsetree.rb +1 -1
  69. data/processor/command/pp.rb +1 -1
  70. data/processor/command/pr.rb +1 -1
  71. data/processor/command/ps.rb +1 -1
  72. data/processor/command/quit.rb +18 -7
  73. data/processor/command/raise.rb +1 -1
  74. data/processor/command/reload.rb +10 -10
  75. data/processor/command/restart.rb +1 -1
  76. data/processor/command/save.rb +1 -1
  77. data/processor/command/server.rb +1 -1
  78. data/processor/command/set_subcmd/auto.rb +7 -1
  79. data/processor/command/set_subcmd/different.rb +5 -4
  80. data/processor/command/set_subcmd/substitute_subcmd/eval.rb +2 -2
  81. data/processor/command/set_subcmd/trace.rb +5 -4
  82. data/processor/command/set_subcmd/trace_subcmd/print.rb +4 -3
  83. data/processor/command/shell.rb +5 -3
  84. data/processor/command/show_subcmd/{alias.rb → aliases.rb} +2 -2
  85. data/processor/command/show_subcmd/auto_subcmd/eval.rb +2 -7
  86. data/processor/command/show_subcmd/trace_subcmd/print.rb +3 -3
  87. data/processor/command/show_subcmd/version.rb +24 -0
  88. data/processor/command/source.rb +1 -1
  89. data/processor/command/step.rb +1 -1
  90. data/processor/command/tbreak.rb +1 -1
  91. data/processor/command/unalias.rb +11 -6
  92. data/processor/command/undisplay.rb +14 -10
  93. data/processor/command/up.rb +12 -13
  94. data/processor/command/watchg.rb +1 -1
  95. data/processor/{command/base/cmd.rb → command.rb} +3 -2
  96. data/processor/display.rb +34 -0
  97. data/processor/frame.rb +2 -2
  98. data/processor/help.rb +6 -4
  99. data/processor/hook.rb +95 -96
  100. data/processor/list.rb +146 -0
  101. data/processor/location.rb +26 -0
  102. data/processor/mock.rb +4 -7
  103. data/processor/msg.rb +54 -42
  104. data/processor/running.rb +6 -3
  105. data/processor/subcmd.rb +16 -41
  106. data/processor/validate.rb +6 -9
  107. data/{processor/main.rb → processor.rb} +11 -40
  108. data/sample/rocky-trepan-colors.rb +0 -1
  109. data/test/data/enable.cmd +1 -1
  110. data/test/data/trace.cmd +6 -0
  111. data/test/data/trace.right +39 -0
  112. data/test/example/gcd.rb +0 -1
  113. data/test/functional/test-next.rb +1 -1
  114. data/test/integration/helper.rb +4 -0
  115. data/test/integration/test-trace.rb +18 -0
  116. data/test/unit/cmd-helper.rb +4 -4
  117. data/test/unit/test-app-cmd_parse.rb +1 -1
  118. data/test/unit/test-app-display.rb +22 -0
  119. data/test/unit/test-app-options.rb +14 -10
  120. data/test/unit/test-app-run.rb +7 -1
  121. data/test/unit/test-base-subcmd.rb +1 -1
  122. data/test/unit/test-cmd-kill.rb +11 -4
  123. data/test/unit/test-cmd-parse_list_cmd.rb +1 -1
  124. data/test/unit/{test-base-cmd.rb → test-command.rb} +1 -1
  125. data/test/unit/test-proc-eval.rb +1 -2
  126. data/test/unit/test-proc-frame.rb +1 -2
  127. data/test/unit/test-proc-list.rb +52 -0
  128. data/test/unit/test-proc-load_cmds.rb +1 -1
  129. data/test/unit/test-proc-location.rb +11 -4
  130. data/test/unit/test-proc-main.rb +1 -1
  131. data/test/unit/test-proc-validate.rb +1 -2
  132. data/test/unit/test-subcmd-help.rb +1 -1
  133. data/trepanning.gemspec +1 -1
  134. metadata +26 -12
@@ -1,8 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative 'base/cmd'
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative '../command'
4
4
  require_relative '../breakpoint'
5
5
  require_relative '../../app/breakpoint'
6
+ require_relative '../../app/util'
6
7
 
7
8
  # disable breakpoint command. The difference however is that the
8
9
  # parameter to @proc.en_disable_breakpoint_by_number is different (set
@@ -11,21 +12,20 @@ require_relative '../../app/breakpoint'
11
12
  # NOTE: The enable command subclasses this, so beware when changing!
12
13
  class Trepan::Command::DisableCommand < Trepan::Command
13
14
 
14
- # Silence already initialized constant .. warnings
15
- old_verbose = $VERBOSE
16
- $VERBOSE = nil
17
- NAME = File.basename(__FILE__, '.rb')
18
- HELP = <<-HELP
19
- #{NAME} [display] bpnumber [bpnumber ...]
20
-
21
- Disables the breakpoints given as a space separated list of breakpoint
22
- numbers. See also "info break" to get a list.
23
- HELP
15
+ Trepan::Util.suppress_warnings {
16
+ NAME = File.basename(__FILE__, '.rb')
17
+ HELP = <<-HELP
18
+ #{NAME} [display] NUM1 [NUM2 ...]
24
19
 
25
- CATEGORY = 'breakpoints'
26
- SHORT_HELP = 'Disable some breakpoints'
20
+ Disables the breakpoints or display given as a space separated list of
21
+ numbers.
27
22
 
28
- $VERBOSE = old_verbose
23
+ See also "enable" and "info break".
24
+ HELP
25
+
26
+ CATEGORY = 'breakpoints'
27
+ SHORT_HELP = 'Disable some breakpoints or displays'
28
+ }
29
29
 
30
30
  def initialize(proc)
31
31
  super
@@ -34,12 +34,18 @@ numbers. See also "info break" to get a list.
34
34
 
35
35
  def run(args)
36
36
  if args.size == 1
37
- errmsg('No breakpoint number given.')
37
+ errmsg('No breakpoint or display number given.')
38
38
  return
39
39
  end
40
- # if args[1] == 'display'
41
- # display_enable(args[2:], 0)
42
- # end
40
+ if args[1] == 'display'
41
+ args.shift
42
+ first = args.shift
43
+ args.each do |num_str|
44
+ i = @proc.get_an_int(num_str)
45
+ success = @proc.en_disable_display_by_number(i, @enable_parm) if i
46
+ msg("Display %s #{@name}d." % i) if success
47
+ end
48
+ end
43
49
  first = args.shift
44
50
  args.each do |num_str|
45
51
  i = @proc.get_an_int(num_str)
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
  require_relative '../../app/disassemble'
5
5
  require_relative '../../app/file'
6
6
 
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
 
5
5
  class Trepan::Command::DisplayCommand < Trepan::Command
6
-
6
+
7
7
  unless defined?(HELP)
8
8
  NAME = File.basename(__FILE__, '.rb')
9
9
  HELP = <<-HELP
@@ -22,41 +22,48 @@ case or not.
22
22
  With no argument, evaluate and display all currently requested
23
23
  auto-display expressions. Use "undisplay" to cancel display
24
24
  requests previously made.
25
+
26
+ See also "undisplay", "enable", and "disable".
25
27
  HELP
26
28
 
27
- CATEGORY = 'data'
28
- NEED_STACK = false
29
- SHORT_HELP = 'Display expressions when entering debugger'
30
- end
31
-
32
- def run(args)
29
+ CATEGORY = 'data'
30
+ NEED_STACK = false
31
+ SHORT_HELP = 'Display expressions when entering debugger'
32
+ end
33
33
 
34
- if args.size == 1
35
- # Display anything active
36
- @proc.run_eval_display
37
- else
38
- if %w(/c /x /o /f /s).member?(args[1])
39
- if 2 == args.size
40
- errmsg("Expecting an expression after the format")
41
- return
42
- end
43
- format = args[1]
44
- expr = args[2..-1].join(' ')
45
- else
46
- format = nil
47
- expr = args[1..-1].join(' ')
48
- end
34
+ #def save_command
35
+ # val = settings[subcmd_setting_key] ? 'on' : 'off'
36
+ # ["#{subcmd_prefix_string} #{val}"]
37
+ #end
49
38
 
50
- dp = @proc.displays.add(@proc.frame, expr, format)
51
- unless dp
52
- errmsg('Error evaluating "%s" in the current frame' % expr)
39
+ def run(args)
40
+
41
+ if args.size == 1
42
+ # Display anything active
43
+ @proc.run_eval_display
44
+ else
45
+ if %w(/c /x /o /f /s).member?(args[1])
46
+ if 2 == args.size
47
+ errmsg("Expecting an expression after the format")
53
48
  return
54
49
  end
55
- msg(dp.to_s(@proc.frame))
56
- @proc.cmdloop_prehooks.insert_if_new(5, *@proc.display_hook)
50
+ format = args[1]
51
+ expr = args[2..-1].join(' ')
52
+ else
53
+ format = nil
54
+ expr = args[1..-1].join(' ')
57
55
  end
56
+
57
+ dp = @proc.displays.add(@proc.frame, expr, format)
58
+ unless dp
59
+ errmsg('Error evaluating "%s" in the current frame' % expr)
60
+ return
61
+ end
62
+ msg(dp.to_s(@proc.frame))
63
+ @proc.cmdloop_prehooks.insert_if_new(5, *@proc.display_hook)
58
64
  end
59
65
  end
66
+ end
60
67
 
61
68
  if __FILE__ == $0
62
69
  # Demo it.
@@ -6,10 +6,10 @@ require_relative 'up'
6
6
  # direction (set by DIRECTION) reversed.
7
7
  class Trepan::Command::DownCommand < Trepan::Command::UpCommand
8
8
 
9
- # Silence already initialized constant .. warnings
10
- old_verbose = $VERBOSE
11
- $VERBOSE = nil
12
- HELP = <<-HELP
9
+ Trepan::Util.suppress_warnings {
10
+ old_verbose = $VERBOSE
11
+ $VERBOSE = nil
12
+ HELP = <<-HELP
13
13
  #{NAME} [count]
14
14
 
15
15
  Move the current frame down in the stack trace (to a newer frame). 0
@@ -18,10 +18,10 @@ is the most recent frame. If no count is given, move down 1.
18
18
  See also 'up' and 'frame'.
19
19
  HELP
20
20
 
21
- ALIASES = %w(d)
22
- NAME = File.basename(__FILE__, '.rb')
23
- SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
24
- $VERBOSE = old_verbose
21
+ ALIASES = %w(d)
22
+ NAME = File.basename(__FILE__, '.rb')
23
+ SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
24
+ }
25
25
 
26
26
  def initialize(proc)
27
27
  super
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative './base/cmd'
3
+ require_relative './../command'
4
4
 
5
5
  class Trepan::Command::EditCommand < Trepan::Command
6
6
 
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative 'disable'
4
4
 
5
5
  # enable breakpoint command. Is like disable but the parameter
@@ -7,22 +7,20 @@ require_relative 'disable'
7
7
  # ENABLE_PARM below).
8
8
  class Trepan::Command::EnableCommand < Trepan::Command::DisableCommand
9
9
 
10
- # Silence already initialized constant .. warnings
11
- old_verbose = $VERBOSE
12
- $VERBOSE = nil
13
- NAME = File.basename(__FILE__, '.rb')
14
- HELP = <<-HELP
15
- #{NAME} [display] BPNUM1 [BPNUM2 ...]
10
+ Trepan::Util.suppress_warnings {
11
+ NAME = File.basename(__FILE__, '.rb')
12
+ HELP = <<-HELP
13
+ #{NAME} [display] NUM1 [NUM2 ...]
16
14
 
17
- Enables breakpoints BPNUM1. Breakpoints numbers are given as a space-
15
+ Enables breakpoints or display NUM1... Breakpoints numbers are given as a space-
18
16
  separated list numbers.
19
17
 
20
- See also "info break" to get a list of breakpoints.
18
+ See also "disable" and "info break".
21
19
  HELP
22
20
 
23
- ALIASES = %w(en)
24
- SHORT_HELP = 'Enable some breakpoints'
25
- $VERBOSE = old_verbose
21
+ ALIASES = %w(en)
22
+ SHORT_HELP = 'Enable some breakpoints'
23
+ }
26
24
 
27
25
  def initialize(proc)
28
26
  super
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative './base/cmd'
3
+ require_relative './../command'
4
4
  require_relative '../../app/util'
5
5
 
6
6
  class Trepan::Command::EvalCommand < Trepan::Command
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
- require_relative 'base/cmd'
2
+ require_relative '../command'
3
3
  class Trepan::Command::ExitCommand < Trepan::Command
4
4
 
5
5
  unless defined?(HELP)
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
 
5
5
  class Trepan::Command::FinishCommand < Trepan::Command
6
6
 
@@ -1,5 +1,5 @@
1
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
- require_relative 'base/cmd'
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require_relative '../command'
3
3
  require_relative '../../app/frame'
4
4
 
5
5
  class Trepan::Command::FrameCommand < Trepan::Command
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
- require_relative 'base/cmd'
2
+ require_relative '../command'
3
3
  require_relative '../../app/complete'
4
4
  class Trepan::Command::HelpCommand < Trepan::Command
5
5
  unless defined?(HELP)
@@ -20,8 +20,6 @@ Some commands like 'info', 'set', and 'show' can accept an
20
20
  additional subcommand to give help just about that particular
21
21
  subcommand. For example 'help info line' give help about the
22
22
  info line command.
23
-
24
- See also 'examine' and 'whatis'.
25
23
  HELP
26
24
 
27
25
  ALIASES = %w(?)
@@ -76,10 +74,10 @@ Type "help" followed by a class name for a list of help items in that class.
76
74
  Type "help aliases" for a list of current aliases.
77
75
  Type "help macros" for a list of current macros.
78
76
  Type "help *" for the list of all commands, macros and aliases.
79
- Type "help all" for the list of all commands.
77
+ Type "help all" for a brief description of all commands.
80
78
  Type "help REGEXP" for the list of commands matching /^#{REGEXP}/.
81
79
  Type "help CLASS *" for the list of all commands in class CLASS.
82
- Type "help" followed by command name for full documentation.
80
+ Type "help" followed by a command name for full documentation.
83
81
  '
84
82
  msg(final_msg)
85
83
  end
@@ -102,6 +100,7 @@ Type "help" followed by command name for full documentation.
102
100
  elsif cmd_name =~ /^all$/i
103
101
  CATEGORIES.sort.each do |category|
104
102
  show_category(category[0], [])
103
+ msg('')
105
104
  end
106
105
  elsif CATEGORIES.member?(cmd_name)
107
106
  show_category(args[1], args[2..-1])
@@ -155,12 +154,11 @@ Type "help" followed by command name for full documentation.
155
154
  category == @proc.commands[cmd_name].category
156
155
  end.sort
157
156
  width = settings[:maxwidth]
158
- return columnize_commands(cmds)
157
+ msg columnize_commands(cmds)
158
+ return
159
159
  end
160
160
 
161
- msg('')
162
161
  section "Command class: %s" % category
163
- msg('')
164
162
  @proc.commands.keys.sort.each do |name|
165
163
  next if category != @proc.commands[name].category
166
164
  msg("%-13s -- %s" % [name, @proc.commands[name].short_help])
@@ -23,5 +23,7 @@ end
23
23
 
24
24
  if __FILE__ == $0
25
25
  require_relative '../mock'
26
+ require 'ruby-debug'; Debugger.start; debugger
26
27
  dbgr, cmd = MockDebugger::setup
28
+ cmd.run(['info', 'iv'])
27
29
  end
@@ -3,11 +3,11 @@
3
3
  require 'linecache'
4
4
  require 'columnize'
5
5
  require_relative '../base/subcmd'
6
- require_relative '../../../app/file'
7
- require_relative '../../../app/complete'
6
+ require_relative '../../../app/run'
7
+ require_relative '../../../app/util'
8
8
 
9
9
  class Trepan::Subcommand::InfoFiles < Trepan::Subcommand
10
- unless defined?(HELP)
10
+ Trepan::Util::suppress_warnings {
11
11
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
12
12
  DEFAULT_FILE_ARGS = %w(size mtime sha1)
13
13
 
@@ -46,16 +46,17 @@ Examples:
46
46
  EOH
47
47
  MIN_ABBREV = 'fi'.size # Note we have "info frame"
48
48
  NEED_STACK = false
49
- end
49
+ }
50
50
 
51
51
  # completion %w(all brkpts iseq sha1 size stat)
52
52
 
53
53
  include Trepanning
54
54
 
55
55
  def file_list
56
- (LineCache.class_variable_get('@@file_cache').keys +
56
+ (LineCache.cached_files +
57
57
  LineCache.class_variable_get('@@file2file_remap').keys).uniq
58
58
  end
59
+
59
60
  def complete(prefix)
60
61
  completions = ['.'] + file_list
61
62
  Trepan::Complete.complete_token(completions, prefix)
@@ -84,8 +85,8 @@ EOH
84
85
  return false
85
86
  nil
86
87
  else
87
- frame_file = @proc.frame.file
88
- LineCache::map_file(frame_file) || File.expand_path(frame_file)
88
+ frame_file = @proc.frame.source_container[1]
89
+ LineCache::unmap_file(frame_file) || File.expand_path(frame_file)
89
90
  end
90
91
  else
91
92
  args[2]
@@ -149,10 +150,15 @@ EOH
149
150
 
150
151
  if %w(all brkpts).member?(arg)
151
152
  unless seen[:brkpts]
152
- msg("Possible breakpoint line numbers:")
153
- lines = LineCache.trace_line_numbers(canonic_name)
154
- fmt_lines = columnize_numbers(lines)
155
- msg(fmt_lines)
153
+ syntax_errors = Trepanning::ruby_syntax_errors(canonic_name)
154
+ if syntax_errors
155
+ msg('Not a syntactically-correct Ruby program.')
156
+ else
157
+ msg("Possible breakpoint line numbers:")
158
+ lines = LineCache.trace_line_numbers(canonic_name)
159
+ fmt_lines = columnize_numbers(lines)
160
+ msg(fmt_lines)
161
+ end
156
162
  end
157
163
  processed_arg = seen[:brkpts] = true
158
164
  end
@@ -60,7 +60,6 @@ end
60
60
  if __FILE__ == $0
61
61
  # Demo it.
62
62
  require_relative '../../mock'
63
- dbgr, cmd = MockDebugger::setup('info')
64
63
  cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoFrame, false)
65
64
  cmd.run(cmd.prefix)
66
65
  end
@@ -1,88 +1,21 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
- require 'columnize'
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
4
3
  require_relative '../base/subcmd'
5
- require_relative '../../../app/frame'
6
4
 
7
5
  class Trepan::Subcommand::InfoLocals < Trepan::Subcommand
8
6
  unless defined?(HELP)
9
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
10
- HELP = <<-EOH
11
- #{CMD}
12
- #{CMD} [names]
13
-
14
- Show local variables including parameters of the current stack frame.
15
- Normally for each which show both the name and value. If you just
16
- want a list of names add parameter 'names'.
17
- EOH
18
- SHORT_HELP = 'Show local variables of the current stack frame'
19
- MIN_ARGS = 0
20
- MAX_ARGS = 1
21
- MIN_ABBREV = 'lo'.size
22
- NEED_STACK = true
23
- end
24
-
25
- def get_local_names
26
- iseq = @proc.frame.iseq
27
- 0.upto(iseq.local_size-2).map do
28
- |i|
29
- iseq.local_name(i)
30
- end
31
- end
8
+ HELP = 'Same thing as "info locals"'
9
+ NEED_LOCALS = true
10
+ end
32
11
 
33
12
  def run(args)
34
- if args.size == 3
35
- if 0 == 'names'.index(args[-1].downcase)
36
- if 'CFUNC' == @proc.frame.type
37
- errmsg('info local names not supported for C frames')
38
- else
39
- local_names = get_local_names()
40
- if local_names.empty?
41
- msg "No local variables defined."
42
- else
43
- section "Local variable names:"
44
- width = settings[:maxwidth]
45
- mess = Columnize::columnize(local_names,
46
- @proc.settings[:maxwidth], ' ',
47
- false, true, ' ' * 2).chomp
48
- msg mess
49
- end
50
- end
51
- else
52
- errmsg("unrecognized argument #{args[2]}")
53
- end
54
- elsif args.size == 2
55
- if 'CFUNC' == @proc.frame.type
56
- argc = @proc.frame.argc
57
- if argc > 0
58
- 1.upto(argc).each do |i|
59
- msg "#{i}: #{@proc.frame.sp(argc-i+3).inspect}"
60
- end
61
- else
62
- msg("No parameters in C call; showing other C locals is not supported.")
63
- end
64
- else
65
- local_names = get_local_names
66
- if local_names.empty?
67
- msg "No local variables defined."
68
- else
69
- section "Local variables:"
70
- get_local_names.each_with_index do |var_name, i|
71
- var_value = @proc.safe_rep(@proc.debug_eval_no_errmsg(var_name).inspect)
72
- msg("#{var_name} = #{var_value}")
73
- end
74
- end
75
- end
76
- else
77
- errmsg("Wrong number of arguments #{args.size}")
78
- end
13
+ @proc.commands['info'].run(%w(info variables locals))
79
14
  end
80
15
  end
81
16
 
82
17
  if __FILE__ == $0
83
18
  # Demo it.
84
19
  require_relative '../../mock'
85
- cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoLocals, false)
86
- cmd.run(cmd.prefix)
87
- cmd.run(cmd.prefix + ['name'])
20
+ # ???
88
21
  end
@@ -6,6 +6,7 @@ require 'columnize'
6
6
  require_relative '../base/subcmd'
7
7
  require_relative '../../../app/file'
8
8
  require_relative '../../../app/complete'
9
+ require_relative '../../../app/run'
9
10
 
10
11
  class Trepan::Subcommand::InfoSource < Trepan::Subcommand
11
12
  unless defined?(HELP)
@@ -48,10 +49,15 @@ EOH
48
49
  max_line = LineCache::size(canonic_name)
49
50
  msg 'File has %d lines.' % max_line if max_line
50
51
  msg('SHA1 is %s.' % LineCache::sha1(canonic_name))
51
- msg('Possible breakpoint line numbers:')
52
- lines = LineCache.trace_line_numbers(canonic_name)
53
- fmt_lines = columnize_numbers(lines)
54
- msg(fmt_lines)
52
+ syntax_errors = Trepan::ruby_syntax_errors(canonic_name)
53
+ if syntax_errors
54
+ msg('Not a syntactically-correct Ruby program.')
55
+ else
56
+ msg('Possible breakpoint line numbers:')
57
+ lines = LineCache.trace_line_numbers(canonic_name)
58
+ fmt_lines = columnize_numbers(lines)
59
+ msg(fmt_lines)
60
+ end
55
61
  if SCRIPT_ISEQS__.member?(canonic_name)
56
62
  msg("File contains instruction sequences:")
57
63
  SCRIPT_ISEQS__[canonic_name].each do |iseq|
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative '../base/subsubcmd'
4
+ require_relative '../base/subsubmgr'
5
+
6
+ class Trepan::SubSubcommand::InfoVariables < Trepan::SubSubcommandMgr
7
+ unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{CMD} [class|globals|locals|instance]
11
+
12
+ List various classes of variables for the current stack frame.
13
+
14
+ Examples:
15
+ #{CMD} locals # show local variables
16
+ #{CMD} globals # show global variables
17
+ EOH
18
+ NEED_STACK = true
19
+ SHORT_HELP = 'List variable names/values via the current stack frame'
20
+ end
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ # Demo it.
25
+ require_relative '../../mock'
26
+ dbgr, parent_cmd = MockDebugger::setup('info', false)
27
+ cmd = Trepan::SubSubcommand::InfoVariables.new(dbgr.core.processor,
28
+ parent_cmd)
29
+ cmd.run(cmd.prefix + %w(locals))
30
+ cmd.run(cmd.prefix + %w(globals name))
31
+ %w(loc glo globals i).each do |prefix|
32
+ p [prefix, cmd.complete(prefix)]
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative 'locals'
4
+
5
+ class Trepan::Subcommand::InfoVariablesClass <
6
+ Trepan::Subcommand::InfoVariablesLocals
7
+ Trepan::Util.suppress_warnings {
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{CMD}
11
+ #{CMD} [names]
12
+
13
+ Show class variables of the current stack frame.
14
+ Normally for each which show both the name and value. If you just
15
+ want a list of names add parameter 'names'.
16
+ EOH
17
+ SHORT_HELP = 'Show instance variables of the current stack frame'
18
+ MIN_ARGS = 0
19
+ MAX_ARGS = 1
20
+ NEED_STACK = true
21
+ }
22
+
23
+ def get_names
24
+ @proc.debug_eval_no_errmsg('self.class_variables') || []
25
+ end
26
+
27
+ def run(args)
28
+ run_for_type(args, 'class', @proc.debug_eval('self'))
29
+ end
30
+ end
31
+
32
+ if __FILE__ == $0
33
+ # Demo it.
34
+ require_relative '../../mock'
35
+ cmd =
36
+ MockDebugger::subsub_setup(Trepan::Subcommand::InfoVariables,
37
+ Trepan::Subcommand::InfoVariablesClass)
38
+ cmd.run(cmd.prefix)
39
+ cmd.run(cmd.prefix + ['name'])
40
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative 'locals'
4
+
5
+ class Trepan::Subcommand::InfoVariablesConstant <
6
+ Trepan::Subcommand::InfoVariablesLocals
7
+ Trepan::Util.suppress_warnings {
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{CMD}
11
+ #{CMD} [names]
12
+
13
+ Show class constants of the current stack frame.
14
+ Normally for each which show both the name and value. If you just
15
+ want a list of names add parameter 'names'.
16
+ EOH
17
+ SHORT_HELP = 'Show class constants via the current stack frame'
18
+ MIN_ABBREV = 'co'.size
19
+ MIN_ARGS = 0
20
+ MAX_ARGS = 1
21
+ NEED_STACK = true
22
+ }
23
+
24
+ def get_names
25
+ @proc.debug_eval_no_errmsg('self.class.constants.sort') || []
26
+ end
27
+
28
+ def run(args)
29
+ run_for_type(args, 'constant', @proc.debug_eval('self'))
30
+ end
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ # Demo it.
35
+ require_relative '../../mock'
36
+ cmd =
37
+ MockDebugger::subsub_setup(Trepan::Subcommand::InfoVariables,
38
+ Trepan::Subcommand::InfoVariablesConstant)
39
+ cmd.run(cmd.prefix)
40
+ cmd.run(cmd.prefix + ['name'])
41
+ end