ruby-debug-ide 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ module Debugger
2
+ class QuitCommand < Command # :nodoc:
3
+ self.control = true
4
+
5
+ def regexp
6
+ /^\s*(?:q(?:uit)?|exit)\s*$/
7
+ end
8
+
9
+ def execute
10
+ if confirm("Really quit? (y/n) ")
11
+ Debugger.save_history if Debugger.respond_to? :save_history
12
+ exit! # exit -> exit!: No graceful way to stop threads...
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def help_command
18
+ %w[quit exit]
19
+ end
20
+
21
+ def help(cmd)
22
+ %{
23
+ q[uit]\texit from debugger,
24
+ exit\talias to quit
25
+ }
26
+ end
27
+ end
28
+ end
29
+
30
+ class RestartCommand < Command # :nodoc:
31
+ self.control = true
32
+
33
+ def regexp
34
+ / ^\s*
35
+ (restart|R)
36
+ (\s+ \S+ .*)?
37
+ $
38
+ /x
39
+ end
40
+
41
+ def execute
42
+ if not defined? Debugger::RDEBUG_SCRIPT or not defined? Debugger::ARGV
43
+ print "We are not in a context we can restart from.\n"
44
+ return
45
+ end
46
+ if @match[2]
47
+ args = Debugger::PROG_SCRIPT + " " + @match[2]
48
+ else
49
+ args = Debugger::ARGV.join(" ")
50
+ end
51
+
52
+ # An execv would be preferable to the "exec" below.
53
+ cmd = Debugger::RDEBUG_SCRIPT + " " + args
54
+ print "Re exec'ing:\n\t#{cmd}\n"
55
+ exec cmd
56
+ end
57
+
58
+ class << self
59
+ def help_command
60
+ 'restart'
61
+ end
62
+
63
+ def help(cmd)
64
+ %{
65
+ restart|R [args]
66
+ Restart the program. This is is a re-exec - all debugger state
67
+ is lost. If command arguments are passed those are used.
68
+ }
69
+ end
70
+ end
71
+ end
72
+
73
+ class StartCommand < Command # :nodoc:
74
+ self.control = true
75
+
76
+ def regexp
77
+ /^\s*(start)(\s+ \S+ .*)?$/x
78
+ end
79
+
80
+ def execute
81
+ @printer.print_debug("Starting: running program script")
82
+ Debugger.run_prog_script #Debugger.prog_script_running?
83
+ end
84
+
85
+ class << self
86
+ def help_command
87
+ 'start'
88
+ end
89
+
90
+ def help(cmd)
91
+ %{
92
+ run prog script
93
+ }
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ class InterruptCommand < Command # :nodoc:
100
+ self.event = false
101
+ self.control = true
102
+ self.need_context = true
103
+
104
+ def regexp
105
+ /^\s*i(?:nterrupt)?\s*$/
106
+ end
107
+
108
+ def execute
109
+ unless Debugger.interrupt_last
110
+ context = Debugger.thread_context(Thread.main)
111
+ context.interrupt
112
+ end
113
+ end
114
+
115
+ class << self
116
+ def help_command
117
+ 'interrupt'
118
+ end
119
+
120
+ def help(cmd)
121
+ %{
122
+ i[nterrupt]\tinterrupt the program
123
+ }
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,64 @@
1
+ module Debugger
2
+ class EvalCommand < Command # :nodoc:
3
+ #self.control = true
4
+
5
+ def match(input)
6
+ @input = input
7
+ super
8
+ end
9
+
10
+ def regexp
11
+ /^\s*(p|e(?:val)?)\s+/
12
+ end
13
+
14
+ def execute
15
+ expr = @match ? @match.post_match : @input
16
+ binding = @state.context ? get_binding : TOPLEVEL_BINDING
17
+ print_eval expr, debug_eval(expr, binding).inspect
18
+ end
19
+
20
+ class << self
21
+ def help_command
22
+ %w|p eval|
23
+ end
24
+
25
+ def help(cmd)
26
+ if cmd == 'p'
27
+ %{
28
+ p expression\tevaluate expression and print its value
29
+ }
30
+ else
31
+ %{
32
+ e[val] expression\tevaluate expression and print its value,
33
+ \t\t\talias for p.
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ class PPCommand < Command # :nodoc:
41
+ def regexp
42
+ /^\s*pp\s+/
43
+ end
44
+
45
+ def execute
46
+ exp = @match.post_match
47
+ out = StringIO.new
48
+ PP.pp(debug_eval(exp), out) rescue out.puts $!.message
49
+ print_pp exp, out.string
50
+ end
51
+
52
+ class << self
53
+ def help_command
54
+ 'pp'
55
+ end
56
+
57
+ def help(cmd)
58
+ %{
59
+ pp expression\tevaluate expression and print its value
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,161 @@
1
+ module Debugger
2
+ module FrameFunctions # :nodoc:
3
+ def adjust_frame(frame_pos, absolute)
4
+ if absolute
5
+ if frame_pos < 0
6
+ abs_frame_pos = @state.context.stack_size + frame_pos
7
+ else
8
+ abs_frame_pos = frame_pos - 1
9
+ end
10
+ else
11
+ abs_frame_pos = @state.frame_pos + frame_pos
12
+ end
13
+
14
+ if abs_frame_pos >= @state.context.stack_size then
15
+ print_error "Adjusting would put us beyond the oldest (initial) frame.\n"
16
+ return
17
+ elsif abs_frame_pos < 0 then
18
+ print_error "Adjusting would put us beyond the newest (innermost) frame.\n"
19
+ return
20
+ end
21
+ if @state.frame_pos != abs_frame_pos then
22
+ @state.previous_line = nil
23
+ @state.frame_pos = abs_frame_pos
24
+ end
25
+ @state.file = @state.context.frame_file(@state.frame_pos)
26
+ @state.line = @state.context.frame_line(@state.frame_pos)
27
+
28
+ print_current_frame(@state.context, @state.frame_pos)
29
+ end
30
+
31
+ def get_int(str, cmd)
32
+ begin
33
+ return Integer(@match[1])
34
+ rescue
35
+ print_error "%s argument needs to be a number.\n" % cmd
36
+ return nil
37
+ end
38
+ end
39
+ end
40
+
41
+ class WhereCommand < Command # :nodoc:
42
+ def regexp
43
+ /^\s*(?:w(?:here)?|bt|backtrace)$/
44
+ end
45
+
46
+ def execute
47
+ print_frames(@state.context, @state.frame_pos)
48
+ end
49
+
50
+ class << self
51
+ def help_command
52
+ %w|where backtrace|
53
+ end
54
+
55
+ def help(cmd)
56
+ if cmd == 'where'
57
+ %{
58
+ w[here]\tdisplay frames
59
+ }
60
+ else
61
+ %{
62
+ bt|backtrace\t\talias for where
63
+ }
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ class UpCommand < Command # :nodoc:
70
+ include FrameFunctions
71
+ def regexp
72
+ /^\s* u(?:p)? (?:\s+(.*))? .*$/x
73
+ end
74
+
75
+ def execute
76
+ unless @match[1]
77
+ pos = 1
78
+ else
79
+ pos = get_int(@match[1], "Up")
80
+ return unless pos
81
+ end
82
+ adjust_frame(pos, false)
83
+ end
84
+
85
+ class << self
86
+ def help_command
87
+ 'up'
88
+ end
89
+
90
+ def help(cmd)
91
+ %{
92
+ up[count]\tmove to higher frame
93
+ }
94
+ end
95
+ end
96
+ end
97
+
98
+ class DownCommand < Command # :nodoc:
99
+ include FrameFunctions
100
+ def regexp
101
+ /^\s* down (?:\s+(.*))? .*$/x
102
+ end
103
+
104
+ def execute
105
+ if not @match[1]
106
+ pos = 1
107
+ else
108
+ pos = get_int(@match[1], "Down")
109
+ return unless pos
110
+ end
111
+ adjust_frame(-pos, false)
112
+ end
113
+
114
+ class << self
115
+ def help_command
116
+ 'down'
117
+ end
118
+
119
+ def help(cmd)
120
+ %{
121
+ down[count]\tmove to lower frame
122
+ }
123
+ end
124
+ end
125
+ end
126
+
127
+ class FrameCommand < Command # :nodoc:
128
+ include FrameFunctions
129
+ def regexp
130
+ /^\s* f(?:rame)? (?:\s+ (.*))? \s*$/x
131
+ end
132
+
133
+ def execute
134
+ if not @match[1]
135
+ print "Missing a frame number argument.\n"
136
+ return
137
+ else
138
+ pos = get_int(@match[1], "Frame")
139
+ return unless pos
140
+ end
141
+ adjust_frame(pos, true)
142
+ end
143
+
144
+ class << self
145
+ def help_command
146
+ 'frame'
147
+ end
148
+
149
+ def help(cmd)
150
+ %{
151
+ f[rame] frame-number
152
+ Move the current frame to the specified frame number.
153
+
154
+ A negative number indicates position from the other end. So
155
+ 'frame -1' moves to the oldest frame, and 'frame 0' moves to
156
+ the newest frame.
157
+ }
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,24 @@
1
+ module Debugger
2
+
3
+ class InspectCommand < Command
4
+ # reference inspection results in order to save them from the GC
5
+ @@references = []
6
+ def self.reference_result(result)
7
+ @@references << result
8
+ end
9
+ def self.clear_references
10
+ @@references = []
11
+ end
12
+
13
+ def regexp
14
+ /^\s*v(?:ar)?\s+inspect\s+/
15
+ end
16
+ #
17
+ def execute
18
+ obj = debug_eval(@match.post_match)
19
+ InspectCommand.reference_result(obj)
20
+ @printer.print_inspect(obj)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,18 @@
1
+ module Debugger
2
+ class LoadCommand < Command
3
+ def regexp
4
+ /^\s*load\s+/
5
+ end
6
+
7
+ def execute
8
+ fileName = @match.post_match
9
+ @printer.print_debug("loading file: %s", fileName)
10
+ begin
11
+ load fileName
12
+ @printer.print_load_result(fileName)
13
+ rescue Exception => error
14
+ @printer.print_load_result(fileName, error)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,105 @@
1
+ module Debugger
2
+ class NextCommand < Command # :nodoc
3
+ self.need_context = true
4
+
5
+ def regexp
6
+ /^\s*n(?:ext)?(?:\s+(\d+))?(?:\s+(\d+))?$/
7
+ end
8
+
9
+ def execute
10
+ steps = @match[1] ? @match[1].to_i : 1
11
+ target_frame = @match[2] ? (@match[2].to_i() -1) : @state.frame_pos
12
+ @state.context.step_over steps, target_frame
13
+ @state.proceed
14
+ end
15
+
16
+ class << self
17
+ def help_command
18
+ 'next'
19
+ end
20
+
21
+ def help(cmd)
22
+ %{
23
+ n[ext][nl] [tf]\tgo over n lines, default is one, go to target frame tf (1-based)
24
+ }
25
+ end
26
+ end
27
+ end
28
+
29
+ class StepCommand < Command # :nodoc:
30
+ self.need_context = true
31
+
32
+ def regexp
33
+ /^\s*s(?:tep)?(?:\s+(\d+))?$/
34
+ end
35
+
36
+ def execute
37
+ @state.context.stop_next = @match[1] ? @match[1].to_i : 1
38
+ @state.proceed
39
+ end
40
+
41
+ class << self
42
+ def help_command
43
+ 'step'
44
+ end
45
+
46
+ def help(cmd)
47
+ %{
48
+ s[tep][ nnn]\tstep (into methods) one line or till line nnn
49
+ }
50
+ end
51
+ end
52
+ end
53
+
54
+ class FinishCommand < Command # :nodoc:
55
+ self.need_context = true
56
+
57
+ def regexp
58
+ /^\s*fin(?:ish)?$/
59
+ end
60
+
61
+ def execute
62
+ if @state.frame_pos == @state.context.stack_size - 1
63
+ print_msg "\"finish\" not meaningful in the outermost frame."
64
+ else
65
+ @state.context.stop_frame = @state.frame_pos
66
+ @state.frame_pos = 0
67
+ @state.proceed
68
+ end
69
+ end
70
+
71
+ class << self
72
+ def help_command
73
+ 'finish'
74
+ end
75
+
76
+ def help(cmd)
77
+ %{
78
+ fin[ish]\treturn to outer frame
79
+ }
80
+ end
81
+ end
82
+ end
83
+
84
+ class ContinueCommand < Command # :nodoc:
85
+ def regexp
86
+ /^\s*c(?:ont)?$/
87
+ end
88
+
89
+ def execute
90
+ @state.proceed
91
+ end
92
+
93
+ class << self
94
+ def help_command
95
+ 'cont'
96
+ end
97
+
98
+ def help(cmd)
99
+ %{
100
+ c[ont]\trun until program ends or hit breakpoint
101
+ }
102
+ end
103
+ end
104
+ end
105
+ end