trepanning 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/ChangeLog +237 -0
  2. data/NEWS +8 -0
  3. data/Rakefile +3 -2
  4. data/app/breakpoint.rb +8 -8
  5. data/app/brkptmgr.rb +86 -85
  6. data/app/client.rb +60 -0
  7. data/app/core.rb-consider +198 -0
  8. data/app/default.rb +17 -7
  9. data/app/disassemble.rb +12 -2
  10. data/app/options.rb +51 -20
  11. data/app/yarv.rb +183 -0
  12. data/bin/trepan +15 -9
  13. data/data/custom_require.rb +44 -0
  14. data/data/irbrc +41 -0
  15. data/data/prelude.rb +38 -0
  16. data/interface/base_intf.rb +10 -4
  17. data/interface/client.rb +79 -0
  18. data/interface/comcodes.rb +18 -0
  19. data/interface/server.rb +142 -0
  20. data/io/base_io.rb +57 -3
  21. data/io/tcpclient.rb +122 -0
  22. data/io/tcpfns.rb +31 -0
  23. data/io/tcpserver.rb +137 -0
  24. data/lib/trepanning.rb +57 -28
  25. data/processor/command/base/cmd.rb +10 -6
  26. data/processor/command/base/subcmd.rb +13 -1
  27. data/processor/command/directory.rb +15 -8
  28. data/processor/command/disassemble.rb +3 -2
  29. data/processor/command/help.rb +71 -19
  30. data/processor/command/info_subcmd/args.rb +2 -3
  31. data/processor/command/info_subcmd/breakpoints.rb +2 -3
  32. data/processor/command/info_subcmd/file.rb +2 -3
  33. data/processor/command/info_subcmd/frame.rb +2 -3
  34. data/processor/command/info_subcmd/iseq.rb +4 -5
  35. data/processor/command/info_subcmd/locals.rb +2 -3
  36. data/processor/command/info_subcmd/program.rb +2 -3
  37. data/processor/command/info_subcmd/registers.rb +2 -3
  38. data/processor/command/info_subcmd/return.rb +2 -3
  39. data/processor/command/info_subcmd/thread.rb +2 -3
  40. data/processor/command/list.rb +10 -6
  41. data/processor/command/reload.rb +1 -1
  42. data/processor/command/reload_subcmd/command.rb +29 -16
  43. data/processor/command/server.rb +70 -0
  44. data/processor/command/set_subcmd/auto.rb +2 -3
  45. data/processor/command/set_subcmd/basename.rb +2 -3
  46. data/processor/command/set_subcmd/debug.rb +2 -3
  47. data/processor/command/set_subcmd/different.rb +2 -3
  48. data/processor/command/set_subcmd/events.rb +2 -3
  49. data/processor/command/set_subcmd/hidelevel.rb +6 -7
  50. data/processor/command/set_subcmd/highlight.rb +32 -0
  51. data/processor/command/set_subcmd/max.rb +2 -3
  52. data/processor/command/set_subcmd/return.rb +2 -3
  53. data/processor/command/set_subcmd/sp.rb +2 -3
  54. data/processor/command/set_subcmd/substitute.rb +2 -3
  55. data/processor/command/set_subcmd/timer.rb +2 -3
  56. data/processor/command/set_subcmd/trace.rb +3 -4
  57. data/processor/command/show_subcmd/alias.rb +3 -3
  58. data/processor/command/show_subcmd/args.rb +2 -3
  59. data/processor/command/show_subcmd/auto.rb +1 -2
  60. data/processor/command/show_subcmd/basename.rb +2 -3
  61. data/processor/command/show_subcmd/debug.rb +1 -2
  62. data/processor/command/show_subcmd/different.rb +2 -1
  63. data/processor/command/show_subcmd/events.rb +2 -2
  64. data/processor/command/show_subcmd/hidelevel.rb +2 -3
  65. data/processor/command/show_subcmd/highlight.rb +23 -0
  66. data/processor/command/show_subcmd/macro.rb +2 -1
  67. data/processor/command/show_subcmd/max.rb +2 -3
  68. data/processor/command/show_subcmd/trace.rb +2 -3
  69. data/processor/command/source.rb +78 -28
  70. data/processor/default.rb +3 -2
  71. data/processor/load_cmds.rb +39 -19
  72. data/processor/location.rb +11 -7
  73. data/processor/main.rb +31 -15
  74. data/processor/mock.rb +22 -7
  75. data/processor/msg.rb +24 -8
  76. data/test/data/fname-with-blank.right +3 -0
  77. data/test/data/quit.right +2 -0
  78. data/test/functional/test-break-long.rb +87 -0
  79. data/test/functional/tmp/b3.rb +5 -0
  80. data/test/functional/tmp/immediate-bug1.rb +9 -0
  81. data/test/integration/helper.rb +14 -11
  82. data/test/integration/test-fname-with-blank.rb +5 -1
  83. data/test/integration/test-quit.rb +6 -2
  84. data/test/unit/cmd-helper.rb +9 -4
  85. data/test/unit/mock-helper.rb +9 -0
  86. data/test/unit/test-app-brkpt.rb +4 -4
  87. data/test/unit/test-app-brkptmgr.rb +2 -2
  88. data/test/unit/test-app-file.rb +0 -1
  89. data/test/unit/test-app-options.rb +26 -5
  90. data/test/unit/test-base-subcmd.rb +0 -1
  91. data/test/unit/test-cmd-alias.rb +0 -1
  92. data/test/unit/test-cmd-break.rb +0 -4
  93. data/test/unit/test-cmd-endisable.rb +1 -3
  94. data/test/unit/test-cmd-help.rb +0 -1
  95. data/test/unit/test-cmd-kill.rb +4 -5
  96. data/test/unit/test-cmd-quit.rb +4 -7
  97. data/test/unit/test-cmd-source.rb +33 -0
  98. data/test/unit/test-cmd-step.rb +0 -2
  99. data/test/unit/test-io-tcp.rb +32 -0
  100. data/test/unit/test-io-tcpclient.rb +53 -0
  101. data/test/unit/test-io-tcpserver.rb +49 -0
  102. data/test/unit/test-proc-main.rb +2 -2
  103. metadata +195 -175
  104. data/processor/command/stepi.rb +0 -63
  105. data/test/functional/tmp/b1.rb +0 -5
  106. data/test/functional/tmp/s1.rb +0 -9
  107. data/test/functional/tmp/t2.rb +0 -6
  108. data/test/integration/try-test-enable.rb +0 -11
