trepanning 0.1.6 → 1.93.32

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 (113) hide show
  1. data/COPYING +57 -0
  2. data/ChangeLog +585 -736
  3. data/NEWS +26 -12
  4. data/README.md +62 -0
  5. data/Rakefile +15 -9
  6. data/app/breakpoint.rb +11 -12
  7. data/app/complete.rb +14 -14
  8. data/app/core.rb +34 -30
  9. data/app/default.rb +8 -7
  10. data/app/markdown.rb +191 -0
  11. data/app/options.rb +104 -99
  12. data/app/run.rb +9 -1
  13. data/app/util.rb +7 -7
  14. data/bin/trepan +7 -7
  15. data/interface.rb +0 -4
  16. data/interface/user.rb +11 -11
  17. data/io/input.rb +13 -13
  18. data/lib/trepanning.rb +30 -29
  19. data/processor.rb +40 -40
  20. data/processor/command.rb +13 -9
  21. data/processor/command/alias.rb +21 -15
  22. data/processor/command/backtrace.rb +27 -19
  23. data/processor/command/break.rb +24 -21
  24. data/processor/command/complete.rb +5 -2
  25. data/processor/command/condition.rb +14 -9
  26. data/processor/command/debug.rb +8 -8
  27. data/processor/command/down.rb +6 -6
  28. data/processor/command/edit.rb +4 -0
  29. data/processor/command/eval.rb +2 -2
  30. data/processor/command/exit.rb +12 -9
  31. data/processor/command/finish.rb +25 -23
  32. data/processor/command/frame.rb +30 -26
  33. data/processor/command/help.rb +203 -185
  34. data/processor/command/help/{command.txt → command.md} +21 -18
  35. data/processor/command/help/examples.md +20 -0
  36. data/processor/command/help/filename.md +46 -0
  37. data/processor/command/help/location.md +34 -0
  38. data/processor/command/help/suffixes.md +19 -0
  39. data/processor/command/info.rb +6 -4
  40. data/processor/command/info_subcmd/breakpoints.rb +13 -13
  41. data/processor/command/info_subcmd/files.rb +35 -31
  42. data/processor/command/info_subcmd/frame.rb +82 -33
  43. data/processor/command/info_subcmd/macro.rb +1 -1
  44. data/processor/command/info_subcmd/program.rb +8 -5
  45. data/processor/command/info_subcmd/registers.rb +15 -13
  46. data/processor/command/kill.rb +23 -17
  47. data/processor/command/list.rb +63 -56
  48. data/processor/command/macro.rb +45 -28
  49. data/processor/command/next.rb +29 -23
  50. data/processor/command/pp.rb +11 -9
  51. data/processor/command/pr.rb +10 -8
  52. data/processor/command/ps.rb +5 -5
  53. data/processor/command/quit.rb +24 -17
  54. data/processor/command/raise.rb +6 -6
  55. data/processor/command/reload.rb +9 -2
  56. data/processor/command/reload_subcmd/command.rb +4 -4
  57. data/processor/command/restart.rb +9 -4
  58. data/processor/command/save.rb +9 -9
  59. data/processor/command/server.rb +18 -17
  60. data/processor/command/set.rb +8 -6
  61. data/processor/command/set_subcmd/confirm.rb +15 -2
  62. data/processor/command/set_subcmd/different.rb +7 -5
  63. data/processor/command/set_subcmd/highlight.rb +14 -3
  64. data/processor/command/set_subcmd/pc.rb +62 -0
  65. data/processor/command/set_subcmd/sp.rb +8 -2
  66. data/processor/command/shell.rb +25 -23
  67. data/processor/command/show.rb +9 -7
  68. data/processor/command/show_subcmd/confirm.rb +12 -1
  69. data/processor/command/show_subcmd/highlight.rb +13 -3
  70. data/processor/command/source.rb +27 -26
  71. data/processor/command/step.rb +52 -43
  72. data/processor/command/tbreak.rb +9 -4
  73. data/processor/command/unalias.rb +9 -7
  74. data/processor/command/undisplay.rb +11 -7
  75. data/processor/command/up.rb +18 -13
  76. data/processor/command/watchg.rb +20 -17
  77. data/processor/complete.rb +120 -0
  78. data/processor/default.rb +47 -43
  79. data/processor/list.rb +23 -6
  80. data/processor/load_cmds.rb +25 -105
  81. data/processor/location.rb +104 -96
  82. data/processor/mock.rb +12 -12
  83. data/processor/msg.rb +61 -52
  84. data/processor/validate.rb +36 -27
  85. data/test/data/fname-with-blank.right +0 -1
  86. data/test/data/trace-mingw.right +28 -0
  87. data/test/data/trace.right +0 -2
  88. data/test/functional/test-raise.rb +3 -0
  89. data/test/integration/helper.rb +16 -16
  90. data/test/integration/test-debugger-stop.rb +8 -2
  91. data/test/integration/test-quit.rb +16 -15
  92. data/test/integration/test-trace.rb +19 -10
  93. data/test/unit/cmd-helper.rb +4 -1
  94. data/test/unit/test-app-complete.rb +3 -1
  95. data/test/unit/test-app-options.rb +7 -1
  96. data/test/unit/test-app-run.rb +9 -1
  97. data/test/unit/test-cmd-alias.rb +1 -1
  98. data/test/unit/test-cmd-edit.rb +2 -0
  99. data/test/unit/test-cmd-help.rb +10 -5
  100. data/test/unit/test-cmd-parse_list_cmd.rb +3 -3
  101. data/test/unit/test-completion.rb +2 -2
  102. data/test/unit/test-proc-default.rb +34 -0
  103. data/trepanning.gemspec +15 -14
  104. metadata +70 -44
  105. data/README.textile +0 -50
  106. data/processor/command/help/examples.txt +0 -16
  107. data/processor/command/help/filename.txt +0 -40
  108. data/processor/command/help/location.txt +0 -37
  109. data/processor/command/help/suffixes.txt +0 -17
  110. data/processor/command/info_subcmd/registers_subcmd/dfp.rb +0 -28
  111. data/processor/command/info_subcmd/registers_subcmd/lfp.rb +0 -47
  112. data/processor/command/nocache.rb +0 -32
  113. data/processor/command/parsetree.rb +0 -56
