trepanning 1.93.35 → 2.15.33

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. checksums.yaml +7 -0
  2. data/ChangeLog +491 -55
  3. data/LICENSE +1 -1
  4. data/NEWS +18 -14
  5. data/README.md +5 -22
  6. data/Rakefile +22 -1
  7. data/app/breakpoint.rb +5 -3
  8. data/app/core.rb +147 -179
  9. data/app/default.rb +47 -46
  10. data/app/file.rb +6 -7
  11. data/app/frame.rb +183 -176
  12. data/app/markdown.rb +2 -9
  13. data/app/options.rb +1 -1
  14. data/app/run.rb +71 -37
  15. data/interface/script.rb +8 -8
  16. data/io.rb +19 -20
  17. data/lib/trepanning.rb +292 -297
  18. data/processor.rb +332 -344
  19. data/processor/breakpoint.rb +98 -96
  20. data/processor/command/base/submgr.rb +9 -9
  21. data/processor/command/break.rb +40 -38
  22. data/processor/command/continue.rb +15 -10
  23. data/processor/command/debug.rb +6 -25
  24. data/processor/command/delete.rb +21 -12
  25. data/processor/command/directory.rb +15 -13
  26. data/processor/command/disable.rb +12 -9
  27. data/processor/command/disassemble.rb +80 -74
  28. data/processor/command/display.rb +15 -12
  29. data/processor/command/down.rb +8 -3
  30. data/processor/command/edit.rb +37 -23
  31. data/processor/command/enable.rb +11 -8
  32. data/processor/command/eval.rb +24 -22
  33. data/processor/command/finish.rb +50 -48
  34. data/processor/command/help.rb +1 -1
  35. data/processor/command/info_subcmd/breakpoints.rb +7 -7
  36. data/processor/command/info_subcmd/files.rb +195 -196
  37. data/processor/command/info_subcmd/frame.rb +7 -4
  38. data/processor/command/info_subcmd/locals.rb +29 -12
  39. data/processor/command/info_subcmd/program.rb +48 -39
  40. data/processor/command/info_subcmd/registers_subcmd/ep.rb +46 -0
  41. data/processor/command/info_subcmd/registers_subcmd/helper.rb +32 -35
  42. data/processor/command/info_subcmd/registers_subcmd/sp.rb +29 -23
  43. data/processor/command/info_subcmd/return.rb +28 -10
  44. data/processor/command/info_subcmd/variables_subcmd/class.rb +3 -3
  45. data/processor/command/info_subcmd/variables_subcmd/constants.rb +77 -0
  46. data/processor/command/info_subcmd/variables_subcmd/globals.rb +7 -7
  47. data/processor/command/info_subcmd/variables_subcmd/instance.rb +68 -22
  48. data/processor/command/info_subcmd/variables_subcmd/locals.rb +148 -67
  49. data/processor/command/list.rb +14 -8
  50. data/processor/command/macro.rb +1 -1
  51. data/processor/command/next.rb +1 -0
  52. data/processor/command/set_subcmd/auto.rb +3 -3
  53. data/processor/command/set_subcmd/different.rb +30 -29
  54. data/processor/command/set_subcmd/events.rb +74 -48
  55. data/processor/command/set_subcmd/max_subcmd/list.rb +12 -5
  56. data/processor/command/set_subcmd/max_subcmd/width.rb +28 -19
  57. data/processor/command/set_subcmd/register.rb +37 -0
  58. data/processor/command/set_subcmd/register_subcmd/pc.rb +67 -0
  59. data/processor/command/set_subcmd/register_subcmd/sp.rb +75 -0
  60. data/processor/command/set_subcmd/reload.rb +12 -10
  61. data/processor/command/set_subcmd/return.rb +68 -44
  62. data/processor/command/shell.rb +3 -2
  63. data/processor/command/show_subcmd/different.rb +17 -14
  64. data/processor/command/show_subcmd/events.rb +25 -25
  65. data/processor/default.rb +1 -1
  66. data/processor/eval.rb +14 -15
  67. data/processor/frame.rb +43 -36
  68. data/processor/help.rb +5 -5
  69. data/processor/hook.rb +26 -29
  70. data/processor/location.rb +54 -51
  71. data/processor/mock.rb +4 -3
  72. data/processor/running.rb +113 -103
  73. data/processor/validate.rb +401 -373
  74. data/test/data/debug.cmd +8 -0
  75. data/test/data/debug.right +13 -0
  76. data/test/data/debugger-stop.right +6 -4
  77. data/test/data/fname-with-blank.cmd +1 -1
  78. data/test/data/fname-with-blank.right +5 -0
  79. data/test/data/pc.cmd +8 -0
  80. data/test/data/pc.right +10 -0
  81. data/test/data/quit.right +3 -1
  82. data/test/data/trace.cmd +2 -2
  83. data/test/data/trace.right +41 -20
  84. data/test/example/assign.rb +6 -0
  85. data/test/functional/fn_helper.rb +11 -17
  86. data/test/functional/test-break-long.rb +15 -16
  87. data/test/functional/test-break.rb +6 -8
  88. data/test/functional/test-condition.rb +8 -10
  89. data/test/functional/test-debugger-call-bug.rb +21 -22
  90. data/test/functional/test-delete.rb +57 -59
  91. data/test/functional/test-eval.rb +101 -103
  92. data/test/functional/test-finish.rb +24 -33
  93. data/test/functional/test-immediate-step-bug.rb +6 -10
  94. data/test/functional/test-next.rb +64 -65
  95. data/test/functional/test-raise.rb +63 -64
  96. data/test/functional/test-recursive-bt.rb +81 -76
  97. data/test/functional/test-remap.rb +6 -7
  98. data/test/functional/test-return.rb +44 -38
  99. data/test/functional/test-step.rb +55 -53
  100. data/test/functional/test-stepbug.rb +6 -9
  101. data/test/functional/test-watchg.rb +40 -39
  102. data/test/integration/test-debug.rb +12 -0
  103. data/test/integration/test-debugger-stop.rb +7 -7
  104. data/test/integration/test-pc.rb +24 -0
  105. data/test/integration/test-trace.rb +1 -1
  106. data/test/unit/cmd-helper.rb +0 -1
  107. data/test/unit/test-app-brkpt.rb +21 -21
  108. data/test/unit/test-app-brkptmgr.rb +7 -8
  109. data/test/unit/test-app-display.rb +3 -4
  110. data/test/unit/test-app-frame.rb +4 -5
  111. data/test/unit/test-base-subsubcmd.rb +2 -2
  112. data/test/unit/test-cmd-break.rb +6 -6
  113. data/test/unit/test-cmd-endisable.rb +7 -6
  114. data/test/unit/test-cmd-parse_list_cmd.rb +24 -24
  115. data/test/unit/test-io-tcpserver.rb +39 -35
  116. data/test/unit/test-proc-default.rb +23 -22
  117. data/test/unit/test-proc-eval.rb +1 -2
  118. data/test/unit/test-proc-frame.rb +8 -9
  119. data/test/unit/test-proc-list.rb +1 -1
  120. data/test/unit/test-proc-location.rb +2 -2
  121. data/test/unit/test-proc-main.rb +10 -10
  122. data/test/unit/test-proc-validate.rb +11 -13
  123. data/test/unit/test-subcmd-help.rb +1 -2
  124. data/trepanning.gemspec +8 -13
  125. metadata +44 -95
  126. data/COPYING +0 -57
  127. data/data/custom_require.rb +0 -44
  128. data/data/perldb.bindings +0 -17
  129. data/data/prelude.rb +0 -38
  130. data/processor/command/info_subcmd/variables_subcmd/constant.rb +0 -41
  131. data/processor/command/raise.rb +0 -48
  132. data/processor/command/set_subcmd/pc.rb +0 -62
  133. data/processor/command/set_subcmd/sp.rb +0 -67
  134. data/processor/eventbuf.rb +0 -133
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2012, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative '../command'
4
4
  require_relative '../breakpoint'
