Top Level Namespace

Constant Summary collapse

DEBUGGER_STEP_TYPE =
['STEP','STOVER','STRET','SUSP']
DEBUGGER_STEP_COMMENT =
['Stepped into','Stepped over','Stepped return','Suspended']
DEBUGGER_LOG_LEVEL_DEBUG =
0
DEBUGGER_LOG_LEVEL_INFO =
1
DEBUGGER_LOG_LEVEL_WARN =
2
DEBUGGER_LOG_LEVEL_ERROR =
3

Instance Method Summary collapse

Instance Method Details

#debug_handle_cmd(inline) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/debugger.rb', line 100

def debug_handle_cmd(inline)
  #$_s.write("start of debug_handle_cmd wait=" + inline.to_s + "\n")

  cmd = $_cmd.match(/^([^\n\r]*)([\n\r]+|$)/)[0]
  processed = false
  wait = inline

  if cmd != ""
    if cmd =~/^CONNECTED/
      log_command(cmd)
      debugger_log(DEBUGGER_LOG_LEVEL_INFO, "Connected to debugger")
      processed = true
    elsif cmd =~/^(BP|RM):/
      log_command(cmd)
      ary = cmd.split(":")
      bp = ary[1].gsub(/\|/,':') + ':' + ary[2].chomp
      if (cmd =~/^RM:/)
        $_breakpoint.delete(bp)
        debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoint removed: #{bp}")
      else
        $_breakpoint.store(bp,1)
        debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoint added: #{bp}")
      end
      processed = true
    elsif cmd =~ /^RMALL/
      log_command(cmd)
      $_breakpoint.clear
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "All breakpoints removed")
      processed = true
    elsif cmd =~ /^ENABLE/
      log_command(cmd)
      $_breakpoints_enabled = true
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoints enabled")
      processed = true
    elsif cmd =~ /^DISABLE/
      log_command(cmd)
      $_breakpoints_enabled = false
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoints disabled")
      processed = true
    elsif inline && (cmd =~ /^STEPOVER/)
      $_s.write("STEPOVER start\n")
      log_command(cmd)
      $_step = 2
      $_step_level = $_call_stack
      $_resumed = true
      wait = false
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step over")
      processed = true
    elsif inline && (cmd =~ /^STEPRET/)
      log_command(cmd)
      if $_call_stack < 1
        $_step = 0
        comment = ' (continue)'
      else
        $_step = 3
        $_step_level = $_call_stack-1;
        comment = ''
      end
      $_resumed = true
      wait = false
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step return" + comment)
      processed = true
    elsif inline && (cmd =~ /^STEP/)
      log_command(cmd)
      $_step = 1
      $_step_level = -1
      $_resumed = true
      wait = false
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step into")
      processed = true
    elsif inline && (cmd =~ /^CONT/)
      log_command(cmd)
      wait = false
      $_step = 0
      $_resumed = true
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Resuming")
      processed = true
    elsif cmd =~ /^SUSP/
      log_command(cmd)
      $_step = 4
      $_step_level = -1
      wait = true
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Suspend")
      processed = true
    elsif cmd =~ /^KILL/
      log_command(cmd)
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Terminating...")
      processed = true
      System.exit
    elsif inline && (cmd =~ /^EVL?:/)
      log_command(cmd)
      processed = true
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Calc evaluation...")
      execute_cmd cmd.sub(/^EVL?:/,""), (cmd =~ /^EVL:/ ? true : false)
    elsif inline && (cmd =~ /^[GLCI]VARS/)
      log_command(cmd)
      debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Get variables...")
      get_variables cmd
      processed = true
    elsif inline
      log_command(cmd)
      debugger_log(DEBUGGER_LOG_LEVEL_WARN, "Unknown command")
      processed = true
    end
  end

  if processed
    $_cmd = $_cmd.sub(/^([^\n\r]*)([\n\r]+(.*)|)$/, "\\3")
    $_wait = wait if inline
  end

  #$_s.write("end of debug_handle_cmd wait=" + $_wait.to_s + "cmd=" + cmd + "\n")

  processed
end

#debug_read_cmd(io, wait) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/debugger.rb', line 22

def debug_read_cmd(io,wait)
  begin
    if wait
      cmd = io.readpartial(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    else
      cmd = io.read_nonblock(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    end
    # $_s.write("get data from front end" + $_cmd.to_s + "\n")
  rescue
    # puts $!.inspect
  end
end

#debugger_log(level, msg) ⇒ Object



12
13
14
15
16
# File 'lib/debugger.rb', line 12

def debugger_log(level, msg)
  if (level >= DEBUGGER_LOG_LEVEL_WARN)
    puts "[Debugger] #{msg}"
  end
end

#execute_cmd(cmd, advanced) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/debugger.rb', line 37

def execute_cmd(cmd, advanced)
  #$_s.write("execute_cmd start\n")
  cmd = URI.unescape(cmd.gsub(/\+/,' ')) if advanced
  debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Executing: #{cmd.inspect}")
  result = ""
  error = '0';
  begin
    result = eval(cmd.to_s, $_binding).inspect
  rescue Exception => exc
    error = '1';
    result = "#{$!}".inspect
  end
  
  cmd = URI.escape(cmd.sub(/[\n\r]+$/, ''), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) if advanced
  $_s.write("EV" + (advanced ? "L:#{error}:#{cmd}:" : ':'+(error.to_i != 0 ? 'ERROR: ':'')) + result + "\n")
  #$_s.write("execute_cmd end\n")
end

#get_variables(scope) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/debugger.rb', line 55

def get_variables(scope)  
  #$_s.write("get_variables start\n")

  if (scope =~ /^GVARS/)
   cmd = "global_variables"
   prefix = ""
   vartype = "G"
  elsif (scope =~ /^LVARS/)
   cmd = "local_variables"
   prefix = ""
   vartype = "L"
  elsif (scope =~ /^CVARS/)
   if $_classname =~ /^\s*$/
     return
   end
   cmd = "class_variables"
   prefix = "#{$_classname}."
   vartype = "C"
  elsif (scope =~ /^IVARS/)
   if ($_classname =~ /^\s*$/) || ($_methodname =~ /^\s*$/)
     return
   end
   cmd = "instance_variables"
   prefix = "self."
   vartype = "I"
  end
  begin
    vars = eval(prefix + cmd, $_binding)
    $_s.write("VSTART:#{vartype}\n")
    vars.each do |v|
      if v !~ /^\$(=|KCODE|-K)$/
        begin
          result = eval(v.to_s, $_binding).inspect
        rescue Exception => exc
          $_s.write("get var exception\n")
          result = "#{$!}".inspect
        end
        $_s.write("V:#{vartype}:#{v}:#{result}\n")
      end
    end
    $_s.write("VEND:#{vartype}\n")
  rescue
  end
end

#log_command(cmd) ⇒ Object



18
19
20
# File 'lib/debugger.rb', line 18

def log_command(cmd)
  debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Received command: #{cmd}")
end