You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ruby: observed loading of node:internal/modules/run_main
288
+
Ruby: observed loading of <...>/agent-fib.js
289
+
Three is the result 3
290
+
```
260
291
292
+
To track variable values, create `agent.rb` script:
293
+
```ruby
294
+
insight.on("enter", -> (ctx, frame) {
295
+
puts("minusOne #{frame.n}")
296
+
}, {
297
+
roots:true,
298
+
rootNameFilter:"minusOne",
299
+
at: {
300
+
sourcePath:".*agent-fib.js"
301
+
}
302
+
})
303
+
```
304
+
This code uses a declarative specification of source location introduced in GraalVM 22.2. Use a dynamic `sourceFilter` with older GraalVM versions:
305
+
```ruby
261
306
insight.on("enter", -> (ctx, frame) {
262
307
puts("minusOne #{frame.n}")
263
308
}, {
264
309
roots:true,
265
310
rootNameFilter:"minusOne",
266
311
sourceFilter:-> (src) {
267
-
return src.name =="agent-fib.js"
312
+
return src.name ==Dir.pwd+"/agent-fib.js"
268
313
}
269
314
})
270
315
```
271
316
272
-
The above Ruby script example prints out value of variable `n` when a function `minusOne` in the `agent-fib.js` program is called.
273
-
Launch a Node.js application and instrument it with the Ruby script:
274
-
317
+
The above Ruby script example prints out value of variable `n` when a function `minusOne` in the [agent-fib.js](../../../vm/tests/all/agentscript/agent-fib.js) program is called:
@@ -462,6 +497,58 @@ GraalVM Insight `enter` and `return` hooks can only modify existing variables.
462
497
They cannot introduce new ones.
463
498
Attempts to do so yield an exception.
464
499
500
+
## Insight to a Specific Location
501
+
502
+
To get to variables at a specific code location, the `at` object may have not only one of the mandatory source specifications:
503
+
a `sourcePath` property with the regular expression matching the source file path, or `sourceURI` property with string representation of the source URI.
504
+
There can also be an optional `line` and/or `column` specified. Let's have a `distance.js` source file:
505
+
```js
506
+
(function(x, y) {
507
+
let x2 = x*x;
508
+
let y2 = y*y;
509
+
let d =Math.sqrt(x2 + y2);
510
+
for (let i =0; i < d; i++) {
511
+
// ...
512
+
}
513
+
return d;
514
+
})(3, 4);
515
+
```
516
+
517
+
Then we can apply following `distance-trace.js` insight script to get values of variables:
0 commit comments