5
5
  require_relative '../../app/breakpoint'
@@ -8,26 +8,35 @@ class Trepan::Command::DeleteCommand < Trepan::Command
8
8
  unless defined?(HELP)
9
9
  NAME = File.basename(__FILE__, '.rb')
10
10
  HELP = <<-HELP
11
- #{NAME} [bpnumber [bpnumber...]]
11
+ **#{NAME}** [*bpnumber* [*bpnumber*...]]
12
12
 
13
13
  Delete some breakpoints.
14
14
 
15
15
  Arguments are breakpoint numbers with spaces in between. To delete
16
- all breakpoints, give no argument. those breakpoints. Without
17
- argument, clear all breaks (but first ask confirmation).
18
-
19
- See also the "clear" command which clears breakpoints by line/file
20
- number.
16
+ all breakpoints, give no argument. When deleting all breakpoints
17
+ confirmation is asked for, unless the command is suffixed with "!".
18
+
19
+ Examples:
20
+
21
+ delete 1 # delete breakpoint 1
22
+ delete # delete all breakpoints
23
+ delete! # Same as above, no questions asked.
24
+
25
+ See also:
26
+ ---------
27
+
28
+ The `clear` command clears breakpoints by line/file number; `set confirm`
29
+ sets whether we confirm potentially destructive operations like this.
21
30
  HELP