@@ -6,17 +6,19 @@ class Trepan::Command::SetCommand < Trepan::SubcommandMgr
6
6
  unless defined?(HELP)
7
7
  NAME = File.basename(__FILE__, '.rb')
8
8
  HELP = <<-HELP
9
+ **#{NAME}** [*set-subcommand*]
10
+
9
11
  Modifies parts of the debugger environment.
10
12
 
11
13
  You can give unique prefix of the name of a subcommand to get
12
14
  information about just that subcommand.
13
15
 
14
- Type "#{NAME}" for a list of "#{NAME}" subcommands and what they do.
15
- Type "help #{NAME} *" for just the list of "#{NAME}" subcommands.
16
+ Type `#{NAME}` for a list of *#{NAME}* subcommands and what they do.
17
+ Type `help #{NAME} *` for just the list of `#{NAME}` subcommands.
16
18
 
17
- For compatability with older ruby-debug "#{NAME} auto..." is the
18
- same as "#{NAME} auto ...". For example "#{NAME} autolist" is the same
19
- as "#{NAME} auto list".
19
+ For compatability with older ruby-debug `#{NAME} auto...` is the
20
+ same as `#{NAME} auto ...`. For example `#{NAME} autolist` is the same
21
+ as `#{NAME} auto list`.
20
22
  HELP
21
23
 
22
24
  CATEGORY = 'support'
@@ -25,7 +27,7 @@ as "#{NAME} auto list".
25
27
  end
26
28
 
27
29
  def run(args)
28
- if args.size > 1
30
+ if args.size > 1
29
31
  first = args[1].downcase
30
32
  alen = 'auto'.size
31
33
  args[1..1] = ['auto', first[alen..-1]] if
@@ -1,11 +1,24 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetConfirm < Trepan::SetBoolSubcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
- HELP = "Set whether to confirm potentially dangerous operations."
8
+ HELP = <<-EOH
9
+ **#{PREFIX.join(' ')}**
10
+
11
+ Some commands have drastic effects, so in interactive mode, we confirm
12
+ these operations. Some commands have a ! suffix to disable that
13
+ confirmation for that specific instance. This command enables or
14
+ disables confirmation across *all* potentially dangerous commands,
15
+
16
+ See also:
17
+ ---------
18
+
19
+ `show confirm`
20
+ EOH
21
+ SHORT_HELP = "Set whether to confirm potentially dangerous operations."
9
22
  IN_LIST = true
10
23
  MIN_ABBREV = 'co'.size
11
24
  end
@@ -6,9 +6,9 @@ class Trepan::Subcommand::SetDifferent < Trepan::SetBoolSubcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
8
  HELP = <<-EOH
9
- #{PREFIX.join(' ')} [on|off|nostack]
9
+ **#{PREFIX.join(' ')}** [**on**|**off**|**nostack**]
10
10
 
11
- Set to make sure 'next' or 'step' moves to a new position.
11
+ Set to make sure `next` or `step` moves to a new position.
12
12
 
13
13
  Due to the interpretive, expression-oriented nature of the Ruby
14
14
  Language and implementation, each line often may contain many possible
@@ -20,15 +20,17 @@ Setting 'different' to on will cause each 'step' or 'next' command to
20
20
  stop at a different position.
21
21
 
22
22
  Note though that the notion of different does take into account stack
23
- nesting. So in ARGV.map {|arg| arg.to_i} you get a stop before ARGV as
24
- well as one in the block.
23
+ nesting. So in `ARGV.map {|arg| arg.to_i}` you get a stop before ARGV as
24
+ well as one in the block.
25
25
 
26
26
  If you to ignore stopping at added nesting levels, there are two
27
27
  possibilities. 'set step nostack' will ignore stack nestings levels on
28
28
  a given line. Also you can use 'next', but that also stepping into
29
29
  functions on different lines to also be skipped.
30
30
 
31
- See also 'step', 'next' which have suffixes '+' and '-' which
31
+ See also:
32
+ ---------
33
+ `step`, `next`' which have suffixes '+' and '-' and which
32
34
  override this setting.
33
35
  EOH
34
36
 
@@ -1,11 +1,22 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetHighlight < Trepan::SetBoolSubcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
- HELP = 'Set whether we use terminal highlighting'
8
+ HELP = <<-EOH
9
+ **#{PREFIX.join(' ')}** [**on**|**off**]
10
+
11
+ Set whether we use terminal highlighting.
12
+
13
+ See also:
14
+ ---------
15
+
16
+ `show highlight`
17
+
18
+ EOH
19
+ SHORT_HELP = 'Set whether we use terminal highlighting'
9
20
  IN_LIST = true
10
21
  MIN_ABBREV = 'hi'.size
11
22
  end
@@ -17,7 +28,7 @@ class Trepan::Subcommand::SetHighlight < Trepan::SetBoolSubcommand
17
28
  def run(args)
18
29
  if args.size == 3 && 'reset' == args[2]
19
30
  LineCache::clear_file_format_cache
20
- @proc.settings[:highlight] = :term
31
+ @proc.settings[:highlight] = :term
21
32
  else
22
33
  super