@@ -1,11 +1,12 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetHidelevel < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "
8
- set hidelevel [NUM]
9
+ #{PREFIX.join(' ')} [NUM]
9
10
 
10
11
  Hide this many stack frames from the bottom (or least-recent) frame.
11
12
 
@@ -21,19 +22,17 @@ would be otherwise be, empty then we show all entries, or take NUM to
21
22
  be 0.
22
23
 
23
24
  Examples:
24
- set hidelevel # Use the default value and hide 'uninteresting' ones
25
- set hidelevel 0 # Show all stack entries, even from loading the program
25
+ #{PREFIX.join(' ')} # Use the default value and hide 'uninteresting' ones
26
+ #{PREFIX.join(' ')} 0 # Show all stack entries, even from loading the program
26
27
  # or initial stack entries the debugger created to
27
28
  # debug the program.
28
- set hidelevel 1 # Hide only the bottom-most or least-recent stack frame.
29
+ #{PREFIX.join(' ')} 1 # Hide only the bottom-most or least-recent stack frame.
29
30
 
30
31
  See also 'backtrace' and 'show hidelevel'.
31
32
  ."
32
33
 
33
34
  IN_LIST = true
34
35
  MIN_ABBREV = 'hide'.size
35
- NAME = File.basename(__FILE__, '.rb')
36
- PREFIX = %W(set #{NAME})
37
36
  SHORT_HELP = "Set the number of bottom frames to hide."
38
37
  end
39
38
 
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative '../base/subcmd'
4
+
5
+ class Trepan::Subcommand::SetHighlight < Trepan::SetBoolSubcommand
6
+ unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
+ HELP = 'Set whether we use highlight highlighting'
9
+ IN_LIST = true
10
+ MIN_ABBREV = 'ba'.size
11
+ end
12
+ def run(args)
13
+ if args.size == 3 && 'reset' == args[2]
14
+ LineCache::clear_file_format_cache
15
+ else
16
+ super
17
+ @proc.settings[:highlight] = :term if @proc.settings[:highlight]
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ # Demo it.
25
+ $0 = __FILE__ + 'notagain' # So we don't run this again
26
+ require_relative '../../mock'
27
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::SetHighlight, false)
28
+ cmd.run(cmd.prefix + ['off'])
29
+ cmd.run(cmd.prefix + ['ofn'])
30
+ cmd.run(cmd.prefix)
31
+ puts cmd.save_command
32
+ end
@@ -1,13 +1,12 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::SetMax < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Set maximum length for things which may have unbounded size'
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %w(set max)
11
10
  end