22
31
 
23
32
  CATEGORY = 'breakpoints'
24
33
  SHORT_HELP = 'Delete some breakpoints'
25
- ALIASES = %w(d)
34
+ ALIASES = %w(d d! delete!)
26
35
  end
27
-
36
+
28
37
  def run(args)
29
38
  if args.size == 1
30
- if confirm('Delete all breakpoints?', false)
39
+ if args[0][-1] == '!' or confirm('Delete all breakpoints?', false)
31
40
  @proc.brkpts.reset
32
41
  return
33
42
  end
@@ -36,14 +45,14 @@ number.
36
45
  args.each do |num_str|
37
46
  opts = {:msg_on_error => '%s must be a number' % num_str}
38
47
  i = @proc.get_an_int(num_str, opts)
39
- if i
48
+ if i
40
49
  success = @proc.delete_breakpoint_by_number(num_str.to_i, false) if i
41
50
  msg('Deleted breakpoint %d.' % i) if success
42
51
  end
43
52
  end
44
53
  end
45
54
  end
46
-
55
+
47
56
  if __FILE__ == $0
48
57
  require_relative '../mock'
49
58
  dbgr, cmd = MockDebugger::setup
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
1
+ # Copyright (C) 2010, 2015 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require_relative '../command'
3
3
  class Trepan::Command::DirectoryCommand < Trepan::Command
4
4
 
@@ -8,25 +8,27 @@ class Trepan::Command::DirectoryCommand < Trepan::Command
8
8
  MAX_ARGS = 1 # Need at most this many
9
9
  NAME = File.basename(__FILE__, '.rb')
10
10
  HELP = <<-HELP
11
- #{NAME} [DIR]
11
+ **#{NAME}** [*dir*]
12
12
 
13
- Add directory DIR to beginning of search path for source files.
14
- DIR can also be $cwd for the current working directory, or $cdir for the
15
- directory in which the debugged file start.
16
- With no argument, reset the search path to $cdir:$cwd, the default.
13
+ Add directory *dir* to beginning of search path for source files.
14
+ *dir* can also be `$cwd` for the current working directory, or `$cdir`
15
+ for the directory in which the debugged file start. With no argument,
16
+ reset the search path to `$cdir:$cwd`, the default.
17
17
 
18
- This command may be useful if for some reason the debugger can't find
19
- source files because directories have been moved.
18
+ This command may be useful if for some reason the debugger can't find
19
+ source files because directories have been moved.
20
20
 
21
21
  Examples:
22
- #{NAME} ~/.rvm/src/ruby-head # Adds an rvm-like directory to path
23
- #{NAME} # reset to $cdir:$cwd
22
+ ---------
23
+
24
+ #{NAME} ~/.rvm/src/ruby-head # Adds an rvm-like directory to path
25
+ #{NAME} # reset to $cdir:$cwd
24
26
  HELP
25
27
 
26
- SHORT_HELP =
27
- 'Add directory DIR to beginning of search path for source files'
28
+ SHORT_HELP =
29
+ 'Add directory *dir* to beginning of search path for source files'
28
30
  end
29
-
31
+
30
32
  # This method runs the command
31
33
  def run(args) # :nodoc
32
34
  if args.size > 1
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2011, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative '../command'
4
4
  require_relative '../breakpoint'
5
5
  require_relative '../../app/breakpoint'
@@ -9,29 +9,32 @@ require_relative '../../app/util'
9
9
  # parameter to @proc.en_disable_breakpoint_by_number is different (set
10
10
  # as ENABLE_PARM below).
11
11
  #
12
- # NOTE: The enable command subclasses this, so beware when changing!
12
+ # NOTE: The enable command subclasses this, so beware when changing!
13
13
  class Trepan::Command::DisableCommand < Trepan::Command
14
14
 
15
15
  Trepan::Util.suppress_warnings {
16
16
  NAME = File.basename(__FILE__, '.rb')
17
17
  HELP = <<-HELP
18
- #{NAME} [display] NUM1 [NUM2 ...]
18
+ **#{NAME}** [*display*] *num1* [*num2* ...]
19
19
 
20
20
  Disables the breakpoints or display given as a space separated list of
21
- numbers.
21
+ numbers.
22
22
 
23
- See also "enable" and "info break".
23
+ See also:
24
+ ---------
25
+
26
+ `enable` and `info break`.
24
27
  HELP
25
-
28
+
26
29
  CATEGORY = 'breakpoints'
27
30
  SHORT_HELP = 'Disable some breakpoints or displays'
28
31
  }
29
32
 
30
33
  def initialize(proc)
31
34
  super
32
- @enable_parm = false # true if enable
35
+ @enable_parm = false # true if enable
33
36
  end
34
-
37
+
35
38
  def run(args)
36
39
  if args.size == 1
37
40
  errmsg('No breakpoint or display number given.')
@@ -54,7 +57,7 @@ See also "enable" and "info break".
54
57
  end
55
58
  end
56
59
  end
57
-
60
+
58
61
  if __FILE__ == $0
59
62
  require_relative '../mock'
60
63
  dbgr, cmd = MockDebugger::setup
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2011, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative '../command'
4
4
  require_relative '../../app/disassemble'
5
5
  require_relative '../../app/file'
@@ -8,12 +8,12 @@ class Trepan::Command::DisassembleCommand < Trepan::Command
8
8
  include Trepan::Disassemble
9
9
  include Trepanning
10
10
 
11
- unless defined?(HELP)
12
- NAME = File.basename(__FILE__, '.rb')
13
- ALIASES = %w(disasm) # Note we have disable
14
- CATEGORY = 'data'
15
- HELP = <<-HELP
16
- #{NAME} [thing] [full]
11
+ unless defined?(HELP)
12
+ NAME = File.basename(__FILE__, '.rb')
13
+ ALIASES = %w(disasm) # Note we have disable
14
+ CATEGORY = 'data'
15
+ HELP = <<-HELP
16
+ **#{NAME}** [*thing*] [**full**]
17
17
 
18
18
  With no argument, disassemble the current frame. With a method,
19
19
  disassemble that method. '.' can be used to indicate the instruction
@@ -25,83 +25,89 @@ instruction sequence might have. If 'full' is given, all instruction
25
25
  sequences are include.
26
26
 
27
27
  Examples:
28
- #{NAME}
29
- #{NAME} . # Same as above
30
- #{NAME} . full # At least the instruction sequence above but maybe more
31
- #{NAME} require_relative # disassemble method 'require_relative'
28
+ ---------
29
+
30
+ #{NAME}
31
+ #{NAME} . # Same as above
32
+ #{NAME} . full # At least the instruction sequence above but maybe more
33
+ #{NAME} require_relative # disassemble method 'require_relative'
34
+
35
+ See also:
36
+ ---------
37
+
38
+ `list`
32
39
  HELP
33
40
 
34
- NEED_STACK = true
35
- SHORT_HELP = 'Disassemble Ruby VM instructions'
36
- end
41
+ NEED_STACK = true
42
+ SHORT_HELP = 'Disassemble Ruby VM instructions'
43
+ end
37
44
 
38
- completion %w(. full)
45
+ completion %w(. full)
39
46
 
40
- # FIXME: put in processor/data.rb?
47
+ # FIXME: put in processor/data.rb?
41
48
 
42
- def marked_disassemble(iseq_param, include_children)
43
- iseqs = include_children ? iseq_param.child_iseqs : [iseq_param]
44
- iseqs.each do |iseq|
45
- ary = mark_disassembly(iseq.disasm_nochildren,
46
- @proc.frame.iseq.equal?(iseq),
47
- @proc.frame.pc_offset,
48
- iseq.brkpts, settings[:maxwidth],
49
- settings[:highlight])
50
- msg ary
49
+ def marked_disassemble(iseq_param, include_children)
50
+ iseqs = include_children ? iseq_param.child_iseqs : [iseq_param]
51
+ iseqs.each do |iseq|
52
+ ary = mark_disassembly(iseq.disasm_nochildren,
53
+ @proc.frame.iseq.equal?(iseq),
54
+ @proc.frame.pc_offset,
55
+ iseq.brkpts, settings[:maxwidth],
56
+ settings[:highlight])
57
+ msg ary
58
+ end
51
59
  end
52
- end
53
-
54
- # Run command.
55
- def run(args)
56
-
57
- obj = nil
58
- include_children =
59
- if args.size > 1 && args[-1] == 'full'
60
- args.pop
61
- true
62
- else
63
- false
64
- end
65
- if args.size == 1 || '.' == args[1]
66
- # Form is: "disassemble" or "disassemble ."
67
- if @proc.frame.type == 'CFUNC'
68
- errmsg "Can't handle C functions yet."
69
- return
70
- elsif @proc.frame.iseq
71
- marked_disassemble(@proc.frame.iseq, include_children)
72
- return
73
- end
74
- else
75
- if !(matches = find_iseqs(ISEQS__, args[1])).empty?
76
- # FIXME: do something if there is more than one
77
- iseq = matches[0]
78
- else
79
- iseq = @proc.object_iseq(args[1])
80
- end
81
- marked_disassemble(iseq, include_children) if iseq
82
- return
60
+
61
+ # Run command.
62
+ def run(args)
63
+
64
+ obj = nil
65
+ include_children =
66
+ if args.size > 1 && args[-1] == 'full'
67
+ args.pop
68
+ true
69
+ else
70
+ false
71
+ end
72
+ if args.size == 1 || '.' == args[1]
73
+ # Form is: "disassemble" or "disassemble ."
74
+ if @proc.frame.type == 'CFUNC'
75
+ errmsg "Can't handle C functions yet."
76
+ return
77
+ elsif @proc.frame.iseq
78
+ marked_disassemble(@proc.frame.iseq, include_children)
79
+ return
80
+ end
81
+ else
82
+ if !(matches = find_iseqs(ISEQS__, args[1])).empty?
83
+ # FIXME: do something if there is more than one
84
+ iseq = matches[0]
85
+ else
86
+ iseq = @proc.object_iseq(args[1])
87
+ end
88
+ marked_disassemble(iseq, include_children) if iseq
89
+ return
90
+ end
91
+ errmsg("Sorry can't handle right now.")
83
92
  end
84
- errmsg("Sorry can't handle right now.")
85
- end
86
93
  end
87
94
 
88
95
  if __FILE__ == $0
89
- # Demo it.
90
- require 'thread_frame'
96
+ # Demo it.
91
97
 
