google-cloud-debugger 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +201 -0
  4. data/README.md +56 -0
  5. data/ext/google/cloud/debugger/debugger_c/debugger.c +31 -0
  6. data/ext/google/cloud/debugger/debugger_c/debugger.h +26 -0
  7. data/ext/google/cloud/debugger/debugger_c/evaluator.c +78 -0
  8. data/ext/google/cloud/debugger/debugger_c/evaluator.h +25 -0
  9. data/ext/google/cloud/debugger/debugger_c/extconf.rb +22 -0
  10. data/ext/google/cloud/debugger/debugger_c/tracer.c +478 -0
  11. data/ext/google/cloud/debugger/debugger_c/tracer.h +31 -0
  12. data/lib/google-cloud-debugger.rb +121 -0
  13. data/lib/google/cloud/debugger.rb +379 -0
  14. data/lib/google/cloud/debugger/agent.rb +204 -0
  15. data/lib/google/cloud/debugger/async_actor.rb +290 -0
  16. data/lib/google/cloud/debugger/breakpoint.rb +382 -0
  17. data/lib/google/cloud/debugger/breakpoint/evaluator.rb +1113 -0
  18. data/lib/google/cloud/debugger/breakpoint/source_location.rb +75 -0
  19. data/lib/google/cloud/debugger/breakpoint/stack_frame.rb +109 -0
  20. data/lib/google/cloud/debugger/breakpoint/variable.rb +304 -0
  21. data/lib/google/cloud/debugger/breakpoint_manager.rb +217 -0
  22. data/lib/google/cloud/debugger/credentials.rb +41 -0
  23. data/lib/google/cloud/debugger/debuggee.rb +204 -0
  24. data/lib/google/cloud/debugger/debuggee/app_uniquifier_generator.rb +78 -0
  25. data/lib/google/cloud/debugger/middleware.rb +77 -0
  26. data/lib/google/cloud/debugger/project.rb +135 -0
  27. data/lib/google/cloud/debugger/rails.rb +141 -0
  28. data/lib/google/cloud/debugger/service.rb +130 -0
  29. data/lib/google/cloud/debugger/tracer.rb +165 -0
  30. data/lib/google/cloud/debugger/transmitter.rb +129 -0
  31. data/lib/google/cloud/debugger/v2.rb +15 -0
  32. data/lib/google/cloud/debugger/v2/controller2_client.rb +299 -0
  33. data/lib/google/cloud/debugger/v2/controller2_client_config.json +43 -0
  34. data/lib/google/cloud/debugger/v2/debugger2_client.rb +378 -0
  35. data/lib/google/cloud/debugger/v2/debugger2_client_config.json +53 -0
  36. data/lib/google/cloud/debugger/v2/doc/google/devtools/clouddebugger/v2/data.rb +441 -0
  37. data/lib/google/cloud/debugger/v2/doc/google/devtools/clouddebugger/v2/debugger.rb +151 -0
  38. data/lib/google/cloud/debugger/v2/doc/google/devtools/source/v1/source_context.rb +161 -0
  39. data/lib/google/cloud/debugger/v2/doc/google/protobuf/timestamp.rb +81 -0
  40. data/lib/google/cloud/debugger/version.rb +22 -0
  41. data/lib/google/devtools/clouddebugger/v2/controller_pb.rb +47 -0
  42. data/lib/google/devtools/clouddebugger/v2/controller_services_pb.rb +97 -0
  43. data/lib/google/devtools/clouddebugger/v2/data_pb.rb +105 -0
  44. data/lib/google/devtools/clouddebugger/v2/debugger_pb.rb +74 -0
  45. data/lib/google/devtools/clouddebugger/v2/debugger_services_pb.rb +64 -0
  46. data/lib/google/devtools/source/v1/source_context_pb.rb +89 -0
  47. metadata +300 -0
