google-cloud-debugger 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51d29e7310e1ea9e0f409ee2e2198d52af61c163
4
- data.tar.gz: 0e8474858473a49f70b06481f281c98b79e0bd70
3
+ metadata.gz: 652e6668d5e1d3e951c59d020e2d9469cc96bd8c
4
+ data.tar.gz: e9e11492a9245c6af29d709375d694c7d528946c
5
5
  SHA512:
6
- metadata.gz: a1e9da07abc025976a843eee2a93d545a09beedac8b7bfc34345ffd77e676ad17a9827fcafd285be65a05ed2d0adfd5380f2f06a12bcaa63b8cf7a000ac88eed
7
- data.tar.gz: b91cc538bbdc514d8105ae0220c482df52be13539c36ad3cb50bb4d0db071a54c146a687c5a34af40a36de04ddd012b283b26b2a309d0d30ef616450c27c33f9
6
+ metadata.gz: 0f18d03765b379d84dfd271ad0796b5aefc12f6e528e538d281b86cd76a1ba752f624a5a723cd8368930b2f57752113a71116bffb130c00522b274249f36766b
7
+ data.tar.gz: '00639952a36ba91f983bf974c26fedbfee09c3eaf0056323ae4a059857bfe860491515d29e6111369ee4aa091662f168a3dfdd63f8fd54730be58d43c804c8e6'
@@ -55,16 +55,26 @@ hash_get_keys(VALUE hash)
55
55
  * Check the Tracer#breakpoints_cache if any breakpoints match the given
56
56
  * tracepoint_path. Return 1 if found. Otherwise 0;
57
57
  */
58
- static VALUE
58
+ static int
59
59
  match_breakpoints_files(VALUE self, VALUE tracepoint_path)
