google-cloud-debugger 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +18 -0
- data/AUTHENTICATION.md +178 -0
- data/CHANGELOG.md +233 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/INSTRUMENTATION.md +115 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +266 -0
- data/TROUBLESHOOTING.md +31 -0
- data/ext/google/cloud/debugger/debugger_c/debugger.c +31 -0
- data/ext/google/cloud/debugger/debugger_c/debugger.h +26 -0
- data/ext/google/cloud/debugger/debugger_c/evaluator.c +115 -0
- data/ext/google/cloud/debugger/debugger_c/evaluator.h +25 -0
- data/ext/google/cloud/debugger/debugger_c/extconf.rb +22 -0
- data/ext/google/cloud/debugger/debugger_c/tracer.c +542 -0
- data/ext/google/cloud/debugger/debugger_c/tracer.h +25 -0
- data/lib/google-cloud-debugger.rb +181 -0
- data/lib/google/cloud/debugger.rb +259 -0
- data/lib/google/cloud/debugger/agent.rb +255 -0
- data/lib/google/cloud/debugger/backoff.rb +70 -0
- data/lib/google/cloud/debugger/breakpoint.rb +443 -0
- data/lib/google/cloud/debugger/breakpoint/evaluator.rb +1099 -0
- data/lib/google/cloud/debugger/breakpoint/source_location.rb +74 -0
- data/lib/google/cloud/debugger/breakpoint/stack_frame.rb +109 -0
- data/lib/google/cloud/debugger/breakpoint/status_message.rb +93 -0
- data/lib/google/cloud/debugger/breakpoint/validator.rb +92 -0
- data/lib/google/cloud/debugger/breakpoint/variable.rb +595 -0
- data/lib/google/cloud/debugger/breakpoint/variable_table.rb +96 -0
- data/lib/google/cloud/debugger/breakpoint_manager.rb +311 -0
- data/lib/google/cloud/debugger/credentials.rb +50 -0
- data/lib/google/cloud/debugger/debuggee.rb +222 -0
- data/lib/google/cloud/debugger/debuggee/app_uniquifier_generator.rb +76 -0
- data/lib/google/cloud/debugger/logpoint.rb +98 -0
- data/lib/google/cloud/debugger/middleware.rb +200 -0
- data/lib/google/cloud/debugger/project.rb +110 -0
- data/lib/google/cloud/debugger/rails.rb +174 -0
- data/lib/google/cloud/debugger/request_quota_manager.rb +95 -0
- data/lib/google/cloud/debugger/service.rb +88 -0
- data/lib/google/cloud/debugger/snappoint.rb +208 -0
- data/lib/google/cloud/debugger/tracer.rb +137 -0
- data/lib/google/cloud/debugger/transmitter.rb +199 -0
- data/lib/google/cloud/debugger/version.rb +22 -0
- metadata +353 -0
data/LOGGING.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Enabling gRPC Logging
|
2
|
+
|
3
|
+
To enable logging for this library, set the logger for the underlying
|
4
|
+
[gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
|
5
|
+
that you set may be a Ruby stdlib
|
6
|
+
[`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
|
7
|
+
shown below, or a
|
8
|
+
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
9
|
+
that will write logs to [Stackdriver
|
10
|
+
Logging](https://cloud.google.com/logging/). See
|
11
|
+
[grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
|
12
|
+
and the gRPC
|
13
|
+
[spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
|
14
|
+
for additional information.
|
15
|
+
|
16
|
+
Configuring a Ruby stdlib logger:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "logger"
|
20
|
+
|
21
|
+
module MyLogger
|
22
|
+
LOGGER = Logger.new $stderr, level: Logger::WARN
|
23
|
+
def logger
|
24
|
+
LOGGER
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
29
|
+
module GRPC
|
30
|
+
extend MyLogger
|
31
|
+
end
|
32
|
+
```
|
data/OVERVIEW.md
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
# Stackdriver Debugger
|
2
|
+
|
3
|
+
Stackdriver Debugger is a feature of the Google Cloud Platform that lets you
|
4
|
+
inspect the state of an application at any code location without using logging
|
5
|
+
statements and without stopping or slowing down your applications. Your users
|
6
|
+
are not impacted during debugging. Using the production debugger you can capture
|
7
|
+
the local variables and call stack and link it back to a specific line location
|
8
|
+
in your source code. You can use this to analyze the production state of your
|
9
|
+
application and understand the behavior of your code in production.
|
10
|
+
|
11
|
+
For general information about Stackdriver Debugger, read [Stackdriver Debugger
|
12
|
+
Documentation](https://cloud.google.com/debugger/docs/).
|
13
|
+
|
14
|
+
The Stackdriver Debugger Ruby library, `google-cloud-debugger`, provides:
|
15
|
+
|
16
|
+
* Easy-to-use debugger instrumentation that reports state data, such as value of
|
17
|
+
program variables and the call stack, to Stackdriver Debugger when the code at
|
18
|
+
a breakpoint location is executed in your Ruby application. See the
|
19
|
+
[instrumenting your app](#instrumenting-your-app) section for how to debug
|
20
|
+
your application, in both development and production.
|
21
|
+
* An idiomatic Ruby API for registerying debuggee application, and querying or
|
22
|
+
manipulating breakpoints in registered Ruby debuggee application. See
|
23
|
+
[Debugger API](#stackdriver-debugger-api) section for an introduction to
|
24
|
+
Stackdriver Debugger API.
|
25
|
+
|
26
|
+
## Instrumenting Your App
|
27
|
+
|
28
|
+
This instrumentation library provides the following features to help you debug
|
29
|
+
your applications in production:
|
30
|
+
|
31
|
+
* Automatic application registration. It facilitates multiple running instances
|
32
|
+
of same version of application when hosted in production.
|
33
|
+
* A background debugger agent that runs side-by-side with your application that
|
34
|
+
automatically collects state data when code is executed at breakpoint
|
35
|
+
locations.
|
36
|
+
* A Rack middleware and Railtie that automatically manages the debugger agent
|
37
|
+
for Ruby on Rails and other Rack-based Ruby applications.
|
38
|
+
|
39
|
+
When this library is configured in your running application, and the source code
|
40
|
+
and breakpoints are setup through the Google Cloud Console, You'll be able to
|
41
|
+
[interact](https://cloud.google.com/debugger/docs/debugging) with your
|
42
|
+
application in real time through the [Stackdriver Debugger
|
43
|
+
UI](https://console.cloud.google.com/debug?_ga=1.84295834.280814654.1476313407).
|
44
|
+
This library also integrates with Google App Engine Flexible to make debuggee
|
45
|
+
application configuration more seemless.
|
46
|
+
|
47
|
+
Note that when no breakpoints are created, the debugger agent consumes very
|
48
|
+
little resource and has no interference with the running application. Once
|
49
|
+
breakpoints are created and depends on where the breakpoints are located, the
|
50
|
+
debugger agent may add a little latency onto each request. The application
|
51
|
+
performance will be back to normal after all breakpoints are finished being
|
52
|
+
evaluated. Be aware the more breakpoints are created, or the harder to reach the
|
53
|
+
breakpoints, the more resource the debugger agent would need to consume.
|
54
|
+
|
55
|
+
### Using instrumentation with Ruby on Rails
|
56
|
+
|
57
|
+
To install application instrumentation in your Ruby on Rails app, add this gem,
|
58
|
+
`google-cloud-debugger`, to your Gemfile and update your bundle. Then add the
|
59
|
+
following line to your `config/application.rb` file:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require "google/cloud/debugger/rails"
|
63
|
+
```
|
64
|
+
|
65
|
+
This will load a Railtie that automatically integrates with the Rails framework
|
66
|
+
by injecting a Rack middleware. The Railtie also takes in the following Rails
|
67
|
+
configuration as parameter of the debugger agent initialization:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Explicitly enable or disable Stackdriver Debugger Agent
|
71
|
+
config.google_cloud.use_debugger = true
|
72
|
+
# Shared Google Cloud Platform project identifier
|
73
|
+
config.google_cloud.project_id = "gcloud-project"
|
74
|
+
# Google Cloud Platform project identifier for Stackdriver Debugger only
|
75
|
+
config.google_cloud.debugger.project_id = "debugger-project"
|
76
|
+
# Shared Google Cloud authentication json file
|
77
|
+
config.google_cloud.keyfile = "/path/to/keyfile.json"
|
78
|
+
# Google Cloud authentication json file for Stackdriver Debugger only
|
79
|
+
config.google_cloud.debugger.keyfile = "/path/to/debugger/keyfile.json"
|
80
|
+
# Stackdriver Debugger Agent service name identifier
|
81
|
+
config.google_cloud.debugger.service_name = "my-ruby-app"
|
82
|
+
# Stackdriver Debugger Agent service version identifier
|
83
|
+
config.google_cloud.debugger.service_version = "v1"
|
84
|
+
```
|
85
|
+
|
86
|
+
See the {Google::Cloud::Debugger::Railtie} class for more information.
|
87
|
+
|
88
|
+
### Using instrumentation with Sinatra
|
89
|
+
|
90
|
+
To install application instrumentation in your Sinatra app, add this gem,
|
91
|
+
`google-cloud-debugger`, to your Gemfile and update your bundle. Then add the
|
92
|
+
following lines to your main application Ruby file:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require "google/cloud/debugger"
|
96
|
+
use Google::Cloud::Debugger::Middleware
|
97
|
+
```
|
98
|
+
|
99
|
+
This will install the debugger middleware in your application.
|
100
|
+
|
101
|
+
Configuration parameters may also be passed in as arguments to Middleware.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require "google/cloud/debugger"
|
105
|
+
use Google::Cloud::Debugger::Middleware project: "debugger-project-id",
|
106
|
+
keyfile: "/path/to/keyfile.json",
|
107
|
+
service_name: "my-ruby-app",
|
108
|
+
service_version: "v1"
|
109
|
+
```
|
110
|
+
|
111
|
+
### Using instrumentation with other Rack-based frameworks
|
112
|
+
|
113
|
+
To install application instrumentation in an app using another Rack-based web
|
114
|
+
framework, add this gem, `google-cloud-debugger`, to your Gemfile and update
|
115
|
+
your bundle. Then add install the debugger middleware in your middleware stack.
|
116
|
+
In most cases, this means adding these lines to your `config.ru` Rack
|
117
|
+
configuration file:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
require "google/cloud/debugger"
|
121
|
+
use Google::Cloud::Debugger::Middleware
|
122
|
+
```
|
123
|
+
|
124
|
+
Some web frameworks have an alternate mechanism for modifying the middleware
|
125
|
+
stack. Consult your web framework's documentation for more information.
|
126
|
+
|
127
|
+
### The Stackdriver diagnostics suite
|
128
|
+
|
129
|
+
The debugger library is part of the Stackdriver diagnostics suite, which also
|
130
|
+
includes error reporting, log analysis, and tracing analysis. If you include the
|
131
|
+
`stackdriver` gem in your Gemfile, this debugger library will be included
|
132
|
+
automatically. In addition, if you include the `stackdriver` gem in an
|
133
|
+
application using Ruby On Rails, the Railties will be installed automatically.
|
134
|
+
See the documentation for the "stackdriver" gem for more details.
|
135
|
+
|
136
|
+
## Stackdriver Debugger API
|
137
|
+
|
138
|
+
This library also includes an easy to use Ruby client for the Stackdriver
|
139
|
+
Debugger API. This API provides calls to register debuggee application, as well
|
140
|
+
as creating or modifying breakpoints.
|
141
|
+
|
142
|
+
For further information on the Debugger API, see
|
143
|
+
{Google::Cloud::Debugger::Project}
|
144
|
+
|
145
|
+
### Registering debuggee application
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
require "google/cloud/debugger/v2"
|
149
|
+
|
150
|
+
controller_client = Google::Cloud::Debugger::V2::Controller::Client.new
|
151
|
+
debuggee = Google::Cloud::Debugger::V2::Debuggee.new
|
152
|
+
response = controller_client.register_debuggee debuggee: debuggee
|
153
|
+
debuggee_id = response.debuggee.id
|
154
|
+
```
|
155
|
+
See [Stackdriver Debugger Debuggee
|
156
|
+
doc](https://cloud.google.com/debugger/api/reference/rpc/google.devtools.clouddebugger.v2#google.devtools.clouddebugger.v2.Debuggee)
|
157
|
+
on fields necessary for registerying a debuggee.
|
158
|
+
|
159
|
+
Upon successful registration, the response debuggee object will contain a
|
160
|
+
debuggee_id that's later needed to interact with the other Stackdriver Debugger
|
161
|
+
API.
|
162
|
+
|
163
|
+
### List Active Breakpoints
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
require "google/cloud/debugger/v2"
|
167
|
+
|
168
|
+
controller_client = Google::Cloud::Debugger::V2::Controller::Client.new
|
169
|
+
|
170
|
+
debuggee_id = ''
|
171
|
+
response = controller_client.list_active_breakpoints debuggee_id: debuggee_id
|
172
|
+
breakpoints = response.breakpoints
|
173
|
+
```
|
174
|
+
|
175
|
+
### Update Active Breakpoint
|
176
|
+
|
177
|
+
Users can send custom snapshots for active breakpoints using this API.
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
require "google/cloud/debugger/v2"
|
181
|
+
|
182
|
+
controller_client = Google::Cloud::Debugger::V2::Controller::Client.new
|
183
|
+
debuggee_id = ''
|
184
|
+
breakpoint = Google::Cloud::Debugger::V2::Breakpoint.new
|
185
|
+
response = controller_client.update_active_breakpoint(
|
186
|
+
debuggee_id: debuggee_id, breakpoint: breakpoint)
|
187
|
+
```
|
188
|
+
|
189
|
+
See [Stackdriver Debugger Breakpoint
|
190
|
+
doc](https://cloud.google.com/debugger/api/reference/rpc/google.devtools.clouddebugger.v2#google.devtools.clouddebugger.v2.Breakpoint)
|
191
|
+
for all available fields for breakpoint.
|
192
|
+
|
193
|
+
### Set Breakpoint
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
require "google/cloud/debugger/v2"
|
197
|
+
|
198
|
+
debugger_client = Google::Cloud::Debugger::V2::Debugger::Client.new
|
199
|
+
debuggee_id = ''
|
200
|
+
breakpoint = Google::Cloud::Debugger::V2::Breakpoint.new
|
201
|
+
client_version = ''
|
202
|
+
response = debugger_client.set_breakpoint(
|
203
|
+
debuggee_id: debuggee_id, breakpoint: breakpoint,
|
204
|
+
client_version: client_version)
|
205
|
+
```
|
206
|
+
|
207
|
+
See [Stackdriver Debugger Breakpoint
|
208
|
+
doc](https://cloud.google.com/debugger/api/reference/rpc/google.devtools.clouddebugger.v2#google.devtools.clouddebugger.v2.Breakpoint)
|
209
|
+
for fields needed to specify breakpoint location.
|
210
|
+
|
211
|
+
### Get Breakpoint
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
require "google/cloud/debugger/v2"
|
215
|
+
|
216
|
+
debugger_client = Google::Cloud::Debugger::V2::Debugger::Client.new
|
217
|
+
debuggee_id = ''
|
218
|
+
breakpoint_id = ''
|
219
|
+
client_version = ''
|
220
|
+
response = debugger_client.get_breakpoint(
|
221
|
+
debuggee_id: debuggee_id, breakpoint_id: breakpoint_id,
|
222
|
+
client_version: client_version)
|
223
|
+
```
|
224
|
+
|
225
|
+
### Delete Breakpoint
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
require "google/cloud/debugger/v2"
|
229
|
+
|
230
|
+
debugger_client = Google::Cloud::Debugger::V2::Debugger::Client.new
|
231
|
+
debuggee_id = ''
|
232
|
+
breakpoint_id = ''
|
233
|
+
client_version = ''
|
234
|
+
debugger_client.delete_breakpoint(
|
235
|
+
debuggee_id: debuggee_id, breakpoint_id: breakpoint_id,
|
236
|
+
client_version: client_version)
|
237
|
+
```
|
238
|
+
|
239
|
+
### List Breakpoints
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
require "google/cloud/debugger/v2"
|
243
|
+
|
244
|
+
debugger_client = Google::Cloud::Debugger::V2::Debugger::Client.new
|
245
|
+
debuggee_id = ''
|
246
|
+
client_version = ''
|
247
|
+
response = debugger_client.list_breakpoints(
|
248
|
+
debuggee_id: debuggee_id, client_version: client_version)
|
249
|
+
```
|
250
|
+
|
251
|
+
### List Debuggees
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
require "google/cloud/debugger/v2"
|
255
|
+
|
256
|
+
debugger_client = Google::Cloud::Debugger::V2::Debugger::Client.new
|
257
|
+
project = ''
|
258
|
+
client_version = ''
|
259
|
+
response = debugger_client.list_debuggees(
|
260
|
+
project: project, client_version: client_version)
|
261
|
+
```
|
262
|
+
|
263
|
+
## Additional information
|
264
|
+
|
265
|
+
Stackdriver Debugger can be configured to use gRPC's logging. To learn more, see
|
266
|
+
the {file:LOGGING.md Logging guide}.
|
data/TROUBLESHOOTING.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Troubleshooting
|
2
|
+
|
3
|
+
## Where can I get more help?
|
4
|
+
|
5
|
+
### Ask the Community
|
6
|
+
|
7
|
+
If you have a question about how to use a Google Cloud client library in your
|
8
|
+
project or are stuck in the Developer's console and don't know where to turn,
|
9
|
+
it's possible your questions have already been addressed by the community.
|
10
|
+
|
11
|
+
First, check out the appropriate tags on StackOverflow:
|
12
|
+
- [`google-cloud-platform+ruby+debugger`][so-ruby]
|
13
|
+
|
14
|
+
Next, try searching through the issues on GitHub:
|
15
|
+
|
16
|
+
- [`api:debugger` issues][gh-search-ruby]
|
17
|
+
|
18
|
+
Still nothing?
|
19
|
+
|
20
|
+
### Ask the Developers
|
21
|
+
|
22
|
+
If you're experiencing a bug with the code, or have an idea for how it can be
|
23
|
+
improved, *please* create a new issue on GitHub so we can talk about it.
|
24
|
+
|
25
|
+
- [New issue][gh-ruby]
|
26
|
+
|
27
|
+
[so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+debugger
|
28
|
+
|
29
|
+
[gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+debugger%22
|
30
|
+
|
31
|
+
[gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2017 Google Inc. All rights reserved.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "ruby/ruby.h"
|
18
|
+
#include "debugger.h"
|
19
|
+
|
20
|
+
static VALUE mGoogle, mCloud, mDebugger;
|
21
|
+
|
22
|
+
void
|
23
|
+
Init_debugger_c()
|
24
|
+
{
|
25
|
+
mGoogle = rb_define_module("Google");
|
26
|
+
mCloud = rb_define_module_under(mGoogle, "Cloud");
|
27
|
+
mDebugger = rb_define_module_under(mCloud, "Debugger");
|
28
|
+
|
29
|
+
Init_tracer(mDebugger);
|
30
|
+
Init_evaluator(mDebugger);
|
31
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2017 Google Inc. All rights reserved.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef GOOGLE_CLOUD_RUBY_DEBUGGER_H_
|
18
|
+
#define GOOGLE_CLOUD_RUBY_DEBUGGER_H_
|
19
|
+
|
20
|
+
#include "tracer.h"
|
21
|
+
#include "evaluator.h"
|
22
|
+
|
23
|
+
void
|
24
|
+
Init_debugger_c();
|
25
|
+
|
26
|
+
#endif // GOOGLE_CLOUD_RUBY_DEBUGGER_H_
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2017 Google Inc. All rights reserved.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "ruby/ruby.h"
|
18
|
+
#include "ruby/debug.h"
|
19
|
+
#include "evaluator.h"
|
20
|
+
|
21
|
+
static void
|
22
|
+
eval_trace_callback(void *data, rb_trace_arg_t *trace_arg)
|
23
|
+
{
|
24
|
+
rb_event_flag_t event;
|
25
|
+
VALUE evaluator;
|
26
|
+
VALUE klass;
|
27
|
+
VALUE obj;
|
28
|
+
VALUE method_id;
|
29
|
+
ID trace_func_cb_id;
|
30
|
+
ID trace_c_func_cb_id;
|
31
|
+
|
32
|
+
CONST_ID(trace_func_cb_id, "trace_func_callback");
|
33
|
+
CONST_ID(trace_c_func_cb_id, "trace_c_func_callback");
|
34
|
+
|
35
|
+
event = rb_tracearg_event_flag(trace_arg);
|
36
|
+
evaluator = (VALUE)data;
|
37
|
+
obj = rb_tracearg_self(trace_arg);
|
38
|
+
method_id = rb_tracearg_method_id(trace_arg);
|
39
|
+
klass = rb_tracearg_defined_class(trace_arg);
|
40
|
+
|
41
|
+
if (event & RUBY_EVENT_CALL) {
|
42
|
+
rb_funcall(evaluator, trace_func_cb_id, 3, obj, klass, method_id);
|
43
|
+
}
|
44
|
+
if (event & RUBY_EVENT_C_CALL) {
|
45
|
+
rb_funcall(evaluator, trace_c_func_cb_id, 3, obj, klass, method_id);
|
46
|
+
}
|
47
|
+
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
rb_disable_method_trace_for_thread(VALUE self)
|
53
|
+
{
|
54
|
+
VALUE current_thread;
|
55
|
+
VALUE thread_variables_hash;
|
56
|
+
VALUE trace_set;
|
57
|
+
ID locals_id;
|
58
|
+
ID eval_trace_thread_id;
|
59
|
+
VALUE eval_trace_thread_flag;
|
60
|
+
|
61
|
+
CONST_ID(locals_id, "locals");
|
62
|
+
CONST_ID(eval_trace_thread_id, "gcloud_eval_trace_set");
|
63
|
+
eval_trace_thread_flag = ID2SYM(eval_trace_thread_id);
|
64
|
+
|
65
|
+
current_thread = rb_thread_current();
|
66
|
+
thread_variables_hash = rb_ivar_get(current_thread, locals_id);
|
67
|
+
trace_set = rb_hash_aref(thread_variables_hash, eval_trace_thread_flag);
|
68
|
+
|
69
|
+
if (RTEST(trace_set)) {
|
70
|
+
rb_thread_remove_event_hook(current_thread, (rb_event_hook_func_t)eval_trace_callback);
|
71
|
+
rb_hash_aset(thread_variables_hash, eval_trace_thread_flag, Qfalse);
|
72
|
+
}
|
73
|
+
|
74
|
+
return Qnil;
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
rb_enable_method_trace_for_thread(VALUE self)
|
79
|
+
{
|
80
|
+
VALUE current_thread;
|
81
|
+
VALUE thread_variables_hash;
|
82
|
+
VALUE trace_set;
|
83
|
+
VALUE evaluator;
|
84
|
+
ID current_evaluator_id;
|
85
|
+
ID locals_id;
|
86
|
+
ID eval_trace_thread_id;
|
87
|
+
VALUE eval_trace_thread_flag;
|
88
|
+
|
89
|
+
CONST_ID(current_evaluator_id, "current");
|
90
|
+
CONST_ID(locals_id, "locals");
|
91
|
+
CONST_ID(eval_trace_thread_id, "gcloud_eval_trace_set");
|
92
|
+
eval_trace_thread_flag = ID2SYM(eval_trace_thread_id);
|
93
|
+
|
94
|
+
current_thread = rb_thread_current();
|
95
|
+
thread_variables_hash = rb_ivar_get(current_thread, locals_id);
|
96
|
+
trace_set = rb_hash_aref(thread_variables_hash, eval_trace_thread_flag);
|
97
|
+
evaluator = rb_funcall(self, current_evaluator_id, 0);
|
98
|
+
|
99
|
+
if (!RTEST(trace_set)) {
|
100
|
+
rb_thread_add_event_hook2(current_thread, (rb_event_hook_func_t)eval_trace_callback, RUBY_EVENT_CALL | RUBY_EVENT_C_CALL, evaluator, RUBY_EVENT_HOOK_FLAG_RAW_ARG | RUBY_EVENT_HOOK_FLAG_SAFE);
|
101
|
+
rb_hash_aset(thread_variables_hash, eval_trace_thread_flag, Qtrue);
|
102
|
+
}
|
103
|
+
|
104
|
+
return Qnil;
|
105
|
+
}
|
106
|
+
|
107
|
+
void
|
108
|
+
Init_evaluator(VALUE mDebugger)
|
109
|
+
{
|
110
|
+
VALUE cBreakpoint = rb_define_class_under(mDebugger, "Breakpoint", rb_cObject);
|
111
|
+
VALUE cEvaluator = rb_define_class_under(cBreakpoint, "Evaluator", rb_cObject);
|
112
|
+
|
113
|
+
rb_define_module_function(cEvaluator, "enable_method_trace_for_thread", rb_enable_method_trace_for_thread, 0);
|
114
|
+
rb_define_module_function(cEvaluator, "disable_method_trace_for_thread", rb_disable_method_trace_for_thread, 0);
|
115
|
+
}
|