23
34
  @proc.settings[:highlight] = :term if @proc.settings[:highlight]
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2012 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative '../base/subcmd'
4
+
5
+ class Trepan::Subcommand::SetPc < Trepan::Subcommand
6
+ unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
+ HELP = 'set PC INTEGER-EXPRESSION
9
+
10
+ Set VM program-counter register (PC) to INTEGER-EXPRESSION.
11
+
12
+ Warning: this is potentially dangerous.
13
+ '
14
+ SHORT_HELP = 'Set VM program counter (PC)'
15
+ IN_LIST = true
16
+ MIN_ABBREV = 'pc'.size
17
+ end
18
+
19
+ def run(args)
20
+ # FIXME handle c-return
21
+ # unless %w(return c-return).member?(@proc.event)
22
+ if args.size < 3
23
+ errmsg "Too few arguments - the 'pc' command requires a value"
24
+ return
25
+ end
26
+ new_val_str = args[2..-1].join(' ')
27
+ begin
28
+ new_val = @proc.debug_eval(new_val_str)
29
+ rescue StandardError, ScriptError => e
30
+ return
31
+ end
32
+ msg("Old value was: %s" % @proc.frame.pc_offset.inspect)
33
+ @proc.frame.pc_offset = new_val
34
+ msg("New value is: %s" % new_val.inspect)
35
+ end
36
+
37
+ end
38
+
39
+ if __FILE__ == $0
40
+ # Demo it.
41
+ require_relative %w(.. .. mock)
42
+ require_relative %w(.. .. subcmd)
43
+ name = File.basename(__FILE__, '.rb')
44
+
45
+ # FIXME: DRY the below code
46
+ dbgr, cmd = MockDebugger::setup('set')
47
+ subcommand = Debugger::Subcommand::SetPc.new(cmd)
48
+ testcmdMgr = Debugger::Subcmd.new(subcommand)
49
+
50
+ def subcommand.msg(message)
51
+ puts message
52
+ end
53
+ def subcommand.msg_nocr(message)
54
+ print message
55
+ end
56
+ def subcommand.errmsg(message)
57
+ puts message
58
+ end
59
+ subcommand.run(%w(20))
60
+ name = File.basename(__FILE__, '.rb')
61
+ subcommand.summary_help(name)
62
+ end
@@ -1,11 +1,17 @@
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_relative '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetSp < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
- HELP = 'Set a stack pointer register'
8
+ HELP = 'set sp INTEGER-EXPRESSION
9
+
10
+ Set VM stack-pointer register (SP) to INTEGER-EXPRESSION.
11
+
12
+ Warning: this is potentially dangerous.
13
+ '
14
+ SHORT_HELP = 'Set a stack pointer register'
9
15
  IN_LIST = true
10
16
  MIN_ABBREV = 'sp'.size
11
17
  end
@@ -9,31 +9,33 @@ class Trepan::Command::IRBCommand < Trepan::Command
9
9
  require_relative '../../app/irb'
10
10
  NAME = File.basename(__FILE__, '.rb')
11
11
  HELP = <<-HELP
12
- #{NAME} [-d]
12
+ **#{NAME}** [**-d**]
13
13
 
14
14
  Start an Interactive Ruby (IRB) session.
15
15
 
16
- If -d is added you can get access to debugger frame the global variables
17
- $trepan_frame and $trepan_cmdproc.
16
+ If `-d` is added, you can get access to debugger frame the global
17
+ variables `$trepan_frame` and `$trepan_cmdproc`.
18
18
 
19
- #{NAME} is extended with methods 'cont', 'ne', and, 'q', 'step' which
20
- run the corresponding debugger commands 'continue', 'next', 'exit' and 'step'.
19
+ #{NAME} is extended with methods `cont`, `ne`, `q`, and `step` which
20
+ run the corresponding debugger commands: `continue`, `next`, `exit`
21
+ and `step`.
21
22
 
22
23
  To issue a debugger command, inside #{NAME} nested inside a debugger use
23
24
  'dbgr'. For example:
24
25
 
25
- dbgr %w(info program)
26
- dbgr('info', 'program') # Same as above
27
- dbgr 'info program' # Single quoted string also works
26
+ dbgr %w(info program)
27
+ dbgr('info', 'program') # Same as above
28
+ dbgr 'info program' # Single quoted string also works
28
29
 
29
30
  But arguments have to be quoted because #{NAME} will evaluate them:
30
31
 
31
- dbgr info program # wrong!
32
- dbgr info, program # wrong!
33
- dbgr(info, program) # What I say 3 times is wrong!
32
+ dbgr info program # wrong!
33
+ dbgr info, program # wrong!
34
+ dbgr(info, program) # What I say 3 times is wrong!
34
35
 