92
- require_relative '../mock'
93
- dbgr, cmd = MockDebugger::setup
94
- def small_fn(cmd, name)
98
+ require_relative '../mock'
99
+ dbgr, cmd = MockDebugger::setup
100
+ def small_fn(cmd, name)
101
+ cmd.proc.frame_setup(RubyVM::Frame::current)
102
+ cmd.run [name]
103
+ end
104
+ small_fn(cmd, cmd.name)
105
+ p = Proc.new do
106
+ |x,y| x + y
107
+ end
95
108
  cmd.proc.frame_setup(RubyVM::Frame::current)
96
- cmd.run [name]
97
- end
98
- small_fn(cmd, cmd.name)
99
- p = Proc.new do
100
- |x,y| x + y
101
- end
102
- cmd.proc.frame_setup(RubyVM::Frame::current)
103
- cmd.run([cmd.name, 'p'])
104
- puts cmd.complete('f')
105
- require 'irb'
106
- cmd.run([cmd.name, 'IRB.start'])
109
+ cmd.run([cmd.name, 'p'])
110
+ puts cmd.complete('f')
111
+ require 'irb'
112
+ cmd.run([cmd.name, 'IRB.start'])
107
113
  end
@@ -1,17 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
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
10
- #{name} [format] EXP
11
-
12
- Print value of expression EXP each time the program stops. FMT may be
13
- used before EXP and may be one of 'c' for char, 'x' for hex, 'o' for
14
- octal, 'f' for float or 's' for string.
10
+ **#{name}** [*format*] *expression*
11
+
12
+ Print value of expression *expression* each time the program stops;
13
+ *format* may be used to specify how to pring and may be one of 'c' for
14
+ char, 'x' for hex, 'o' for octal, 'f' for float or 's' for string.
15
15
 
16
16
  For now, display expressions are only evaluated when in the same
17
17
  instruction sequence as the frame that was in effect when the display
@@ -20,12 +20,15 @@ more flexibility in the future to specify whether this should be the
20
20
  case or not.
21
21
 
22
22
  With no argument, evaluate and display all currently requested
23
- auto-display expressions. Use "undisplay" to cancel display
23
+ auto-display expressions. Use `undisplay` to cancel display
24
24
  requests previously made.
25
25
 
26
- See also "undisplay", "enable", and "disable".
26
+ See also:
27
+ ---------
28
+
29
+ `undisplay`, `enable`, and `disable`.
27
30
  HELP
28
-
31
+
29
32
  CATEGORY = 'data'
30
33
  NEED_STACK = false
31
34
  SHORT_HELP = 'Display expressions when entering debugger'
@@ -37,7 +40,7 @@ end
37
40
  #end
38
41
 
39
42
  def run(args)
40
-
43
+
41
44
  if args.size == 1
42
45
  # Display anything active
43
46
  @proc.run_eval_display
@@ -53,7 +56,7 @@ def run(args)
53
56
  format = nil
54
57
  expr = args[1..-1].join(' ')
55
58
  end
56
-
59
+
57
60
  dp = @proc.displays.add(@proc.frame, expr, format)
58
61
  unless dp
59
62
  errmsg('Error evaluating "%s" in the current frame' % expr)
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative 'up'
4
4
 
5
5
  # Debugger "down" command. Is the same as the "up" command with the
@@ -10,12 +10,17 @@ class Trepan::Command::DownCommand < Trepan::Command::UpCommand
10
10
  old_verbose = $VERBOSE
11
11
  $VERBOSE = nil
12
12
  HELP = <<-HELP
13
- #{NAME} [count]
13
+ **#{NAME}** [*count*]
14
14
 
15
15
  Move the current frame down in the stack trace (to a newer frame). 0
16
16
  is the most-recent frame. If no count is given, move down 1.
17
17
 
18
- See also 'up' and 'frame'.
18
+ A negative number moves in the opposite direction.
19
+
20
+ See also:
21
+ ---------
22
+
23
+ `up` and `frame`.
19
24
  HELP
20
25
 
21
26
  NAME = File.basename(__FILE__, '.rb')
@@ -1,27 +1,31 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2011, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative './../command'
4
4
 
