rhomobile-debug 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/CHANGELOG +3 -0
  2. data/lib/debugger.rb +39 -29
  3. metadata +4 -4
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.4
2
+ * Debugger low level messages excluded from application log
3
+
1
4
  ## 1.0.3
2
5
  * Fix working with Ruby 1.9.2
3
6
 
data/lib/debugger.rb CHANGED
@@ -4,6 +4,21 @@ require 'timeout'
4
4
  DEBUGGER_STEP_TYPE = ['STEP','STOVER','STRET','SUSP']
5
5
  DEBUGGER_STEP_COMMENT = ['Stepped into','Stepped over','Stepped return','Suspended']
6
6
 
7
+ DEBUGGER_LOG_LEVEL_DEBUG = 0
8
+ DEBUGGER_LOG_LEVEL_INFO = 1
9
+ DEBUGGER_LOG_LEVEL_WARN = 2
10
+ DEBUGGER_LOG_LEVEL_ERROR = 3
11
+
12
+ def debugger_log(level, msg)
13
+ if (level >= DEBUGGER_LOG_LEVEL_WARN)
14
+ puts "[Debugger] #{msg}"
15
+ end
16
+ end
17
+
18
+ def log_command(cmd)
19
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Received command: #{cmd}")
20
+ end
21
+
7
22
  def debug_read_cmd(io,wait)
8
23
  begin
9
24
  if wait
@@ -13,8 +28,7 @@ def debug_read_cmd(io,wait)
13
28
  cmd = io.read_nonblock(4096)
14
29
  $_cmd << cmd if cmd !~ /^\s*$/
15
30
  end
16
-
17
- #$_s.write("get data from front end" + $_cmd.to_s + "\n")
31
+ # $_s.write("get data from front end" + $_cmd.to_s + "\n")
18
32
  rescue
19
33
  # puts $!.inspect
20
34
  end
@@ -23,7 +37,7 @@ end
23
37
  def execute_cmd(cmd, advanced)
24
38
  #$_s.write("execute_cmd start\n")
25
39
  cmd = URI.unescape(cmd.gsub(/\+/,' ')) if advanced
26
- puts "[Debugger] Executing: #{cmd.inspect}"
40
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Executing: #{cmd.inspect}")
27
41
  result = ""
28
42
  error = '0';
29
43
  begin
@@ -83,10 +97,6 @@ def get_variables(scope)
83
97
  end
84
98
  end
85
99
 
86
- def log_command(cmd)
87
- # puts "[Debugger] Received command: #{cmd}"
88
- end
89
-
90
100
  def debug_handle_cmd(inline)
91
101
  #$_s.write("start of debug_handle_cmd wait=" + inline.to_s + "\n")
92
102
 
@@ -97,7 +107,7 @@ def debug_handle_cmd(inline)
97
107
  if cmd != ""
98
108
  if cmd =~/^CONNECTED/
99
109
  log_command(cmd)
100
- puts "[Debugger] Connected to debugger"
110
+ debugger_log(DEBUGGER_LOG_LEVEL_INFO, "Connected to debugger")
101
111
  processed = true
102
112
  elsif cmd =~/^(BP|RM):/
103
113
  log_command(cmd)
@@ -105,26 +115,26 @@ def debug_handle_cmd(inline)
105
115
  bp = ary[1].gsub(/\|/,':') + ':' + ary[2].chomp
106
116
  if (cmd =~/^RM:/)
107
117
  $_breakpoint.delete(bp)
108
- puts "[Debugger] Breakpoint removed: #{bp}"
118
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoint removed: #{bp}")
109
119
  else
110
120
  $_breakpoint.store(bp,1)
111
- puts "[Debugger] Breakpoint added: #{bp}"
121
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoint added: #{bp}")
112
122
  end
113
123
  processed = true
114
124
  elsif cmd =~ /^RMALL/
115
125
  log_command(cmd)
116
126
  $_breakpoint.clear
117
- puts "[Debugger] All breakpoints removed"
127
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "All breakpoints removed")
118
128
  processed = true
119
129
  elsif cmd =~ /^ENABLE/
120
130
  log_command(cmd)
121
131
  $_breakpoints_enabled = true
122
- puts "[Debugger] Breakpoints enabled"
132
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoints enabled")
123
133
  processed = true
124
134
  elsif cmd =~ /^DISABLE/
125
135
  log_command(cmd)
126
136
  $_breakpoints_enabled = false
127
- puts "[Debugger] Breakpoints disabled"
137
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Breakpoints disabled")
128
138
  processed = true
129
139
  elsif inline and (cmd =~ /^STEPOVER/)
130
140
  $_s.write("STEPOVER start\n")
@@ -133,7 +143,7 @@ def debug_handle_cmd(inline)
133
143
  $_step_level = $_call_stack
134
144
  $_resumed = true
135
145
  wait = false
136
- puts "[Debugger] Step over"
146
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step over")
137
147
  processed = true
138
148
  elsif inline and (cmd =~ /^STEPRET/)
139
149
  log_command(cmd)
@@ -147,7 +157,7 @@ def debug_handle_cmd(inline)
147
157
  end
148
158
  $_resumed = true
149
159
  wait = false
150
- puts "[Debugger] Step return" + comment
160
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step return" + comment)
151
161
  processed = true