35
36
  Here then is a loop to query VM stack values:
36
- (-1..1).each {|i| dbgr(\"info reg sp \#{i}\")}
37
+
38
+ (-1..1).each {|i| dbgr(\"info reg sp \#{i}\")}
37
39
  HELP
38
40
 
39
41
  ALIASES = %w(irb)
@@ -44,7 +46,7 @@ Here then is a loop to query VM stack values:
44
46
 
45
47
  # This method runs the command
46
48
  def run(args)
47
- add_debugging =
49
+ add_debugging =
48
50
  if args.size > 1
49
51
  '-d' == args[1]
50
52
  else
@@ -60,7 +62,7 @@ Here then is a loop to query VM stack values:
60
62
  throw :IRB_EXIT, :cont if $trepan_in_irb
61
63
  end
62
64
 
63
- $trepan = @proc.dbgr
65
+ $trepan = @proc.dbgr
64
66
  $trepan_cmdproc = @proc
65
67
  if add_debugging
66
68
  $trepan_frame = @proc.frame
@@ -73,32 +75,32 @@ Here then is a loop to query VM stack values:
73
75
  :RC => true}
74
76
 
75
77
  # ?? Should we set GNU readline to what we have,
76
- # or let IRB make its own determination?
78
+ # or let IRB make its own determination?
77
79
 
78
- # Save the Readline history and set the Readline completion function
79
- # to be IRB's function
80
- if Trepan::GNU_readline?
80
+ # Save the Readline history and set the Readline completion function
81
+ # to be IRB's function
82
+ if Trepan::GNU_readline?
81
83
  @proc.intf.save_history if @proc.intf.respond_to?(:save_history)
82
84
  require 'irb/completion'
83
85
  Readline.completion_proc = IRB::InputCompletor::CompletionProc
84
86
  end
85
87
 
86
- # And just when you thought, we'd never get around to
88
+ # And just when you thought, we'd never get around to
87
89
  # actually running irb...
88
90
  cont = IRB.start_session(@proc.frame.binding, @proc, conf)
89
91
  trap('SIGINT', save_trap) # Restore our old interrupt function.
90
92
 
91
- # Restore the debuggers' Readline history and the Readline completion
93
+ # Restore the debuggers' Readline history and the Readline completion
92
94
  # function
93
95
  if Trepan::GNU_readline? && @proc.dbgr.completion_proc
94
96
  @proc.intf.read_history if @proc.intf.respond_to?(:read_history)
95
- Readline.completion_proc = @proc.dbgr.completion_proc
97
+ Readline.completion_proc = @proc.dbgr.completion_proc
96
98
  end
97
99
 
98
100
  # Respect any backtrace limit set in irb.
99
101
  back_trace_limit = IRB.CurrentContext.back_trace_limit
100
102
  if settings[:maxstack] != back_trace_limit
101
- msg("\nSetting debugger's BACK_TRACE_LIMIT (%d) to match irb's last setting (%d)" %
103
+ msg("\nSetting debugger's BACK_TRACE_LIMIT (%d) to match irb's last setting (%d)" %
102
104
  [settings[:maxstack], back_trace_limit])
103
105
  settings[:maxstack]= IRB.CurrentContext.back_trace_limit
104
106
  end
@@ -107,7 +109,7 @@ Here then is a loop to query VM stack values:
107
109
  when :continue
108
110
  @proc.continue
109
111
  when :finish
110
- @proc.finish
112
+ @proc.finish
111
113
  when :next
112
114
  @proc.next # (1, {})
113
115
  when :quit
@@ -1,17 +1,19 @@
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 'base/submgr'
4
4
 
5
5
  class Trepan::Command::ShowCommand < Trepan::SubcommandMgr
6
6
  unless defined?(HELP)
7
7
  NAME = File.basename(__FILE__, '.rb')
8
8
  HELP = <<-HELP
9
- 'Generic command for showing things about the debugger. You can
10
- give unique prefix of the name of a subcommand to get information
11
- about just that subcommand.
9
+ **#{NAME}** [*show-subcommand*]
12
10
 
13
- Type "#{NAME}" for a list of "#{NAME}" subcommands and what they do.
14
- Type "help #{NAME} *" for just a list of "#{NAME}" subcommands.
11
+ Generic command for showing things about the debugger. You can
12
+ give unique prefix of the name of a subcommand to get
13
+ information about just that subcommand.
14
+
15
+ Type `#{NAME}` for a list of *#{NAME}* subcommands and what they do.
16
+ Type `help #{NAME} *` for just the list of `#{NAME}` subcommands.
15
17
  HELP
16
18
 
17
19
  CATEGORY = 'status'
@@ -20,7 +22,7 @@ Type "help #{NAME} *" for just a list of "#{NAME}" subcommands.
20
22
  end
21
23
 
22
24
  def run(args)
23
- if args.size > 1
25
+ if args.size > 1
24
26
  first = args[1].downcase
25
27
  alen = 'auto'.size
26
28
  args[1..1] = ['auto', first[alen..-1]] if
@@ -5,7 +5,18 @@ require_relative '../base/subcmd'
5
5
  class Trepan::Subcommand::ShowConfirm < Trepan::ShowBoolSubcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
- HELP = "Show confirm potentially dangerous operations setting"
8
+ HELP = <<-EOH
9
+ **#{PREFIX.join(' ')}**
10
+
11
+ Show confirm potentially dangerous operations setting.
12
+
13
+ See also:
14
+ ---------
15
+
16
+ `set confirm`
17
+ EOH
18
+
19
+ SHORT_HELP = "Show confirm potentially dangerous operations setting"
9
20
  MIN_ABBREV = 'co'.size
10
21
  end
11
22
  end
@@ -1,17 +1,27 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::Subcommand::ShowHighlight < Trepan::ShowBoolSubcommand
7
7
  unless defined?(HELP)
8
8
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
- HELP = 'Show whether we use terminal highlighting'
9
+ HELP = <<-EOH
10
+ **#{PREFIX.join(' ')}**
11
+
12
+ Show whether we use terminal highlighting.
13
+
14
+ See also:
15
+ ---------
16
+
17
+ `set highlight`
18
+ EOH
19
+ SHORT_HELP = 'Show whether we use terminal highlighting'
10
20
  MIN_ABBREV = 'high'.size
11
21
  end
12
22
 
13
23
  def run(args)
14
- val = :term == @proc.settings[:highlight]
24
+ val = :term == @proc.settings[:highlight]
15
25
  onoff = show_onoff(val)
16
26
  msg("%s is %s." % [@name, onoff])
17
27
  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, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'optparse'
4
4
 
5
5
  # Our local modules
@@ -12,27 +12,28 @@ class Trepan::Command::SourceCommand < Trepan::Command
12
12
  unless defined?(HELP)
13
13
  NAME = File.basename(__FILE__, '.rb')
14
14
  HELP = <<-HELP
15
- #{NAME} [options] FILE
15
+ **#{NAME}** [*options*] *file*
16
+
17
+ options:
16
18
 
17
- options:
18
19
  -q | --quiet | --no-quiet
19
20
  -c | --continue | --no-continue
20
21
  -Y | --yes | -N | --no
21
22
  -v | --verbose | --no-verbose
22
23
 
23
- Read debugger commands from a file named FILE. Optional -v switch
24
- causes each command in FILE to be echoed as it is executed. Option -Y
25
- sets the default value in any confirmation command to be 'yes' and -N
26
- sets the default value to 'no'.
24
+ Read debugger commands from *file*. The optional `-v switch
25
+ causes each command in *file* to be echoed as it is executed. Option `-Y`
26
+ sets the default value in any confirmation command to be "yes" and `-N`
27
+ sets the default value to "no".
27
28
 
28
- Option -q will turn off any debugger output that normally occurs in the
29
+ Option `-q` will turn off any debugger output that normally occurs in the
29
30
  running of the program.
30
31
 
31
32
  Note that the command startup file #{Trepan::CMD_INITFILE_BASE} is read automatically
32
33
  via a #{NAME} command the debugger is started.
33
34
 
34
35
  An error in any command terminates execution of the command file
35
- unless option -c or --continue is given.
36
+ unless option `-c` or `--continue` is given.
36
37
  HELP
37
38
  CATEGORY = 'support'
38
39
  MIN_ARGS = 1 # Need at least this many
@@ -52,35 +53,35 @@ unless option -c or --continue is given.
52
53
  files = Readline::FILENAME_COMPLETION_PROC.call(prefix) || []
53
54
  opts = %w(-c --continue --no-continue -N --no -y --yes
54
55
  --verbose --no-verbose) + files
55
- Trepan::Complete.complete_token(opts, prefix)
56
+ Trepan::Complete.complete_token(opts, prefix)
56
57
  end
57
-
58
+
58
59
  def parse_options(options, args) # :nodoc
59
60
  seen_yes_no = false
60
61
  parser = OptionParser.new do |opts|
61
- opts.on('-c', '--[no-]continue',
62
+ opts.on('-c', '--[no-]continue',
62
63
  'Continue in the face of errors') do
63
- |v|
64
+ |v|
64
65
  options[:abort_on_error] = !v
65
66
  end
66
- opts.on('-v',
67
+ opts.on('-v',
67
68
  '--[no-]verbose', 'echo each command as it is executed') do
68
- |v|
69
+ |v|
69
70
  options[:verbose] = v
70
71
  end
71
72
  opts.on('-N', '--no', "Use 'no' in any confirmation prompts") do
72
- |v|
73
+ |v|
73
74
  if seen_yes_no
74
75
  msg('Yes/No option already seen. This option (no) ignored.')
75
76
  end
76
77
  options[:confirm_val] = false
77
78
  end
78
79
  opts.on('-q', '--[no-]quiet', 'Silence debugger output') do
79
- |v|
80
+ |v|
80
81
  options[:quiet] = v
81
82
  end
82
83
  opts.on('-Y', '--yes', "Use 'yes' in any confirmation prompts") do
83
- |v|
84
+ |v|
84
85
  if seen_yes_no
85
86
  msg("Yes/No option already seen. This option, --yes, ignored.")
86
87
  end
@@ -96,37 +97,37 @@ unless option -c or --continue is given.
96
97
  options = parse_options(DEFAULT_OPTIONS.dup, args[1..-2])
97
98
  intf = @proc.interfaces
98
99
  output = options[:quiet] ? Trepan::OutputNull.new(nil) : intf[-1].output
99
-
100
+
100
101
  filename = args[-1]
101
-
102
+
102
103
  expanded_file = File.expand_path(filename)
103
104
  unless File.readable?(expanded_file)
104
- errmsg("Debugger command file '%s' (%s) is not a readable file" %
105
+ errmsg("Debugger command file '%s' (%s) is not a readable file" %
105
106
  [filename, expanded_file])
106
107
  return false
107
108
  end
108
-
109
+
109
110
  # Push a new debugger interface.
110
111
  script_intf = Trepan::ScriptInterface.new(expanded_file, output, options)
111
112
  intf << script_intf
112
113
  return false
113
114
  end
114
115
  end
115
-
116
+
116
117
  # Demo it
117
118
  if __FILE__ == $0
118
119
  require_relative '../mock'
119
120
  dbgr, cmd = MockDebugger::setup
120
- %w(--quiet -q --no-quiet --continue --no-continue -c -v --verbose
121
+ %w(--quiet -q --no-quiet --continue --no-continue -c -v --verbose
121
122
  --no-verbose).each do |opt|
122
123
  puts "parsing #{opt}"
123
- options =
124
+ options =
124
125
  cmd.parse_options(Trepan::Command::SourceCommand::DEFAULT_OPTIONS.dup,
125
126
  opt)
126
127
  p options
127
128
  end
128
129
 
129
- if ARGV.size >= 1
130
+ if ARGV.size >= 1
130
131
  puts "running... #{cmd.name} #{ARGV}"
131
132
  cmd.run([cmd.name, *ARGV])
132
133
  end