5
5
  class Trepan::Command::EditCommand < Trepan::Command
6
6
 
7
- old_verbose = $VERBOSE
7
+ old_verbose = $VERBOSE
8
8
  $VERBOSE = nil
9
9
  NAME = File.basename(__FILE__, '.rb')
10
10
  HELP = <<-HELP
11
- #{NAME} [[FILE] [LINE]]
11
+ **#{NAME}** [[*file*] [*line*]]
12
12
 
13
13
  With no argument, edits file containing most recent line listed.
14
- The value of the environment variable EDITOR is used for the
15
- editor to run. If no EDITOR environment variable is set /bin/ex
16
- is used. The editor should support line and file positioning via
17
- editor-name +line file-name
14
+ The value of the environment variable `EDITOR` is used for the
15
+ editor to run. If no `EDITOR` environment variable is set `/bin/ex`
16
+ is used. The editor should support line and file positioning via:
17
+
18
+ editor-name +line file-name
19
+
18
20
  (Most editors do.)
19
21
 
20
22
  Examples:
21
- #{NAME} # Edit current location
22
- #{NAME} 7 # Edit current file at line 7
23
- #{NAME} test.rb # Edit test.rb, line 1
24
- #{NAME} test.rb 10 # Edit test.rb line 10
23
+ ---------
24
+
25
+ #{NAME} # Edit current location
26
+ #{NAME} 7 # Edit current file at line 7
27
+ #{NAME} test.rb # Edit test.rb, line 1
28
+ #{NAME} test.rb 10 # Edit test.rb line 10
25
29
  HELP
26
30
 
27
31
  ALIASES = %w(e)
@@ -29,30 +33,40 @@ Examples:
29
33
  NEED_STACK = false
30
34
  SHORT_HELP = 'Invoke an editor on some source code'
31
35
  MAX_ARGS = 2
32
- $VERBOSE = old_verbose
36
+ $VERBOSE = old_verbose
33
37
 
34
38
  # FIXME: redo with locations and kparse.
35
39
  def run(args)
36
40
  case args.size
37
41
  when 1
38
- file = @proc.frame.source_container[1]
39
- line = @proc.frame.source_location[0]
42
+ if @proc.frame
43
+ file = @proc.frame.source_container[1]
44
+ line = @proc.frame.source_location[0]
45
+ else
46
+ errmsg("No Ruby program loaded.")
47
+ return
48
+ end
40
49
  when 2
41
- line = Integer(args[1]) rescue nil
42
- if line
43
- file = @proc.frame.source_container[1]
44
- else
50
+ line = Integer(args[1]) rescue nil
51
+ if line
52
+ if @proc.frame
53
+ file = @proc.frame.source_container[1]
54
+ else
55
+ errmsg("No Ruby program loaded.")
56
+ return
57
+ end
58
+ else
45
59
  file = args[1]
46
60
  line = 1
47
61
  end
48
62
  when 3
49
63
  line, file = args[2], args[1]
50
64
  else
51
- errmsg "edit needs at most 2 args."
65
+ errmsg "edit needs at most 2 args."
52
66
  end
53
67
  editor = ENV['EDITOR'] || '/bin/ex'
54
68
  unless File.executable?(editor)
55
- errmsg "Editor #{editor} is not executable. Trying anyway..."
69
+ errmsg "Editor #{editor} is not executable. Trying anyway..."
56
70
  end
57
71
 
58
72
  if File.readable?(file)
@@ -71,7 +85,7 @@ if __FILE__ == $0
71
85
  require_relative '../mock'
72
86
  dbgr, cmd = MockDebugger::setup
73
87
  ENV['EDITOR'] = 'echo FAKE-EDITOR'
74
- cmd.run [cmd.name]
75
- cmd.run [cmd.name, '7']
76
- cmd.run [cmd.name, __FILE__, '10']
88
+ cmd.run [cmd.name]
89
+ cmd.run [cmd.name, '7']
90
+ cmd.run [cmd.name, __FILE__, '10']
77
91
  end