12
11
 
13
12
  # def run(args)
@@ -1,15 +1,14 @@
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 '../base/subcmd'
4
4
  require_relative '../../../app/frame'
5
5
 
6
6
  class Trepan::Subcommand::SetReturn < Trepan::Subcommand
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Set the value that will be returned in the current method'
9
10
  IN_LIST = true
10
11
  MIN_ABBREV = 'ret'.size
11
- NAME = File.basename(__FILE__, '.rb')
12
- PREFIX = %w(set return)
13
12
  end
14
13
 
15
14
  include Trepan::Frame
@@ -1,14 +1,13 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetSp < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = 'Set a stack pointer register'
8
9
  IN_LIST = true
9
10
  MIN_ABBREV = 'sp'.size
10
- NAME = File.basename(__FILE__, '.rb')
11
- PREFIX = %w(set sp)
12
11
  end
13
12
 
14
13
  def run(args)
@@ -1,13 +1,12 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::SetSubstitute < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Set instruction sequence-to-filename mapping'
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %w(set substitute)
11
10
  end
12
11
  end
13
12
 
@@ -1,9 +1,10 @@
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 '../base/subsubcmd'
4
4
 
5
5
  class Trepan::Subcommand::SetTimer < Trepan::SetBoolSubcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "set timer [on|off|0|1]
8
9
 
9
10
  Tracks and shows elapsed time between debugger events.
@@ -26,8 +27,6 @@ See also: 'set events', 'set trace buffer', 'step', and 'break'.
26
27
  "
27
28
 
28
29
  MIN_ABBREV = 'ti'.size
29
- NAME = File.basename(__FILE__, '.rb')
30
- PREFIX = %w(set timer)
31
30
  SHORT_HELP = "Set to show elapsed time between debugger events"
32
31
  end
33
32
 
@@ -1,22 +1,21 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::SetTrace < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = "Set tracing of various sorts.
9
10
 
10
11
  The types of tracing include global variables, events from the trace
11
12
  buffer, or printing those events.
12
13
 
13
- See 'help set trace *' or a list of subcommands or 'help set trace
14
+ See 'help #{PREFIX.join(' ')} *' for a list of subcommands or 'help set trace
14
15
  <name>' for help on a particular trace subcommand."
15
16
 
16
17
  IN_LIST = true
17
18
  MIN_ABBREV = 'tr'.size
18
- NAME = File.basename(__FILE__, '.rb')
19
- PREFIX = %w(set trace)
20
19
  SHORT_HELP = 'Set tracing of various sorts.'
21
20
  end
22
21
 
@@ -1,16 +1,16 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowAlias < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "show alias [NAME1 NAME2 ...]
8
9
 
9
10
  If aliases names are given, show their definition. If left blank, show
10
11
  all alias names"
11
12
 
12
13
  MIN_ABBREV = 'al'.size
13
- NAME = File.basename(__FILE__, '.rb')
14
14
  SHORT_HELP = "Show defined aliases"
15
15
  end
16
16
 
@@ -26,7 +26,7 @@ all alias names"
26
26
  elsif @proc.aliases.empty?
27
27
  msg "No aliases defined."
28
28
  else
29
- msg "List of aliases names currently defined:"
29
+ section "List of aliases names currently defined:"
30
30
  msg columnize_commands(@proc.aliases.keys.sort)
31
31
  end
32
32
  end