@@ -0,0 +1,75 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Debugger
19
+ class Breakpoint
20
+ ##
21
+ # # SourceLocation
22
+ #
23
+ # Additional information about the source code location that's
24
+ # associated with the breakpoint.
25
+ #
26
+ # See also {Breakpoint#location}.
27
+ #
28
+ class SourceLocation
29
+ ##
30
+ # Path to the source file within the source context of the target
31
+ # binary.
32
+ attr_accessor :path
33
+
34
+ ##
35
+ # Line inside the file. The first line in the file has the value 1.
36
+ attr_accessor :line
37
+
38
+ ##
39
+ # @private Create an empty SourceLocation object.
40
+ def initialize
41
+ end
42
+
43
+ ##
44
+ # @private New Google::Cloud::Debugger::Breakpoint::SourceLocation
45
+ # from a Google::Devtools::Clouddebugger::V2::SourceLocation object.
46
+ def self.from_grpc grpc
47
+ return new if grpc.nil?
48
+ new.tap do |o|
49
+ o.path = grpc.path
50
+ o.line = grpc.line
51
+ end
52
+ end
53
+
54
+ ##
55
+ # @private Determines if the SourceLocation has any data.
56
+ def empty?
57
+ path.nil? &&
58
+ line.nil?
59
+ end
60
+
61
+ ##
62
+ # @private Exports the SourceLocation to a
63
+ # Google::Devtools::Clouddebugger::V2::SourceLocation object.
64
+ def to_grpc
65
+ return nil if empty?
66
+ Google::Devtools::Clouddebugger::V2::SourceLocation.new(
67
+ path: path.to_s,
68
+ line: line
69
+ )
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "google/cloud/debugger/breakpoint/source_location"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Debugger
21
+ class Breakpoint
22
+ ##
23
+ # # StackFrame
24
+ #
25
+ # Represents a stack frame context.
26
+ #
27
+ # See also {Breakpoint#stack_frames}.
28
+ #
29
+ class StackFrame
30
+ ##
31
+ # Demangled function name at the call site.
32
+ attr_accessor :function
33
+
34
+ ##
35
+ # Source location of the call site.
36
+ attr_accessor :location
37
+
38
+ ##
39
+ # Set of arguments passed to this function. Note that this might not
40
+ # be populated for all stack frames.
41
+ attr_accessor :arguments
42
+
43
+ ##
44
+ # Set of local variables at the stack frame location. Note that this
45
+ # might not be populated for all stack frames.
46
+ attr_accessor :locals
47
+
48
+ ##
49
+ # @private Create an empty StackFrame object.
50
+ def initialize
51
+ @location = SourceLocation.new
52
+ @arguments = []
53
+ @locals = []
54
+ end
55
+
56
+ ##
57
+ # @private New Google::Cloud::Debugger::Breakpoint::SourceLocation
58
+ # from a Google::Devtools::Clouddebugger::V2::SourceLocation object.
59
+ def self.from_grpc grpc
60
+ new.tap do |o|
61
+ o.function = grpc.function
62
+ o.location = SourceLocation.from_grpc grpc.location
63
+ o.arguments = Variable.from_grpc_list grpc.arguments
64
+ o.locals = Variable.from_grpc_list grpc.locals
65
+ end
66
+ end
67
+
68
+ ##
69
+ # @private Determines if the StackFrame has any data.
70
+ def empty?
71
+ function.nil? &&
72
+ location.nil? &&
73
+ arguments.nil? &&
74
+ locals.nil?
75
+ end
76
+
77
+ ##
78
+ # @private Exports the StackFrame to a
79
+ # Google::Devtools::Clouddebugger::V2::StackFrame object.
80
+ def to_grpc
81
+ return nil if empty?
82
+ Google::Devtools::Clouddebugger::V2::StackFrame.new(
83
+ function: function.to_s,
84
+ location: location.to_grpc,
85
+ arguments: arguments_to_grpc,
86
+ locals: locals_to_grpc
87
+ )
88
+ end
89
+
90
+ private
91
+
92
+ ##
93
+ # @private Exports the StackFrame arguments to an array of
94
+ # Google::Devtools::Clouddebugger::V2::Variable objects.
95
+ def arguments_to_grpc
96
+ arguments.nil? ? [] : arguments.map(&:to_grpc)
97
+ end
98
+
99
+ ##
100
+ # @private Exports the StackFrame locals to an array of
101
+ # Google::Devtools::Clouddebugger::V2::Variable objects.
102
+ def locals_to_grpc
103
+ locals.nil? ? [] : locals.map(&:to_grpc)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,304 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Debugger
19
+ class Breakpoint
20
+ ##
21
+ # # Variable
22
+ #
23
+ # Represents a variable or an argument possibly of a compound object
24
+ # type. Note how the following variables are represented:
25
+ #
26
+ # A simple Variable:
27
+ # ```ruby
28
+ # x = 5
29
+ # # Captured variable:
30
+ # # { name: "x", value: "5", type: "Integer" }
31
+ # ```
32
+ #
33
+ # A Compound Variable:
34
+ # ```ruby
35
+ # class T
36
+ # attr_accessor :m1, :m2
37
+ # ...
38
+ # end
39
+ # v = T.new(1, "2")
40
+ # # Captured variable:
41
+ # # {
42
+ # # name: "v",
43
+ # # type: "T",
44
+ # # members: [
45
+ # # { name: "@m1", value: "1", type: "Integer" },
46
+ # # { name: "@m2", value: "2", type: "String" }
47
+ # # ]
48
+ # # }
49
+ # ```
50
+ #
51
+ # A Hash object:
52
+ # ```ruby
53
+ # hash = { a: 1, b: :two }
54
+ # # Captured variable:
55
+ # # {
56
+ # # name: "hash",
57
+ # # type: "Hash",
58
+ # # members: [
59
+ # # { name: "a", value: "1", type: "Integer" },
60
+ # # { name: "b", value: ":2", type: "Symbol" }
61
+ # # ]
62
+ # # }
63
+ # ```
64
+ #
65
+ # An Array object:
66
+ # ```ruby
67
+ # ary = [1, nil]
68
+ # # Captured variable:
69
+ # # {
70
+ # # name: "ary",
71
+ # # type: "Array",
72
+ # # members: [
73
+ # # { name: "[0]", value: "1", type: "Integer" },
74
+ # # { name: "[1]", value: "nil", type: "NilClass" }
75
+ # # ]
76
+ # # }
77
+ # ```
78
+ #
79
+ class Variable
80
+ ##
81
+ # Max depth to convert on compound variables
82
+ MAX_DEPTH = 3
83
+
84
+ ##
85
+ # Max number of member variables to evaluate in compound variables
86
+ MAX_MEMBERS = 10
87
+
88
+ ##
89
+ # Max length on variable inspect results. Truncate extra and replace
90
+ # with ellipsis.
91
+ MAX_STRING_LENGTH = 260
92
+
93
+ ##
94
+ # @private Name of the variable, if any.
95
+ # @return [String]
96
+ attr_accessor :name
97
+
98
+ ##
99
+ # @private Simple value of the variable.
100
+ # @return [String]
101
+ attr_accessor :value
102
+
103
+ ##
104
+ # @private Variable type (e.g. MyClass). If the variable is split with
105
+ # var_table_index, type goes next to value.
106
+ # @return [String]
107
+ attr_accessor :type
108
+
109
+ ##
110
+ # @private Members contained or pointed to by the variable.
111
+ # @return [Array<Variable>]
112
+ attr_accessor :members
113
+
114
+ ##
115
+ # @private Status associated with the variable. This field will
116
+ # usually stay unset. A status of a single variable only applies to
117
+ # that variable or expression. The rest of breakpoint data still
118
+ # remains valid. Variables might be reported in error state even when
119
+ # breakpoint is not in final state.
120
+ # The message may refer to variable name with refers_to set to
121
+ # VARIABLE_NAME. Alternatively refers_to will be set to
122
+ # VARIABLE_VALUE. In either case variable value and members will be
123
+ # unset.
124
+ # TODO: Implement variable status
125
+ # attr_accessor :status
126
+
127
+ ##
128
+ # @private Create an empty Variable object.
129
+ def initialize
130
+ @members = []
131
+ end
132
+
133
+ ##
134
+ # Convert a Ruby variable into a
135
+ # Google::Cloud::Debugger::Breakpoint::Variable object.
136
+ #
137
+ # @param [Any] source Source Ruby variable to convert from
138
+ # @param [String] name Name of the varaible
139
+ # @param [Integer] depth Number of levels to evaluate in compound
140
+ # variables. Default to
141
+ # {Google::Cloud::Debugger::Breakpoint::Variable::MAX_DEPTH}
142
+ #
143
+ # @example
144
+ # x = 3
145
+ # var = Variable.from_rb_var x, name: "x"
146
+ # var.name #=> "x"
147
+ # var.value #=> "3"
148
+ # var.type #=> "Integer"
149
+ #
150
+ # @example
151
+ # hash = {a: 1, b: :two}
152
+ # var = Variable.from_rb_var hash, name: "hash"
153
+ # var.name #=> "hash"
154
+ # var.type #=> "Hash"
155
+ # var.members[0].name #=> "a"
156
+ # var.members[0].value #=> "1"
157
+ # var.members[0].type #=> "Integer"
158
+ # var.members[1].name #=> "b"
159
+ # var.members[1].value #=> "two"
160
+ # var.members[1].type #=> "Symbol"
161
+ #
162
+ # @example
163
+ # foo = Foo.new(a: 1, b: []) #=> #<Foo:0x0000 @a: 1, @b: []>
164
+ # var = Variable.from_rb_var foo, name: "foo"
165
+ # var.name #=> "foo"
166
+ # var.type #=> "Foo"
167
+ # var.members[0].name #=> "@a"
168
+ # var.members[0].value #=> "1"
169
+ # var.members[0].type #=> "Integer"
170
+ # var.members[1].name #=> "@b"
171
+ # var.members[1].value #=> "[]"
172
+ # var.members[1].type #=> "Array"
173
+ #
174
+ # @return [Google::Cloud::Debugger::Breakpoint::Variable] Converted
175
+ # variable.
176
+ #
177
+ def self.from_rb_var source, name: nil, depth: MAX_DEPTH
178
+ return source if source.is_a? Variable
179
+
180
+ # If source is a non-empty Array or Hash, or source has instance
181
+ # variables, evaluate source as a compound variable.
182
+ if (((source.is_a?(Hash) || source.is_a?(Array)) &&
183
+ !source.empty?) || !source.instance_variables.empty?) &&
184
+ depth > 0
185
+ from_compound_var source, name: name, depth: depth
186
+ else
187
+ var = Variable.new
188
+ var.name = name.to_s if name
189
+ var.type = source.class.to_s
190
+ var.value = truncate_value(source.inspect)
191
+
192
+ var
193
+ end
194
+ end
195
+
196
+ ##
197
+ # @private Helper method that converts compound variables.
198
+ def self.from_compound_var source, name: nil, depth: MAX_DEPTH
199
+ return source if source.is_a? Variable
200
+ var = Variable.new
201
+ var.name = name.to_s if name
202
+ var.type = source.class.to_s
203
+
204
+ case source
205
+ when Hash
206
+ add_compound_members var, source do |(k, v)|
207
+ from_rb_var(v, name: k, depth: depth - 1)
208
+ end
209
+ when Array
210
+ add_compound_members var, source do |el, i|
211
+ from_rb_var(el, name: "[#{i}]", depth: depth - 1)
212
+ end
213
+ else
214
+ add_compound_members var, source.instance_variables do |var_name|
215
+ instance_var = source.instance_variable_get var_name
216
+ from_rb_var(instance_var, name: var_name, depth: depth - 1)
217
+ end
218
+ end
219
+ var
220
+ end
221
+
222
+ ##
223
+ # @private Help interate through collection of member variables for
224
+ # compound variables.
225
+ def self.add_compound_members var, members
226
+ members.each_with_index do |el, i|
227
+ if i < MAX_MEMBERS
228
+ var.members << yield(el, i)
229
+ else
230
+ var.members << Variable.new.tap do |last_var|
231
+ last_var.value =
232
+ "(Only first #{MAX_MEMBERS} items were captured)"
233
+ end
234
+ break
235
+ end
236
+ end
237
+ end
238
+
239
+ ##
240
+ # @private New Google::Cloud::Debugger::Breakpoint::Variable
241
+ # from a Google::Devtools::Clouddebugger::V2::Variable object.
242
+ def self.from_grpc grpc
243
+ return new if grpc.nil?
244
+ new.tap do |o|
245
+ o.name = grpc.name
246
+ o.value = grpc.value
247
+ o.type = grpc.type
248
+ o.members = from_grpc_list grpc.members
249
+ end
250
+ end
251
+
252
+ ##
253
+ # @private New array of Google::Cloud::Debugger::Breakpoint::Variable
254
+ # from an array of Google::Devtools::Clouddebugger::V2::Variable
255
+ # objects.
256
+ def self.from_grpc_list grpc_list
257
+ return [] if grpc_list.nil?
258
+ grpc_list.map { |var_grpc| from_grpc var_grpc }
259
+ end
260
+
261
+ ##
262
+ # @private Limit string to MAX_STRING_LENTH. Replace extra characters
263
+ # with ellipsis
264
+ def self.truncate_value str
265
+ str.gsub(/(.{#{MAX_STRING_LENGTH - 3}}).+/, '\1...')
266
+ end
267
+ private_class_method :add_compound_members, :truncate_value
268
+
269
+ ##
270
+ # @private Determines if the Variable has any data.
271
+ def empty?
272
+ name.nil? &&
273
+ value.nil? &&
274
+ type.nil? &&
275
+ members.nil?
276
+ # TODO: Add status when implementing variable status
277
+ end
278
+
279
+ ##
280
+ # @private Exports the Variable to a
281
+ # Google::Devtools::Clouddebugger::V2::Variable object.
282
+ def to_grpc
283
+ return nil if empty?
284
+ Google::Devtools::Clouddebugger::V2::Variable.new(
285
+ name: name.to_s,
286
+ value: value.to_s,
287
+ type: type.to_s,
288
+ members: members_to_grpc || []
289
+ )
290
+ end
291
+
292
+ private
293
+
294
+ ##
295
+ # @private Exports the Variable members to an array of
296
+ # Google::Devtools::Clouddebugger::V2::Variable objects.
297
+ def members_to_grpc
298
+ members.nil? ? nil : members.map(&:to_grpc)
299
+ end
300
+ end
301
+ end
302
+ end
303
+ end
304
+ end