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, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative 'disable'
4
4
 
5
5
  # enable breakpoint command. Is like disable but the parameter
@@ -10,12 +10,15 @@ class Trepan::Command::EnableCommand < Trepan::Command::DisableCommand
10
10
  Trepan::Util.suppress_warnings {
11
11
  NAME = File.basename(__FILE__, '.rb')
12
12
  HELP = <<-HELP
13
- #{NAME} [display] NUM1 [NUM2 ...]
14
-
15
- Enables breakpoints or display NUM1... Breakpoints numbers are given as a space-
16
- separated list numbers.
13
+ **#{NAME}** [**display**] *num1* [*num2* ...]
17
14
 
18
- See also "disable" and "info break".
15
+ Enables breakpoints or display *num1*... Breakpoints numbers are given
16
+ as a space-separated list numbers.
17
+
18
+ See also:
19
+ ---------
20
+
21
+ `disable` and `info break`.
19
22
  HELP
20
23
 
21
24
  ALIASES = %w(en)
@@ -24,11 +27,11 @@ See also "disable" and "info break".
24
27
 
25
28
  def initialize(proc)
26
29
  super
27
- @enable_parm = true # true if enable
30
+ @enable_parm = true # true if enable
28
31
  end
29
32
 
30
33
  end
31
-
34
+
32
35
  if __FILE__ == $0
33
36
  require_relative '../mock'
34
37
  dbgr, cmd = MockDebugger::setup
@@ -1,15 +1,15 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2011, 2012 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2011-2012, 2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require_relative './../command'
4
4
  require_relative '../../app/util'
5
5
 
6
6
  class Trepan::Command::EvalCommand < Trepan::Command
7
7
 
8
- old_verbose = $VERBOSE
8
+ old_verbose = $VERBOSE
9
9
  $VERBOSE = nil
10
10
  NAME = File.basename(__FILE__, '.rb')
11
11
  HELP = <<-HELP
12
- #{NAME} [STRING]
12
+ **#{NAME}** [*string*]
13
13
 
14
14
  Run code in the context of the current frame.
15
15
 
@@ -18,44 +18,46 @@ may be used again easily. The name of the global variable is printed
18
18
  next to the inspect output of the value.
19
19
 
20
20
  If no string is given, we run the string from the current source code
21
- about to be run. If the command ends ? (via an alias) and no string is
22
- given, the following translations occur:
21
+ about to be run. If the command ends with a "?" (via an alias) and no
22
+ string is given, the following translations occur:
23
23
 
24
- {if|elsif|unless} expr [then] => expr
25
- {until|while} expr [do] => expr
26
- return expr => expr
27
- case expr => expr
28
- def fn(params) => [params]
29
- var = expr => expr
24
+ {if|elsif|unless} expr [then] => expr
25
+ {until|while} expr [do] => expr
26
+ return expr => expr
27
+ case expr => expr
28
+ def fn(params) => [params]
29
+ var = expr => expr
30
30
 
31
31
  The above is done via regular expression. No fancy parsing is done, say,
32
32
  to look to see if expr is split across a line or whether var an assigment
33
33
  might have multiple variables on the left-hand side.
34
34
 
35
35
  Examples:
36
+ ---------
36
37
 
37
- #{NAME} 1+2 # 3
38
- #{NAME} @v
39
- #{NAME} # Run current source-code line
40
- #{NAME}? # but strips off leading 'if', 'while', ..
41
- # from command
38
+ #{NAME} 1+2 # 3
39
+ #{NAME} @v
40
+ #{NAME} # Run current source-code line
41
+ #{NAME}? # but strips off leading 'if', 'while', ..a
42
+ # from command
42
43
 
43
- See also 'set autoeval'. The command helps one predict future execution.
44
- See 'set buffer trace' for showing what may have already been run.
44
+ See also:
45
+ ---------
46
+ `set autoeval`.
45
47
  HELP
46
48
 
47
49
  ALIASES = %w(eval? ev? ev)
48
50
  CATEGORY = 'data'
49
51
  NEED_STACK = true
50
52
  SHORT_HELP = 'Run code in the current context'
51
- $VERBOSE = old_verbose
53
+ $VERBOSE = old_verbose
52
54
 
53
55
  def complete(prefix)
54
- if prefix.empty?
56
+ if prefix.empty?
55
57
  if @proc.leading_str.start_with?('eval?')
56
58
  Trepan::Util.extract_expression @proc.current_source_text
57
59
  else
58
- @proc.current_source_text
60
+ @proc.current_source_text
59
61
  end
60
62
  else
61
63
  prefix
@@ -65,7 +67,7 @@ See 'set buffer trace' for showing what may have already been run.
65
67
  def run(args)
66
68
  if args.size == 1
67
69
  text = @proc.current_source_text
68
- if '?' == args[0][-1..-1]
70
+ if '?' == args[0][-1..-1]
69
71
  text = Trepan::Util::extract_expression(text)
70
72
  msg "eval: #{text}"
71
73
  end
@@ -33,58 +33,60 @@ program. In general, `#{NAME}`, `step` and `next` may slow a program
33
33
  down while `break` will have less overhead.
34
34
 
35
35
  HELP
36
- ALIASES = %w(fin)
37
- CATEGORY = 'running'
38
- # execution_set = ['Running']
36
+ ALIASES = %w(fin)
37
+ CATEGORY = 'running'
38
+ # execution_set = ['Running']
39
39
 
40
- # Need at most this many.
41
- MAX_ARGS = 1
42
- NEED_STACK = true
43
- SHORT_HELP = 'Step to end of current method (step out)'
44
- end
45
-
46
- # This method runs the command
47
- def run(args)
48
- opts = {}
49
- if args.size == 1
50
- # Form is: "finish" which means "finish 1"
51
- level_count = 0
52
- else
53
- count_str = args[1]
54
- opts = {
55
- :msg_on_error =>
56
- "The '#{NAME}' command argument must eval to an integer. Got: %s" %
57
- count_str,
58
- :min_value => 1
59
- }
60
- count = @proc.get_an_int(count_str, opts)
61
- return unless count
62
- # step 1 is core.level_count = 0 or "stop next event"
63
- level_count = count - 1
40
+ # Need at most this many.
41
+ MAX_ARGS = 1
42
+ NEED_STACK = true
43
+ NEED_RUNNING = true
44
+ SHORT_HELP = 'Step to end of current method (step out)'
64
45
  end
65
- if 0 == level_count and %w(return c-return yield leave).member?(@proc.event)
66
- errmsg "You are already at the requested return event."
67
- else
68
- @proc.finish(level_count, opts)
46
+
47
+ # This method runs the command
48
+ def run(args)
49
+ opts = {}
50
+ if args.size == 1
51
+ # Form is: "finish" which means "finish 1"
52
+ level_count = 0
53
+ else
54
+ count_str = args[1]
55
+ opts = {
56
+ :msg_on_error =>
57
+ "The '#{NAME}' command argument must eval to an integer. Got: %s" %
58
+ count_str,
59
+ :min_value => 1
60
+ }
61
+ count = @proc.get_an_int(count_str, opts)
62
+ return unless count
63
+ # step 1 is core.level_count = 0 or "stop next event"
64
+ level_count = count - 1
65
+ end
66
+ if (0 == level_count and
67
+ %w(return c_return b_return end raise).member?(@proc.event.to_s))
68
+ errmsg "You are already at the requested return event."
69
+ else
70
+ @proc.finish(level_count, opts)
71
+ end
69
72
  end
70
- end
71
73
  end
72
74
 
73
75
  if __FILE__ == $0
74
- require_relative '../mock'
75
- dbgr, cmd = MockDebugger::setup
76
- [%W(#{cmd.name} 1), %w(fin 2-1), %w(n foo)].each do |c|
77
- cmd.proc.next_level = 0
78
- cmd.proc.leave_cmd_loop = false
79
- result = cmd.run(c)
80
- puts 'Run result: %s' % result
81
- puts 'level_count %d, leave_cmd_loop: %s' % [cmd.proc.next_level,
82
- cmd.proc.leave_cmd_loop]
83
- end
84
- [%w(fin), [cmd.name]].each do |c|
85
- cmd.proc.next_level = 0
86
- cmd.proc.leave_cmd_loop = false
87
- result = cmd.run(c)
88
- puts cmd.proc.different_pos
89
- end
76
+ require_relative '../mock'
77
+ dbgr, cmd = MockDebugger::setup
78
+ [%W(#{cmd.name} 1), %w(fin 2-1), %w(n foo)].each do |c|
79
+ cmd.proc.next_level = 0
80
+ cmd.proc.leave_cmd_loop = false
81
+ result = cmd.run(c)
82
+ puts 'Run result: %s' % result
83
+ puts 'level_count %d, leave_cmd_loop: %s' % [cmd.proc.next_level,
84
+ cmd.proc.leave_cmd_loop]
85
+ end
86
+ [%w(fin), [cmd.name]].each do |c|
87
+ cmd.proc.next_level = 0
88
+ cmd.proc.leave_cmd_loop = false
89
+ result = cmd.run(c)
90
+ puts cmd.proc.different_pos
91
+ end
90
92
  end
@@ -34,7 +34,7 @@ info line command.
34
34
  NEED_STACK = false
35
35
  SHORT_HELP = 'Print commands or give help for command(s)'
36
36
 
37
- ROOT_DIR = File.dirname(RubyVM::Frame.current.source_container[1])
37
+ ROOT_DIR = File.dirname(RubyVM::Frame.get.source_container[1])
38
38
  HELP_DIR = File.join(ROOT_DIR, 'help')
39
39
  MARKDOWN_EXTENSION='.md'
40
40
  end
@@ -6,19 +6,19 @@ class Trepan::Subcommand::InfoBreakpoints < Trepan::Subcommand
6
6
  unless defined?(HELP)
7
7
  Trepanning::Subcommand.set_name_prefix(__FILE__, self)
8
8
  HELP = <<-EOH
9
- **#{CMD}** [*num1* ...] [**verbose**]
9
+ **#{CMD}** [*num1* ...] [**--verbose**]
10
10
 
11
11
  Show status of user-settable breakpoints. If no breakpoint numbers are
12
12
  given, the show all breakpoints. Otherwise only those breakpoints
13
- listed are shown and the order given. If *verbose* is given, more
13
+ listed are shown and the order given. If ``--verbose` is given, more
14
14
  information provided about each breakpoint.
15
15
 
16
- The "Disp" column contains one of "keep", "del", the disposition of
16
+ In the *Disp* column values are "keep", or "del", the disposition of
17
17
  the breakpoint after it gets hit.
18
18
 
19
- The "enb" column indicates whether the breakpoint is enabled.
19
+ The *enb* column indicates whether the breakpoint is enabled.
20
20
 
21
- The "Where" column indicates where the breakpoint is located.
21
+ The *Where* column indicates where the breakpoint is located.
22
22
  EOH
23
23
  MIN_ABBREV = 'br'.size
24
24
  SHORT_HELP = 'Status of user-settable breakpoints'
@@ -35,7 +35,7 @@ EOH
35
35
  [iseq.source_container.join(' '),
36
36
  iseq.offset2lines(bp.offset).join(', ')]
37
37
  vm_loc = "VM offset %d of instruction sequence \"%s\"" %
38
- [bp.offset, iseq.name]
38
+ [bp.offset, iseq.label]
39
39
 
40
40
  loc, other_loc =
41
41
  if 'line' == bp.type
@@ -79,7 +79,7 @@ EOH
79
79
  def run(args)
80
80
  verbose = false
81
81
  unless args.empty?
82
- if 'verbose' == args[-1]
82
+ if '--verbose' == args[-1]
83
83
  verbose = true
84
84
  args.pop
85
85
  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 'linecache'
4
4
  require 'columnize'
5
5
  require_relative '../base/subcmd'
@@ -7,230 +7,229 @@ require_relative '../../../app/run'
7
7
  require_relative '../../../app/util'
8
8
 
9
9
  class Trepan::Subcommand::InfoFiles < Trepan::Subcommand
10
- Trepan::Util::suppress_warnings {
11
- Trepanning::Subcommand.set_name_prefix(__FILE__, self)
12
- DEFAULT_FILE_ARGS = %w(size mtime sha1)
10
+ Trepan::Util::suppress_warnings {
11
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
12
+ DEFAULT_FILE_ARGS = %w(size mtime sha1)
13
13
 
14
- HELP = <<-EOH
15
- **#{CMD}** [{*filename*|.|\\*} *attributes*
16
-
17
- *attributes* can be any set of of:
18
- **all**, **ctime**, **brkpts**, **mtime**, **sha1**, **size** or **stat**
14
+ HELP = <<-EOH
15
+ **#{CMD}** [{*filename*|**.**|`*`} [**all**|**ctime**|**brkpts**|**mtime**|**sha1**|**size**|**stat**]]
19
16
 
20
17
  Show information about the current file. If no filename is given and
21
18
  the program is running, then the current file associated with the
22
19
  current stack entry is used. Giving . has the same effect.
23
20
 
24
- A `*` gives a list of all files we know about.
21
+ If given a filename of `*`, we give a list of all files we know about.
25
22
 
26
23
  Sub options which can be shown about a file are:
27
24
 
28
- brkpts -- Line numbers where there are statement boundaries.
29
- These lines can be used in breakpoint commands.
30
- ctime -- File creation time
31
- iseq -- Instruction sequences from this file.
32
- mtime -- File modification time
33
- sha1 -- A SHA1 hash of the source text. This may be useful in comparing
34
- source code.
35
- size -- The number of lines in the file.
36
- stat -- File.stat information
37
-
38
- all -- All of the above information.
25
+ * `brkpts` Line numbers where there are statement boundaries. These lines can be used in breakpoint commands.
26
+ * `ctime` File creation time
27
+ * `iseq` Instruction sequences from this file.
28
+ * `mtime` File modification time
29
+ * `sha1` SHA1 hash of the source text. This may be useful in comparing source code.
30
+ * `size` number of lines in the file.
31
+ * `stat` File.stat information
32
+ * `all` All of the above information.
39
33
 
40
- If no sub-options are given, `#{DEFAULT_FILE_ARGS.join(' ')}` are assumed.
34
+ If no sub-options are given, "#{DEFAULT_FILE_ARGS.join(' ')}" are assumed.
41
35
 
42
36
  Examples:
43
- ---------
44
-
37
+ --------
45
38
  #{CMD} # Show #{DEFAULT_FILE_ARGS.join(' ')} information about current file
46
39
  #{CMD} . # same as above
47
40
  #{CMD} brkpts # show the number of lines in the current file
48
41
  #{CMD} brkpts size # same as above but also list breakpoint line numbers
49
42
  #{CMD} * # Give a list of files we know about
43
+
44
+ See also:
45
+ ---------
46
+ `info frame`, `info program`
50
47
  EOH
51
- MIN_ABBREV = 'fi'.size # Note we have "info frame"
52
- NEED_STACK = false
53
- }
54
-
55
- # completion %w(all brkpts iseq sha1 size stat)
56
-
57
- include Trepanning
58
-
59
- def file_list
60
- (LineCache.cached_files +
61
- LineCache.class_variable_get('@@file2file_remap').keys).uniq
62
- end
63
-
64
- def complete(prefix)
65
- completions = ['.'] + file_list
66
- Trepan::Complete.complete_token(completions, prefix)
67
- end
68
-
69
- # Get file information
70
- def run(args)
71
- return if args.size < 2
72
- args << '.' if 2 == args.size
73
- if '*' == args[2]
74
- section 'Canonic Files names cached:'
75
- primary = LineCache.class_variable_get('@@file_cache')
76
- remap = LineCache.class_variable_get('@@file2file_remap')
77
- msg columnize_commands(remap.keys.uniq.sort)
78
- names = remap.keys - primary.keys
79
- unless names.empty?
80
- section 'Non-canonic names cached:'
81
- msg columnize_commands(names.sort)
82
- end
83
- return
48
+ MIN_ABBREV = 'fi'.size # Note we have "info frame"
49
+ NEED_STACK = false
50
+ }
51
+
52
+ # completion %w(all brkpts iseq sha1 size stat)
53
+
54
+ include Trepanning
55
+
56
+ def file_list
57
+ (LineCache.cached_files +
58
+ LineCache.class_variable_get('@@file2file_remap').keys).uniq
84
59
  end
85
- filename =
86
- if '.' == args[2]
87
- if not @proc.frame
88
- errmsg("No frame - no default file.")
89
- return false
90
- nil
91
- else
92
- frame_file = @proc.frame.source_container[1]
93
- LineCache::unmap_file(frame_file) || File.expand_path(frame_file)
94
- end
95
- else
96
- args[2]
97
- end
98
- args += DEFAULT_FILE_ARGS if args.size == 3
99
-
100
- m = filename
101
- canonic_name = @proc.canonic_file(filename)
102
- canonic_name = LineCache::map_file(canonic_name) || canonic_name
103
- if LineCache::cached?(canonic_name)
104
- m += " is cached in debugger"
105
- if canonic_name != filename
106
- m += (" as:\n " + canonic_name)
107
- end
108
- m += '.'
109
- msg(m)
110
- elsif !(matches = find_scripts(filename)).empty?
111
- if (matches.size > 1)
112
- msg("Multiple files found:")
113
- matches.sort.each { |match_file| msg "\t%s" % match_file }
114
- return
115
- else
116
- msg('File "%s" just now cached.' % filename)
117
- LineCache::cache(matches[0])
118
- LineCache::remap_file(filename, matches[0])
119
- canonic_name = matches[0]
120
- end
121
- else
122
- matches = file_list.select{|try| try.end_with?(filename)}
123
- if (matches.size > 1)
124
- msg("Multiple files found ending filename string:")
125
- matches.sort.each { |match_file| msg "\t%s" % match_file }
126
- return
127
- elsif 1 == matches.size
128
- canonic_name = LineCache::map_file(matches[0])
129
- m += " matched debugger cache file:\n " + canonic_name
130
- msg m
131
- else
132
- msg(m + ' is not cached in debugger.')
133
- return
134
- end
60
+
61
+ def complete(prefix)
62
+ completions = ['.'] + file_list
63
+ Trepan::Complete.complete_token(completions, prefix)
135
64
  end
136
- seen = {}
137
- args[3..-1].each do |arg|
138
- processed_arg = false
139
-
140
- if %w(all size).member?(arg)
141
- unless seen[:size]
142
- max_line = LineCache::size(canonic_name)
143
- msg "File has %d lines." % max_line if max_line
144
- end
145
- processed_arg = seen[:size] = true
146
- end
147
65
 
148
- if %w(all sha1).member?(arg)
149
- unless seen[:sha1]
150
- msg("SHA1 is %s." % LineCache::sha1(canonic_name))
151
- end
152
- processed_arg = seen[:sha1] = true
153
- end
154
-
155
- if %w(all brkpts).member?(arg)
156
- unless seen[:brkpts]
157
- syntax_errors = Trepanning::ruby_syntax_errors(canonic_name)
158
- if syntax_errors
159
- msg('Not a syntactically-correct Ruby program.')
160
- else
161
- msg("Possible breakpoint line numbers:")
162
- lines = LineCache.trace_line_numbers(canonic_name)
163
- fmt_lines = columnize_numbers(lines)
164
- msg(fmt_lines)
165
- end
66
+ # Get file information
67
+ def run(args)
68
+ return if args.size < 2
69
+ args << '.' if 2 == args.size
70
+ if '*' == args[2]
71
+ section 'Canonic filenames cached:'
72
+ primary = LineCache.class_variable_get('@@file_cache')
73
+ remap = LineCache.class_variable_get('@@file2file_remap')
74
+ msg columnize_commands(remap.keys.uniq.sort)
75
+ names = remap.keys - primary.keys
76
+ unless names.empty?
77
+ section 'Non-canonic names cached:'
78
+ msg columnize_commands(names.sort)
79
+ end
80
+ return
166
81
  end
167
- processed_arg = seen[:brkpts] = true
168
- end
169
-
170
- if %w(all ctime).member?(arg)
171
- unless seen[:ctime]
172
- msg("create time:\t%s." %
173
- LineCache::stat(canonic_name).ctime.to_s)
82
+ if '.' == args[2]
83
+ if not @proc.frame
84
+ errmsg("No frame - no default file.")
85
+ return false
86
+ nil
87
+ elsif @proc.frame.source_container[0] == 'binary'
88
+ errmsg("frame refers to binary - no file here.")
89
+ return false
90
+ else
91
+ frame_file = @proc.frame.source_container[1]
92
+ filename = LineCache::map_file(frame_file) || File.expand_path(frame_file)
93
+ end
94
+ else
95
+ filename = args[2]
174
96
  end
175
- processed_arg = seen[:ctime] = true
176
- end
177
-
178
- if %w(all iseq).member?(arg)
179
- unless seen[:iseq]
180
- if SCRIPT_ISEQS__.member?(canonic_name)
181
- msg("File contains instruction sequences:")
182
- SCRIPT_ISEQS__[canonic_name].each do |iseq|
183
- msg("\t %s %s" % [iseq, iseq.name.inspect])
97
+ args += DEFAULT_FILE_ARGS if args.size == 3
98
+
99
+ m = filename
100
+ canonic_name = @proc.canonic_file(filename)
101
+ canonic_name = LineCache::map_file(canonic_name) || canonic_name
102
+ if LineCache::cached?(canonic_name)
103
+ m += " is cached in debugger"
104
+ if canonic_name != filename
105
+ m += (" as:\n " + canonic_name)
106
+ end
107
+ m += '.'
108
+ msg(m)
109
+ elsif !(matches = find_scripts(filename)).empty?
110
+ if (matches.size > 1)
111
+ msg("Multiple files found:")
112
+ matches.sort.each { |match_file| msg "\t%s" % match_file }
113
+ return
114
+ else
115
+ msg('File "%s" just now cached.' % filename)
116
+ LineCache::cache(matches[0])
117
+ LineCache::remap_file(filename, matches[0])
118
+ canonic_name = matches[0]
119
+ end
120
+ else
121
+ matches = file_list.select{|try| try.end_with?(filename)}
122
+ if (matches.size > 1)
123
+ msg("Multiple files found ending filename string:")
124
+ matches.sort.each { |match_file| msg "\t%s" % match_file }
125
+ return
126
+ elsif 1 == matches.size
127
+ canonic_name = LineCache::map_file(matches[0])
128
+ m += " matched debugger cache file:\n " + canonic_name
129
+ msg m
130
+ else
131
+ msg(m + ' is not cached in debugger.')
132
+ return
184
133
  end
185
- else
186
- msg("Instruction sequences not recorded; there may be some, though.")
187
- end
188
134
  end
189
- processed_arg = seen[:iseq] = true
190
- end
135
+ seen = {}
136
+ args[3..-1].each do |arg|
137
+ processed_arg = false
138
+
139
+ if %w(all size).member?(arg)
140
+ unless seen[:size]
141
+ max_line = LineCache::size(canonic_name)
142
+ msg "File has %d lines." % max_line if max_line
143
+ end
144
+ processed_arg = seen[:size] = true
145
+ end
191
146
 
192
- if %w(all mtime).member?(arg)
193
- unless seen[:mtime]
194
- msg("modify time:\t%s." %
195
- LineCache::stat(canonic_name).mtime.to_s)
196
- end
197
- processed_arg = seen[:mtime] = true
198
- end
147
+ if %w(all sha1).member?(arg)
148
+ unless seen[:sha1]
149
+ msg("SHA1 is %s." % LineCache::sha1(canonic_name))
150
+ end
151
+ processed_arg = seen[:sha1] = true
152
+ end
199
153
 
200
- if %w(all stat).member?(arg)
201
- unless seen[:stat]
202
- msg("Stat info:\n\t%s." % LineCache::stat(canonic_name).inspect)
203
- end
204
- processed_arg = seen[:stat] = true
205
- end
206
-
207
- if not processed_arg
208
- errmsg("I don't understand sub-option \"%s\"." % arg)
209
- end
210
- end unless args.empty?
211
- end
154
+ if %w(all brkpts).member?(arg)
155
+ unless seen[:brkpts]
156
+ syntax_errors = Trepanning::ruby_syntax_errors(canonic_name)
157
+ if syntax_errors
158
+ msg('Not a syntactically-correct Ruby program.')
159
+ else
160
+ msg("Possible breakpoint line numbers:")
161
+ lines = LineCache.trace_line_numbers(canonic_name)
162
+ fmt_lines = columnize_numbers(lines)
163
+ msg(fmt_lines)
164
+ end
165
+ end
166
+ processed_arg = seen[:brkpts] = true
167
+ end
168
+
169
+ if %w(all ctime).member?(arg)
170
+ unless seen[:ctime]
171
+ msg("create time:\t%s." %
172
+ LineCache::stat(canonic_name).ctime.to_s)
173
+ end
174
+ processed_arg = seen[:ctime] = true
175
+ end
176
+
177
+ if %w(all iseq).member?(arg)
178
+ unless seen[:iseq]
179
+ if SCRIPT_ISEQS__.member?(canonic_name)
180
+ msg("File contains instruction sequences:")
181
+ SCRIPT_ISEQS__[canonic_name].each do |iseq|
182
+ msg("\t %s %s" % [iseq, iseq.label.inspect])
183
+ end
184
+ else
185
+ msg("Instruction sequences not recorded; there may be some, though.")
186
+ end
187
+ end
188
+ processed_arg = seen[:iseq] = true
189
+ end
190
+
191
+ if %w(all mtime).member?(arg)
192
+ unless seen[:mtime]
193
+ msg("modify time:\t%s." %
194
+ LineCache::stat(canonic_name).mtime.to_s)
195
+ end
196
+ processed_arg = seen[:mtime] = true
197
+ end
198
+
199
+ if %w(all stat).member?(arg)
200
+ unless seen[:stat]
201
+ msg("Stat info:\n\t%s." % LineCache::stat(canonic_name).inspect)
202
+ end
203
+ processed_arg = seen[:stat] = true
204
+ end
205
+
206
+ if not processed_arg
207
+ errmsg("I don't understand sub-option \"%s\"." % arg)
208
+ end
209
+ end unless args.empty?
210
+ end
212
211
  end
213
212
 
214
213
  if __FILE__ == $0
215
- if !(ARGV.size == 1 && ARGV[0] == 'noload')
216
- ISEQS__ = {}
217
- SCRIPT_ISEQS__ = {}
218
- ARGV[0..-1] = ['noload']
219
- load(__FILE__)
220
- else
221
- require_relative '../../mock'
222
- cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoFiles, false)
223
- [%w(info file nothere),
224
- %w(info file .),
225
- %w(info file *),
226
- %w(info file),
227
- %w(info file file.rb),
228
- %w(info file citrus/file.rb),
229
- %w(info file . all),
230
- %w(info file . brkpts bad size sha1 sha1)].each do |args|
231
- cmd.run(args)
232
- puts '-' * 40
214
+ if !(ARGV.size == 1 && ARGV[0] == 'noload')
215
+ ISEQS__ = {}
216
+ SCRIPT_ISEQS__ = {}
217
+ ARGV[0..-1] = ['noload']
218
+ load(__FILE__)
219
+ else
220
+ require_relative '../../mock'
221
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoFiles, false)
222
+ [%w(info file nothere),
223
+ %w(info file .),
224
+ %w(info file *),
225
+ %w(info file),
226
+ %w(info file file.rb),
227
+ %w(info file citrus/file.rb),
228
+ %w(info file . all),
229
+ %w(info file . brkpts bad size sha1 sha1)].each do |args|
230
+ cmd.run(args)
231
+ puts '-' * 40
232
+ end
233
+ p cmd.complete('')
233
234
  end
234
- p cmd.complete('')
235
- end
236
235
  end