@@ -1,13 +1,12 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowArgs < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = 'Show argument list to give program when it is restarted'
8
9
  MIN_ABBREV = 'ar'.size
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %W(show #{NAME})
11
10
  end
12
11
 
13
12
  def run(args)
@@ -5,9 +5,8 @@ require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::ShowAuto < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Show settings which some sort of "automatic" default behavior'
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %W(show #{NAME})
11
10
  MIN_ABBREV = 'au'.size
12
11
  end
13
12
  end
@@ -1,13 +1,12 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowBasename < Trepan::ShowBoolSubcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "Show only file basename in showing file names"
8
9
  MIN_ABBREV = 'ba'.size
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %W(show #{NAME})
11
10
  end
12
11
 
13
12
  end
@@ -5,9 +5,8 @@ require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::ShowDebug < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Show internal debugger settings.'
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %W(show #{NAME})
11
10
  MIN_ABBREV = 'de'.size
12
11
  end
13
12
  end
@@ -1,9 +1,10 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowDifferent < Trepan::ShowBoolSubcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "Show status of 'set different'"
8
9
  MIN_ABBREV = 'dif'.size
9
10
  end
@@ -1,12 +1,12 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowEvents < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = 'Show trace events we may stop on.'
8
9
  MIN_ABBREV = 'ev'.size
9
- NAME = File.basename(__FILE__, '.rb')
10
10
  end
11
11
 
12
12
  # FIXME: this really should be a subcommand of "set trace"
@@ -1,13 +1,12 @@
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 '../base/subsubcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowHidelevel < Trepan::ShowIntSubcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = 'Show the number of stack levels to hide'
8
9
  MIN_ABBREV = 'hide'.size
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %w(show hidelevel)
11
10
  end
12
11
  def run(args)
13
12
  if @proc.settings[:hidelevel]
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require_relative '../base/subsubcmd'
4
+ require_relative '../base/subsubmgr'
5
+
6
+ class Trepan::Subcommand::ShowHighlight < Trepan::ShowBoolSubcommand
7
+ unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = 'Show whether we use highlight highlighting'
10
+ end
11
+
12
+ def run(args)
13
+ val = :term == @proc.settings[:highlight]
14
+ onoff = show_onoff(val)
15
+ msg("%s is %s." % [@name, onoff])
16
+ end
17
+ end
18
+
19
+ if __FILE__ == $0
20
+ require_relative '../../mock'
21
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::ShowHighlight, false)
22
+ cmd.run(cmd.prefix)
23
+ end
@@ -1,9 +1,10 @@
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 '../base/subcmd'
4
4
 
5
5
  class Trepan::Subcommand::ShowMacro < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
7
8
  HELP = "Show defined macros"
8
9
  MIN_ABBREV = 'ma'.size
9
10
  end
@@ -1,13 +1,12 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::ShowMax < Trepan::SubSubcommandMgr
7
7
  unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
9
  HELP = 'Show "maximum length" settings'
9
- NAME = File.basename(__FILE__, '.rb')
10
- PREFIX = %W(show #{NAME})
11
10
  MIN_ABBREV = NAME.size
12
11
  end
13
12
 
@@ -1,14 +1,13 @@
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 '../base/subsubcmd'
4
4
  require_relative '../base/subsubmgr'
5
5
 
6
6
  class Trepan::SubSubcommand::ShowTrace < Trepan::SubSubcommandMgr
7
7
 
8
8
  unless defined?(HELP)
9
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
10
  HELP = "Show event tracing printing"
10
- NAME = File.basename(__FILE__, '.rb')
11
- PREFIX = %W(show #{NAME})
12
11
  MIN_ABBREV = 'tr'.size
13
12
  SHORT_HELP = HELP
14
13
  end
@@ -1,54 +1,95 @@
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
+ require 'optparse'
3
4
 
4
5
  # Our local modules
5
6
  require_relative 'base/cmd'
6
7
  require_relative '../../interface/script'
7
- # Mfile = import_relative('file', '...lib', 'pydbgr')
8
+ require_relative '../../io/null_output'
9
+ require_relative '../../app/default'
8
10
 
9
11
  class Trepan::Command::SourceCommand < Trepan::Command
12
+ include Trepanning
10
13
  unless defined?(HELP)
11
- NAME = File.basename(__FILE__, '.rb')
14
+ NAME = File.basename(__FILE__, '.rb')
12
15
  HELP = <<-HELP
13
- #{NAME} [-v][-Y|-N][-c][q] FILE
16
+ #{NAME} [options] FILE
17
+
18
+ options:
19
+ -q | --quiet | --no-quiet
20
+ -c | --continue | --no-continue
21
+ -Y | --yes | -N | --no
22
+ -v | --verbose | --no-verbose
14
23
 
15
24
  Read debugger commands from a file named FILE. Optional -v switch
16
- (before the filename) causes each command in FILE to be echoed as it
17
- is executed. Option -Y sets the default value in any confirmation
18
- command to be 'yes' and -N sets the default value to 'no'.
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'.
28
+
29
+ Option -q will turn off any debugger output that normally occurs in the
30
+ running of the program.
19
31
 
20
- Note that the command startup file '.pydbgrc' is read automatically
32
+ Note that the command startup file #{Trepan::CMD_INITFILE_BASE} is read automatically
21
33
  via a #{NAME} command the debugger is started.
22
34
 
23
35
  An error in any command terminates execution of the command file
24
- unless option -c is given.
36
+ unless option -c or --continue is given.
25
37
  HELP
26
38
  CATEGORY = 'support'
27
39
  MIN_ARGS = 1 # Need at least this many
28
40
  MAX_ARGS = nil
29
41
  SHORT_HELP = 'Read and run debugger commands from a file'
42
+
43
+ DEFAULT_OPTIONS = {
44
+ :abort_on_error => false,
45
+ :confirm_val => false,
46
+ :quiet => false,
47
+ :verbose => false
48
+ }
49
+
30
50
  end
31
51
 
32
- def run(args)
33
- verbose = false
34
- parms = args[1..-1]
35
- opts = {}
36
- intf = @proc.dbgr.intf
37
- output = intf[-1].output
38
- parms.each do |arg|
39
- case arg
40
- when '-v'
41
- opts[:verbose] = true
42
- when '-Y'
43
- opts[:confirm_val] = true
44
- when '-N'
45
- opts[:confirm_val] = false
46
- when '-c'
47
- opts[:abort_on_error] = false
48
- when '-q'
49
- output = Trepan::OutputNull.new(nil)
52
+ def parse_options(options, args) # :nodoc
53
+ seen_yes_no = false
54
+ parser = OptionParser.new do |opts|
55
+ opts.on("-c", "--[no-]continue",
56
+ "Continue in the face of errors") do
57
+ |v|
58
+ options[:abort_on_error] = !v
59
+ end
60
+ opts.on("-v",
61
+ "--[no-]verbose", "echo each command as it is executed") do
62
+ |v|
63
+ options[:verbose] = v
64
+ end
65
+ opts.on("-N", "--no", "Use 'no' in any confirmation prompts") do
66
+ |v|
67
+ if seen_yes_no
68
+ msg("Yes/No option already seen. This option (no) ignored.")
69
+ end
70
+ options[:confirm_val] = false
71
+ end
72
+ opts.on("-q", "--[no-]quiet", "Silence debugger output") do
73
+ |v|
74
+ options[:quiet] = v
75
+ end
76
+ opts.on("-Y", "--yes", "Use 'yes' in any confirmation prompts") do
77
+ |v|
78
+ if seen_yes_no
79
+ msg("Yes/No option already seen. This option, --yes, ignored.")
80
+ end
81
+ options[:confirm_val] = true
82
+ seen_yes_no = true
50
83
  end
51
84
  end
85
+ parser.parse(args)
86
+ return options
87
+ end
88
+
89
+ def run(args)
90
+ options = parse_options(DEFAULT_OPTIONS.dup, args[1..-2])
91
+ intf = @proc.dbgr.intf
92
+ output = options[:quiet] ? Trepan::OutputNull.new(nil) : intf[-1].output
52
93
 
53
94
  filename = args[-1]
54
95
 
@@ -59,7 +100,7 @@ unless option -c is given.
59
100
  end
60
101
 
61
102
  # Push a new debugger interface.
62
- script_intf = Trepan::ScriptInterface.new(expanded_file, output, opts)
103
+ script_intf = Trepan::ScriptInterface.new(expanded_file, output, options)
63
104
  intf << script_intf
64
105
  return false
65
106
  end
@@ -69,6 +110,15 @@ end
69
110
  if __FILE__ == $0
70
111
  require_relative '../mock'
71
112
  dbgr, cmd = MockDebugger::setup
113
+ %w(--quiet -q --no-quiet --continue --no-continue -c -v --verbose
114
+ --no-verbose).each do |opt|
115
+ puts "parsing #{opt}"
116
+ options =
117
+ cmd.parse_options(Trepan::Command::SourceCommand::DEFAULT_OPTIONS.dup,
118
+ opt)
119
+ p options
120
+ end
121
+
72
122
  if ARGV.size >= 1
73
123
  puts "running... #{cmd.name} #{ARGV}"
74
124
  cmd.run([cmd.name, *ARGV])