152
162
  elsif inline and (cmd =~ /^STEP/)
153
163
  log_command(cmd)
@@ -155,40 +165,40 @@ def debug_handle_cmd(inline)
155
165
  $_step_level = -1
156
166
  $_resumed = true
157
167
  wait = false
158
- puts "[Debugger] Step into"
168
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Step into")
159
169
  processed = true
160
170
  elsif inline and (cmd =~ /^CONT/)
161
171
  log_command(cmd)
162
172
  wait = false
163
173
  $_step = 0
164
174
  $_resumed = true
165
- puts "[Debugger] Resuming"
175
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Resuming")
166
176
  processed = true
167
177
  elsif cmd =~ /^SUSP/
168
178
  log_command(cmd)
169
179
  $_step = 4
170
180
  $_step_level = -1
171
181
  wait = true
172
- puts "[Debugger] Suspend"
182
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Suspend")
173
183
  processed = true
174
184
  elsif cmd =~ /^KILL/
175
185
  log_command(cmd)
176
- puts "[Debugger] Terminating..."
186
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Terminating...")
177
187
  processed = true
178
188
  System.exit
179
189
  elsif inline and (cmd =~ /^EVL?:/)
180
190
  log_command(cmd)
181
191
  processed = true
182
- puts "[Debugger] Calc evaluation..."
192
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Calc evaluation...")
183
193
  execute_cmd cmd.sub(/^EVL?:/,""), (cmd =~ /^EVL:/ ? true : false)
184
194
  elsif inline and (cmd =~ /^[GLCI]VARS/)
185
195
  log_command(cmd)
186
- puts "[Debugger] Get variables..."
196
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, "Get variables...")
187
197
  get_variables cmd
188
198
  processed = true
189
199
  elsif inline
190
200
  log_command(cmd)
191
- puts "[Debugger] Unknown command"
201
+ debugger_log(DEBUGGER_LOG_LEVEL_WARN, "Unknown command")
192
202
  processed = true
193
203
  end
194
204
  end
@@ -230,7 +240,7 @@ $_tracefunc = lambda{|event, file, line, id, bind, classname|
230
240
  fn = filename.gsub(/:/, '|')
231
241
  cl = classname.to_s.gsub(/:/,'#')
232
242
  $_s.write((step_stop ? DEBUGGER_STEP_TYPE[$_step-1] : "BP") + ":#{fn}:#{ln}:#{cl}:#{id}\n")
233
- puts "[Debugger] " + (step_stop ? DEBUGGER_STEP_COMMENT[$_step-1] : "Breakpoint") + " in #{fn} at #{ln}"
243
+ debugger_log(DEBUGGER_LOG_LEVEL_DEBUG, (step_stop ? DEBUGGER_STEP_COMMENT[$_step-1] : "Breakpoint") + " in #{fn} at #{ln}")
234
244
  $_step = 0
235
245
  $_step_level = -1
236
246
 
@@ -278,7 +288,7 @@ $_tracefunc = lambda{|event, file, line, id, bind, classname|
278
288
  $_s = nil
279
289
 
280
290
  begin
281
- puts "[Debugger] Opening connection"
291
+ debugger_log(DEBUGGER_LOG_LEVEL_INFO, "Opening connection")
282
292
  debug_host_env = ENV['RHOHOST']
283
293
  debug_port_env = ENV['rho_debug_port']
284
294
  debug_path_env = ENV['ROOT_PATH']
@@ -286,13 +296,13 @@ begin
286
296
  debug_host = (debug_host_env.nil? or debug_host_env == "") ? '127.0.0.1' : debug_host_env
287
297
  debug_port = (debug_port_env.nil? or debug_port_env == "") ? 9000 : debug_port_env
288
298
 
289
- puts "host=" + debug_host_env.to_s
290
- puts "port=" + debug_port_env.to_s
291
- puts "path=" + debug_path_env.to_s
299
+ debugger_log(DEBUGGER_LOG_LEVEL_INFO, "host=" + debug_host_env.to_s)
300
+ debugger_log(DEBUGGER_LOG_LEVEL_INFO, "port=" + debug_port_env.to_s)
301
+ debugger_log(DEBUGGER_LOG_LEVEL_INFO, "path=" + debug_path_env.to_s)
292
302
 
293
303
  $_s = timeout(30) { TCPSocket.open(debug_host, debug_port) }
294
304
 
295
- puts "[Debugger] Connected: " + $_s.to_s
305
+ debugger_log(DEBUGGER_LOG_LEVEL_WARN, "Connected: " + $_s.to_s)
296
306
  $_s.write("CONNECT\nHOST=" + debug_host.to_s + "\nPORT=" + debug_port.to_s + "\n")
297
307
 
298
308
  $_breakpoint = Hash.new
@@ -326,6 +336,6 @@ begin
326
336
  }
327
337
 
328
338
  rescue
329
- puts "[Debugger] Unable to open connection to debugger: " + $!.inspect
339
+ debugger_log(DEBUGGER_LOG_LEVEL_ERROR, "Unable to open connection to debugger: " + $!.inspect)
330
340
  $_s = nil
331
341
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhomobile-debug
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rhomobile
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-19 00:00:00 -07:00
18
+ date: 2011-10-20 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21