60
60
  {
61
61
  int i;
62
- char *c_tracepoint_path = rb_string_value_cstr(&tracepoint_path);
62
+ char *c_tracepoint_path;
63
+ VALUE path_breakpoints_hash;
64
+ VALUE breakpoints_paths;
65
+ VALUE *c_breakpoints_paths;
66
+ int breakpoints_paths_len;
67
+
68
+ // Return 0 if the given path is Qnil
69
+ if(!RTEST(tracepoint_path)) {
70
+ return 0;
71
+ }
63
72
 
64
- VALUE path_breakpoints_hash = rb_iv_get(self, "@breakpoints_cache");
65
- VALUE breakpoints_paths = hash_get_keys(path_breakpoints_hash);
66
- VALUE *c_breakpoints_paths = RARRAY_PTR(breakpoints_paths);
67
- int breakpoints_paths_len = RARRAY_LEN(breakpoints_paths);
73
+ c_tracepoint_path = rb_string_value_cstr(&tracepoint_path);
74
+ path_breakpoints_hash = rb_iv_get(self, "@breakpoints_cache");
75
+ breakpoints_paths = hash_get_keys(path_breakpoints_hash);
76
+ c_breakpoints_paths = RARRAY_PTR(breakpoints_paths);
77
+ breakpoints_paths_len = RARRAY_LEN(breakpoints_paths);
68
78
 
69
79
  for (i = 0; i < breakpoints_paths_len; i++) {
70
80
  VALUE breakpoint_path = c_breakpoints_paths[i];
@@ -139,15 +149,28 @@ static void
139
149
  line_trace_callback(rb_event_flag_t event, VALUE data, VALUE obj, ID mid, VALUE klass)
140
150
  {
141
151
  VALUE self = data;
142
- const char *c_trace_path = rb_sourcefile();
143
- int c_trace_lineno = rb_sourceline();
152
+ VALUE trace_path;
153
+ int c_trace_lineno;
154
+ const char *c_trace_path;
144
155
  VALUE trace_binding;
145
156
  VALUE call_stack_bindings;
146
-
147
- VALUE matching_result = match_breakpoints(self, c_trace_path, c_trace_lineno);
148
-
149
157
  ID callers_id;
150
158
  ID breakpoints_hit_id;
159
+ VALUE matching_result;
160
+
161
+ c_trace_path = rb_sourcefile();
162
+ // Ensure C_trace_path is absolute path
163
+ trace_path = rb_str_new_cstr(c_trace_path);
164
+ trace_path = rb_file_expand_path(trace_path, Qnil);
165
+
166
+ if(!RTEST(trace_path)) {
167
+ return;
168
+ }
169
+
170
+ c_trace_path = rb_string_value_cstr(&trace_path);
171
+
172
+ c_trace_lineno = rb_sourceline();
173
+ matching_result = match_breakpoints(self, c_trace_path, c_trace_lineno);
151
174
 
152
175
  CONST_ID(callers_id, "callers");
153
176
  CONST_ID(breakpoints_hit_id, "breakpoints_hit");
@@ -163,7 +186,6 @@ line_trace_callback(rb_event_flag_t event, VALUE data, VALUE obj, ID mid, VALUE
163
186
 
164
187
  trace_binding = rb_binding_new();
165
188
  call_stack_bindings = rb_funcall(trace_binding, callers_id, 0);
166
- rb_ary_pop(call_stack_bindings);
167
189
 
168
190
  rb_funcall(self, breakpoints_hit_id, 2, matching_result, call_stack_bindings);
169
191
 
@@ -248,12 +270,13 @@ enable_line_trace_for_thread(VALUE self)
248
270
  static void
249
271
  return_trace_callback(void *data, rb_trace_arg_t *trace_arg)
250
272
  {
251
- VALUE match_found;
273
+ int match_found;
252
274
  VALUE self = (VALUE) data;
253
275
  VALUE caller_locations;
254
276
  VALUE *c_caller_locations;
255
277
  VALUE caller_location;
256
278
  VALUE caller_path;
279
+ int c_caller_locations_len;
257
280
 
258
281
  ID caller_locations_id;
259
282
  ID absolute_path_id;
@@ -261,16 +284,26 @@ return_trace_callback(void *data, rb_trace_arg_t *trace_arg)
261
284
  CONST_ID(caller_locations_id, "caller_locations");
262
285
  CONST_ID(absolute_path_id, "absolute_path");
263
286
 
264
- caller_locations = rb_funcall(rb_mKernel, caller_locations_id, 2, INT2NUM(0), INT2NUM(1));
287
+ caller_locations = rb_funcall(rb_mKernel, caller_locations_id, 2, INT2NUM(1), INT2NUM(1));
265
288
 
289
+
290
+ // Return if current execution stack is too shallow.
266
291
  if(!RTEST(caller_locations)) {
267
292
  return;
268
293
  }
269
294
 
270
295
  c_caller_locations = RARRAY_PTR(caller_locations);
296
+ c_caller_locations_len = RARRAY_LEN(caller_locations);
297
+
298
+ // Make sure caller locations has at least one entry.
299
+ if(c_caller_locations_len == 0) {
300
+ return;
301
+ }
302
+
271
303
  caller_location = c_caller_locations[0];
272
304
  caller_path = rb_funcall(caller_location, absolute_path_id, 0);
273
305
 
306
+ // Return if caller location doesn't have absolute path. (i.e. dynamically defined method)
274
307
  if(!RTEST(caller_path)) {
275
308
  return;
276
309
  }
@@ -367,11 +400,18 @@ file_tracepoint_callback(VALUE tracepoint, void *data)
367
400
  VALUE self = (VALUE) data;
368
401
  rb_trace_arg_t *tracepoint_arg = rb_tracearg_from_tracepoint(tracepoint);
369
402
  VALUE tracepoint_path = rb_tracearg_path(tracepoint_arg);
370
- VALUE match_found;
403
+ int match_found;
371
404
 
372
405
  if (!RB_TYPE_P(tracepoint_path, T_STRING))
373
406
  return;
374
407
 
408
+ // Ensure tracepoint_path is absolute path
409
+ tracepoint_path = rb_file_expand_path(tracepoint_path, Qnil);
410
+
411
+ if (!RTEST(tracepoint_path)) {
412
+ return;
413
+ }
414
+
375
415
  match_found = match_breakpoints_files(self, tracepoint_path);
376
416
 
377
417
  if (match_found) {
@@ -31,8 +31,8 @@ module Google
31
31
  # For more information on connecting to Google Cloud see the [Authentication
32
32
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
33
33
  #
34
- # @param [String] module_name Name for the debuggee application. Optional.
35
- # @param [String] module_version Version identifier for the debuggee
34
+ # @param [String] service_name Name for the debuggee application. Optional.
35
+ # @param [String] service_version Version identifier for the debuggee
36
36
  # application. Optional.
37
37
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
38
38
  # set of resources and operations that the connection can access. See
@@ -63,13 +63,14 @@ module Google
63
63
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
64
64
  # debugger = gcloud.debugger scope: platform_scope
65
65
  #
66
- def debugger module_name: nil, module_version: nil, scope: nil,
66
+ def debugger service_name: nil, service_version: nil, scope: nil,
67
67
  timeout: nil, client_config: nil
68
- Google::Cloud.debugger @project, @keyfile, module_name: module_name,
69
- module_version: module_version,
70
- scope: scope,
71
- timeout: (timeout || @timeout),
72
- client_config: client_config
68
+ Google::Cloud.debugger @project, @keyfile,
69
+ service_name: service_name,
70
+ service_version: service_version,
71
+ scope: scope,
72
+ timeout: (timeout || @timeout),
73
+ client_config: client_config
73
74
  end
74
75
 
75
76
  ##
@@ -84,8 +85,8 @@ module Google
84
85
  # service you are connecting to.
85
86
  # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
86
87
  # file path the file must be readable.
87
- # @param [String] module_name Name for the debuggee application. Optional.
88
- # @param [String] module_version Version identifier for the debuggee
88
+ # @param [String] service_name Name for the debuggee application. Optional.
89
+ # @param [String] service_version Version identifier for the debuggee
89
90
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
90
91
  # set of resources and operations that the connection can access. See
91
92
  # [Using OAuth 2.0 to Access Google
@@ -107,13 +108,13 @@ module Google
107
108
  #
108
109
  # debugger.start
109
110
  #
110
- def self.debugger project = nil, keyfile = nil, module_name: nil,
111
- module_version: nil, scope: nil, timeout: nil,
111
+ def self.debugger project = nil, keyfile = nil, service_name: nil,
112
+ service_version: nil, scope: nil, timeout: nil,
112
113
  client_config: nil
113
114
  require "google/cloud/debugger"
114
115
  Google::Cloud::Debugger.new project: project, keyfile: keyfile,
115
- module_name: module_name,
116
- module_version: module_version,
116
+ service_name: service_name,
117
+ service_version: service_version,
117
118
  scope: scope, timeout: timeout,
118
119
  client_config: client_config
119
120
  end
@@ -104,10 +104,10 @@ module Google
104
104
  # config.google_cloud.keyfile = "/path/to/keyfile.json"
105
105
  # # Google Cloud authentication json file for Stackdriver Debugger only
106
106
  # config.google_cloud.debugger.keyfile = "/path/to/debugger/keyfile.json"
107
- # # Stackdriver Debugger Agent module name identifier
108
- # config.google_cloud.debugger.module_name = "my-ruby-app"
109
- # # Stackdriver Debugger Agent module version identifier
110
- # config.google_cloud.debugger.module_version = "v1"
107
+ # # Stackdriver Debugger Agent service name identifier
108
+ # config.google_cloud.debugger.service_name = "my-ruby-app"
109
+ # # Stackdriver Debugger Agent service version identifier
110
+ # config.google_cloud.debugger.service_version = "v1"
111
111
  # ```
112
112
  #
113
113
  # See the {Google::Cloud::Debugger::Railtie} class for more information.
@@ -130,8 +130,8 @@ module Google
130
130
  # require "google/cloud/debugger"
131
131
  # use Google::Cloud::Debugger::Middleware project: "debugger-project-id",
132
132
  # keyfile: "/path/to/keyfile.json",
133
- # module_name: "my-ruby-app",
134
- # module_version: "v1"
133
+ # service_name: "my-ruby-app",
134
+ # service_version: "v1"
135
135
  # ```
136
136
  #
137
137
  # ### Using instrumentation with other Rack-based frameworks
@@ -343,8 +343,9 @@ module Google
343
343
  # service.
344
344
  # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud:
345
345
  # either the JSON data or the path to a readable file.
346
- # @param [String] module_name Name for the debuggee application. Optional.
347
- # @param [String] module_version Version identifier for the debuggee
346
+ # @param [String] service_name Name for the debuggee application.
347
+ # Optional.
348
+ # @param [String] service_version Version identifier for the debuggee
348
349
  # application. Optional.
349
350
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
350
351
  # the set of resources and operations that the connection can access.
@@ -361,19 +362,19 @@ module Google
361
362
  # debugger = Google::Cloud::Debugger.new
362
363
  # debugger.start
363
364
  #
364
- def self.new project: nil, keyfile: nil, module_name: nil,
365
- module_version: nil, scope: nil, timeout: nil,
365
+ def self.new project: nil, keyfile: nil, service_name: nil,
366
+ service_version: nil, scope: nil, timeout: nil,
366
367
  client_config: nil
367
368
  project ||= Debugger::Project.default_project
368
369
  project = project.to_s # Always cast to a string
369
- module_name ||= Debugger::Project.default_module_name
370
- module_name = module_name.to_s
371
- module_version ||= Debugger::Project.default_module_version
372
- module_version = module_version.to_s
370
+ service_name ||= Debugger::Project.default_service_name
371
+ service_name = service_name.to_s
372
+ service_version ||= Debugger::Project.default_service_version
373
+ service_version = service_version.to_s
373
374
 
374
375
  fail ArgumentError, "project is missing" if project.empty?
375
- fail ArgumentError, "module_name is missing" if module_name.empty?
376
- fail ArgumentError, "module_version is missing" if module_version.nil?
376
+ fail ArgumentError, "service_name is missing" if service_name.empty?
377
+ fail ArgumentError, "service_version is missing" if service_version.nil?
377
378
 
378
379
  credentials = Credentials.credentials_with_scope keyfile, scope
379
380
 
@@ -381,8 +382,8 @@ module Google
381
382
  Google::Cloud::Debugger::Service.new(
382
383
  project, credentials, timeout: timeout,
383
384
  client_config: client_config),
384
- module_name: module_name,
385
- module_version: module_version
385
+ service_name: service_name,
386
+ service_version: service_version
386
387
  )
387
388
  end
388
389
 
@@ -114,19 +114,19 @@ module Google
114
114
  # object
115
115
  # @param [Google::Cloud::Logging::Logger] logger The logger used
116
116
  # to write the results of Logpoints.
117
- # @param [String] module_name Name for the debuggee application.
118
- # @param [String] module_version Version identifier for the debuggee
117
+ # @param [String] service_name Name for the debuggee application.
118
+ # @param [String] service_version Version identifier for the debuggee
119
119
  # application.
120
120
  # @param [String] app_root Absolute path to the root directory of
121
121
  # the debuggee application. Default to Rack root.
122
122
  #
123
- def initialize service, logger: nil, module_name:, module_version:,
123
+ def initialize service, logger: nil, service_name:, service_version:,
124
124
  app_root: nil
125
125
  super()
126
126
 
127
127
  @service = service
128
- @debuggee = Debuggee.new service, module_name: module_name,
129
- module_version: module_version
128
+ @debuggee = Debuggee.new service, service_name: service_name,
129
+ service_version: service_version
130
130
  @tracer = Debugger::Tracer.new self
131
131
  @breakpoint_manager = BreakpointManager.new self, service
132
132
  @breakpoint_manager.on_breakpoints_change =
@@ -136,8 +136,7 @@ module Google
136
136
 
137
137
  @logger = logger || default_logger
138
138
 
139
- @app_root = app_root
140
- @app_root ||= Rack::Directory.new("").root if defined? Rack::Directory
139
+ init_app_root app_root
141
140
 
142
141
  # Agent actor thread needs to force exit immediately.
143
142
  set_cleanup_options timeout: 0
@@ -199,6 +198,16 @@ module Google
199
198
 
200
199
  private
201
200
 
201
+ ##
202
+ # @private Initialize `@app_root` instance variable.
203
+ def init_app_root app_root = nil
204
+ app_root ||= Google::Cloud::Debugger.configure.app_root
205
+ app_root ||= Rack::Directory.new("").root if defined? Rack::Directory
206
+ app_root ||= Dir.pwd
207
+
208
+ @app_root = app_root
209
+ end
210
+
202
211
  ##
203
212
  # @private Callback function for breakpoint manager when any updates
204
213
  # happens to the list of active breakpoints
@@ -271,7 +271,8 @@ module Google
271
271
  ##
272
272
  # Get the file path of this breakpoint
273
273
  # @example
274
- # breakpoint = Breakpoint.new nil, "path/to/file.rb"
274
+ # breakpoint =
275
+ # Google::Cloud::Debugger::Breakpoint.new nil, "path/to/file.rb"
275
276
  # breakpoint.path #=> "path/to/file.rb"
276
277
  # @return [String] The file path for this breakpoint
277
278
  def path
@@ -281,7 +282,8 @@ module Google
281
282
  ##
282
283
  # Get the line number of this breakpoint
283
284
  # @example
284
- # breakpoint = Breakpoint.new nil, "path/to/file.rb", 11
285
+ # breakpoint =
286
+ # Google::Cloud::Debugger::Breakpoint.new nil, "path/to/file.rb", 11
285
287
  # breakpoint.line #=> 11
286
288
  # @return [Integer] The line number for this breakpoint
287
289
  def line
@@ -107,6 +107,7 @@ module Google
107
107
  Complex,
108
108
  FalseClass,
109
109
  Float,
110
+ Integer,
110
111
  MatchData,
111
112
  NilClass,
112
113
  Numeric,
@@ -120,7 +121,7 @@ module Google
120
121
  Enumerable,
121
122
  Math
122
123
  ].concat(
123
- RUBY_VERSION.to_f >= 2.4 ? [Integer] : [Bignum, Fixnum]
124
+ RUBY_VERSION.to_f >= 2.4 ? [] : [Bignum, Fixnum]
124
125
  ).freeze
125
126
 
126
127
  ##
@@ -934,7 +935,15 @@ module Google
934
935
  # Otherwise raise Google::Cloud::Debugger::MutationError error.
935
936
  #
936
937
  def trace_func_callback receiver, mid
937
- meth = receiver.method mid
938
+ meth = nil
939
+ begin
940
+ meth = receiver.method mid
941
+ rescue
942
+ raise Google::Cloud::Debugger::EvaluationError.new(
943
+ PROHIBITED_OPERATION_MSG,
944
+ Google::Cloud::Debugger::EvaluationError::META_PROGRAMMING)
945
+ end
946
+
938
947
  yarv_instructions = RubyVM::InstructionSequence.disasm meth
939
948
 
940
949
  return if immutable_yarv_instructions?(yarv_instructions,
@@ -998,9 +1007,10 @@ module Google
998
1007
  # @private Custom error type used to identify evaluation error during
999
1008
  # breakpoint expression evaluation.
1000
1009
  class EvaluationError < StandardError
1001
- UNKNOWN_CAUSE = Object.new.freeze
1002
- PROHIBITED_YARV = Object.new.freeze
1003
- PROHIBITED_C_FUNC = Object.new.freeze
1010
+ UNKNOWN_CAUSE = :unknown_cause
1011
+ PROHIBITED_YARV = :prohibited_yarv
1012
+ PROHIBITED_C_FUNC = :prohibited_c_func
1013
+ META_PROGRAMMING = :meta_programming
1004
1014
 
1005
1015
  attr_reader :mutation_cause
1006
1016
 
@@ -57,9 +57,10 @@ module Google
57
57
  end
58
58
 
59
59
  ##
60
- # @private Check the file from given file path is a ".rb" file
60
+ # @private Check the file from given file path is a Ruby file
61
61
  def self.verify_file_type file_path
62
- File.extname(file_path) == ".rb"
62
+ File.extname(file_path) == ".rb" ||
63
+ File.basename(file_path) == "config.ru"
63
64
  rescue
64
65
  false
65
66
  end
@@ -101,6 +101,10 @@ module Google
101
101
  # full.
102
102
  BUFFER_FULL_MSG = "Buffer full. Use an expression to see more data."
103
103
 
104
+ ##
105
+ # @private Error message when variable can't be converted.
106
+ FAIL_CONVERSION_MSG = "Error: Unable to inspect value"
107
+
104
108
  ##
105
109
  # @private Name of the variable, if any.
106
110
  # @return [String]
@@ -174,42 +178,46 @@ module Google
174
178
  # conversions.
175
179
  #
176
180
  # @example Simple variable conversion
177
- # x = 3
178
- # var = Variable.from_rb_var x, name: "x"
181
+ # x = 3.0
182
+ # var = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \
183
+ # x, name: "x"
179
184
  # var.name #=> "x"
180
- # var.value #=> "3"
181
- # var.type #=> "Integer"
185
+ # var.value #=> "3.0"
186
+ # var.type #=> "Float"
182
187
  #
183
188
  # @example Hash conversion
184
- # hash = {a: 1, b: :two}
185
- # var = Variable.from_rb_var hash, name: "hash"
189
+ # hash = {a: 1.0, b: :two}
190
+ # var = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \
191
+ # hash, name: "hash"
186
192
  # var.name #=> "hash"
187
193
  # var.type #=> "Hash"
188
194
  # var.members[0].name #=> "a"
189
- # var.members[0].value #=> "1"
190
- # var.members[0].type #=> "Integer"
195
+ # var.members[0].value #=> "1.0"
196
+ # var.members[0].type #=> "Float"
191
197
  # var.members[1].name #=> "b"
192
- # var.members[1].value #=> "two"
198
+ # var.members[1].value #=> ":two"
193
199
  # var.members[1].type #=> "Symbol"
194
200
  #
195
201
  # @example Custom compound variable conversion
196
- # foo = Foo.new(a: 1, b: []) #=> #<Foo:0x0000 @a: 1, @b: []>
197
- # var_table = VariableTable.new
198
- # var = Variable.from_rb_var foo, name: "foo"
202
+ # foo = Foo.new(a: 1.0, b: [])
203
+ # foo.inspect #=> "#<Foo:0xXXXXXX @a=1.0, @b=[]>"
204
+ # var = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \
205
+ # foo, name: "foo"
199
206
  # var.name #=> "foo"
200
207
  # var.type #=> "Foo"
201
208
  # var.members[0].name #=> "@a"
202
- # var.members[0].value #=> "1"
203
- # var.members[0].type #=> "Integer"
209
+ # var.members[0].value #=> "1.0"
210
+ # var.members[0].type #=> "Float"
204
211
  # var.members[1].name #=> "@b"
205
212
  # var.members[1].value #=> "[]"
206
213
  # var.members[1].type #=> "Array"
207
214
  #
208
215
  # @example Use variable table for shared compound variables
209
- # hash = {a: 1}
216
+ # hash = {a: 1.0}
210
217
  # ary = [hash, hash]
211
- # var_table = VariableTable.new
212
- # var = Variable.from_rb_var ary, name: "ary", var_table: var_table
218
+ # var_table = Google::Cloud::Debugger::Breakpoint::VariableTable.new
219
+ # var = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \
220
+ # ary, name: "ary", var_table: var_table
213
221
  # var.name #=> "ary"
214
222
  # var.var_table_index #=> 0
215
223
  # var_table[0].type #=> "Array"
@@ -219,8 +227,8 @@ module Google
219
227
  # var_table[0].members[1].var_table_index #=> 1
220
228
  # var_table[1].type #=> "Hash"
221
229
  # var_table[1].members[0].name #=> "a"
222
- # var_table[1].members[0].type #=> "Integer"
223
- # var_table[1].members[0].value #=> "1"
230
+ # var_table[1].members[0].type #=> "Float"
231
+ # var_table[1].members[0].value #=> "1.0"
224
232
  #
225
233
  # @return [Google::Cloud::Debugger::Breakpoint::Variable] Converted
226
234
  # variable.
@@ -239,14 +247,27 @@ module Google
239
247
  from_compound_var source, name: name, depth: depth,
240
248
  var_table: var_table, limit: limit
241
249
  else
242
- new.tap do |var|
243
- var.name = name.to_s if name
244
- var.type = source.class.to_s
245
- limit = deduct_limit limit,
246
- var.name.to_s.bytesize + var.type.bytesize
247
- var.value = truncate_value source.inspect, limit
248
- var.source_var = source
249
- end
250
+ from_primitive_var source, name: name, limit: limit
251
+ end
252
+ rescue
253
+ new.tap do |var|
254
+ var.name = name.to_s if name
255
+ var.set_error_state FAIL_CONVERSION_MSG
256
+ var.source_var = source
257
+ end
258
+ end
259
+
260
+ ##
261
+ # @private Helper method that converts primitive variables.
262
+ def self.from_primitive_var source, name: nil, limit: nil
263
+ new.tap do |var|
264
+ var.name = name.to_s if name
265
+ var.type = source.class.to_s
266
+ var.source_var = source
267
+ limit = deduct_limit limit,
268
+ var.name.to_s.bytesize + var.type.bytesize
269
+
270
+ var.value = truncate_value source.inspect, limit
250
271
  end
251
272
  end
252
273
 
@@ -344,8 +365,7 @@ module Google
344
365
  var.members << Variable.new.tap do |last_var|
345
366
  last_var.set_error_state \
346
367
  "Only first #{i} items were captured. Use in " \
347
- "an expression to see all items.",
348
- refers_to: StatusMessage::VARIABLE_VALUE
368
+ "an expression to see all items."
349
369
  end
350
370
  break
351
371
  else
@@ -368,8 +388,7 @@ module Google
368
388
  var.var_table = var_table
369
389
  var.var_table_index = 0
370
390
  else
371
- var.set_error_state BUFFER_FULL_MSG,
372
- refers_to: StatusMessage::VARIABLE_VALUE
391
+ var.set_error_state BUFFER_FULL_MSG
373
392
  end
374
393
  end
375
394
  end
@@ -382,7 +401,8 @@ module Google
382
401
 
383
402
  private_class_method :add_compound_members,
384
403
  :add_shared_compound_var,
385
- :add_member_vars, :compound_var?,
404
+ :add_member_vars,
405
+ :compound_var?,
386
406
  :deduct_limit
387
407
 
388
408
  ##
@@ -452,7 +472,7 @@ module Google
452
472
 
453
473
  ##
454
474
  # Set this variable to an error state by setting the status field
455
- def set_error_state message, refers_to: StatusMessage::UNSPECIFIED
475
+ def set_error_state message, refers_to: StatusMessage::VARIABLE_VALUE
456
476
  @status = StatusMessage.new.tap do |s|
457
477
  s.is_error = true
458
478
  s.refers_to = refers_to
@@ -141,7 +141,8 @@ module Google
141
141
  # Evaluates a hit breakpoint, and submit the breakpoint to
142
142
  # Transmitter if this breakpoint is evaluated successfully.
143
143
  #
144
- # See {Breakpoint#evaluate} for evaluation details.
144
+ # See {Snappoint#evaluate} and {Logpoint#evaluate} for evaluation
145
+ # details.
145
146
  #
146
147
  # @param [Google::Cloud::Debugger::Breakpoint] breakpoint The breakpoint
147
148
  # to be evaluated
@@ -48,12 +48,12 @@ module Google
48
48
  ##
49
49
  # Name for the debuggee application
50
50
  # @return [String]
51
- attr_reader :module_name
51
+ attr_reader :service_name
52
52
 
53
53
  ##
54
54
  # Version identifier for the debuggee application
55
55
  # @return [String]
56
- attr_reader :module_version
56
+ attr_reader :service_version
57
57
 
58
58
  ##
59
59
  # Registered Debuggee ID. Set by Stackdriver Debugger service when
@@ -63,10 +63,10 @@ module Google
63
63
 
64
64
  ##
65
65
  # @private Construct a new instance of Debuggee
66
- def initialize service, module_name:, module_version:
66
+ def initialize service, service_name:, service_version:
67
67
  @service = service
68
- @module_name = module_name
69
- @module_version = module_version
68
+ @service_name = service_name
69
+ @service_version = service_version
70
70
  @computed_uniquifier = nil
71
71
  @id = nil
72
72
  end
@@ -142,8 +142,8 @@ module Google
142
142
  def labels
143
143
  {
144
144
  "projectid" => String(project_id),
145
- "module" => String(module_name),
146
- "version" => String(module_version)
145
+ "module" => String(service_name),
146
+ "version" => String(service_version)
147
147
  }
148
148
  end
149
149
 
@@ -155,10 +155,10 @@ module Google
155
155
  # @return [String] A compact debuggee description.
156
156
  #
157
157
  def description
158
- if module_version.nil? || module_version.empty?
159
- module_name
158
+ if service_version.nil? || service_version.empty?
159
+ service_name
160
160
  else
161
- "#{module_name} - #{module_version}"
161
+ "#{service_name} - #{service_version}"
162
162
  end
163
163
  end
164
164
 
@@ -29,7 +29,7 @@ module Google
29
29
  ##
30
30
  # Evaluate the breakpoint unless it's already marked as completed.
31
31
  # Store evaluted expressions and stack frame variables in
32
- # @evaluated_expressions and @evaluated_log_message.
32
+ # `@evaluated_expressions` and `@evaluated_log_message`.
33
33
  #
34
34
  # @param [Array<Binding>] call_stack_bindings An array of Ruby Binding
35
35
  # objects, from the call stack that leads to the triggering of the
@@ -69,8 +69,9 @@ module Google
69
69
  # @private Format log message by interpolate expressions.
70
70
  #
71
71
  # @example
72
- # Evaluator.format_log_message("Hello $0",
73
- # ["World"]) #=> "Hello World"
72
+ # log_point = Google::Cloud::Debugger::Logpoint.new
73
+ # log_point.format_message(
74
+ # "Hello $0", ["World"]) #=> "Hello \"World\""
74
75
  #
75
76
  # @param [String] message_format The message with with
76
77
  # expression placeholders such as `$0`, `$1`, etc.
@@ -51,8 +51,8 @@ module Google
51
51
  @debugger =
52
52
  Debugger.new(project: configuration.project_id,
53
53
  keyfile: configuration.keyfile,
54
- module_name: configuration.module_name,
55
- module_version: configuration.module_version)
54
+ service_name: configuration.service_name,
55
+ service_version: configuration.service_version)
56
56
 
57
57
  @debugger.agent.quota_manager =
58
58
  Google::Cloud::Debugger::RequestQuotaManager.new
@@ -104,10 +104,10 @@ module Google
104
104
  configuration.keyfile = kwargs[:keyfile] ||
105
105
  configuration.keyfile
106
106
 
107
- configuration.module_name = kwargs[:module_name] ||
108
- configuration.module_name
109
- configuration.module_version = kwargs[:module_version] ||
110
- configuration.module_version
107
+ configuration.service_name = kwargs[:service_name] ||
108
+ configuration.service_name
109
+ configuration.service_version = kwargs[:service_version] ||
110
+ configuration.service_version
111
111
 
112
112
  init_default_config
113
113
  end
@@ -119,9 +119,9 @@ module Google
119
119
  Debugger::Project.default_project
120
120
  configuration.keyfile ||= Cloud.configure.keyfile
121
121
 
122
- configuration.module_name ||= Debugger::Project.default_module_name
123
- configuration.module_version ||=
124
- Debugger::Project.default_module_version
122
+ configuration.service_name ||= Debugger::Project.default_service_name
123
+ configuration.service_version ||=
124
+ Debugger::Project.default_service_version
125
125
  end
126
126
 
127
127
  ##
@@ -50,10 +50,10 @@ module Google
50
50
 
51
51
  ##
52
52
  # @private Creates a new Project instance.
53
- def initialize service, module_name:, module_version:
53
+ def initialize service, service_name:, service_version:
54
54
  @service = service
55
- @agent = Agent.new service, module_name: module_name,
56
- module_version: module_version
55
+ @agent = Agent.new service, service_name: service_name,
56
+ service_version: service_version
57
57
  end
58
58
 
59
59
  ##
@@ -85,17 +85,17 @@ module Google
85
85
  end
86
86
 
87
87
  ##
88
- # @private Default module name identifier.
89
- def self.default_module_name
90
- ENV["DEBUGGER_MODULE_NAME"] ||
88
+ # @private Default service name identifier.
89
+ def self.default_service_name
90
+ ENV["DEBUGGER_SERVICE_NAME"] ||
91
91
  Google::Cloud.env.app_engine_service_id ||
92
92
  "ruby-app"
93
93
  end
94
94
 
95
95
  ##
96
- # @private Default module version identifier.
97
- def self.default_module_version
98
- ENV["DEBUGGER_MODULE_VERSION"] ||
96
+ # @private Default service version identifier.
97
+ def self.default_service_version
98
+ ENV["DEBUGGER_SERVICE_VERSION"] ||
99
99
  Google::Cloud.env.app_engine_service_version ||
100
100
  ""
101
101
  end
@@ -23,8 +23,9 @@ module Google
23
23
  # Google::Cloud::Debugger::Railtie automatically adds the
24
24
  # Google::Cloud::Debugger::Middleware to Rack in a Rails environment.
25
25
  #
26
- # The Middleware is only added when certain conditions are met. See
27
- # {Railtie.use_debugger?} for detail.
26
+ # The Middleware is only added when the
27
+ # `Google::Cloud.configure.use_debugger` setting is true or Rails is
28
+ # in the production environment.
28
29
  #
29
30
  # When loaded, the Google::Cloud::Debugger::Middleware will be inserted
30
31
  # after the Rack::ETag Middleware, which is top of the Rack stack, closest
@@ -62,7 +63,7 @@ module Google
62
63
  # configuration. Also consolidate the `use_debugger` setting by
63
64
  # verifying credentials and Rails environment. The `use_debugger`
64
65
  # setting will be true if credentials are valid, and the setting is
65
- # manually set to true or Rails is in production environment.
66
+ # manually set to true or Rails is in the production environment.
66
67
  #
67
68
  # @param [Rails::Railtie::Configuration] config The
68
69
  # Rails.application.config
@@ -85,7 +86,7 @@ module Google
85
86
  end
86
87
 
87
88
  # Otherwise set use_debugger to true if Rails is running in
88
- # production
89
+ # the production environment
89
90
  Google::Cloud.configure.use_debugger ||= Rails.env.production?
90
91
  end
91
92
 
@@ -100,8 +101,8 @@ module Google
100
101
  Debugger.configure do |config|
101
102
  config.project_id ||= dbg_config.project_id || gcp_config.project_id
102
103
  config.keyfile ||= dbg_config.keyfile || gcp_config.keyfile
103
- config.module_name ||= dbg_config.module_name
104
- config.module_version ||= dbg_config.module_version
104
+ config.service_name ||= dbg_config.service_name
105
+ config.service_version ||= dbg_config.service_version
105
106
  end
106
107
  end
107
108
 
@@ -110,8 +111,8 @@ module Google
110
111
  def self.init_default_config
111
112
  config = Debugger.configure
112
113
  config.project_id ||= Debugger::Project.default_project
113
- config.module_name ||= Debugger::Project.default_module_name
114
- config.module_version ||= Debugger::Project.default_module_version
114
+ config.service_name ||= Debugger::Project.default_service_name
115
+ config.service_version ||= Debugger::Project.default_service_version
115
116
  end
116
117
 
117
118
  ##
@@ -100,7 +100,7 @@ module Google
100
100
  # rules. If the expressions do any write operations, the evaluations
101
101
  # abort and show an error message in place of the real result.
102
102
  #
103
- # @param [Binding] binding The binding object from the context
103
+ # @param [Binding] bind The binding object from the context
104
104
  #
105
105
  def eval_expressions bind
106
106
  @evaluated_expressions = []
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Debugger
19
- VERSION = "0.27.0"
19
+ VERSION = "0.28.0"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heng Xiong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller