The first part of this is easy: the existing --trace flag traces all function calls. If printing to stdout is not what you need, you can at least grep for FLAG_trace in the code to see where you'd have to add your own code.The second part, logging all accessed properties, seems considerably harder -- I'm not sure how to do it. As a start, you can turn off ICs, and add code to the RUNTIME_FUNCTIONs you see in ic.cc. But that leaves a bunch of implicit property loads inside built-in functions, and those don't go through any common bottlenecks, so you'd have to find them all by hand. It's going to be a lot of work.
On Wed, Apr 15, 2020 at 9:20 AM <jun5...@gmail.com> wrote:Hello,For research reason, I need to log all the function names and properties accessed from javascript. Given the below example code from a webpage:<script>console.log('test");window.name="new name";</script>I'd like to capture that 'console.log()' and 'window.name' have been accessed.I'm quite new to v8 development. I've been struggling with the v8 source code in the chromium for a while.Could anyone save my life by giving me some hints or code snippets to get started?
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAKSzg3T0qJSaZjRY2gSW%3DnTbjCBV6NAEEXhN9z9WQUjt9URqrg%40mail.gmail.com.
That sounds like a scenario that shouldn't need any modification of V8 itself, since JavaScript gives you a lot of control to override how properties behave. Here's a (not very well-tested, and probably with bugs) function to enable logging of a particular property:
function enableLogging(obj, name) {var descriptor = Object.getOwnPropertyDescriptor(obj, name);if (!descriptor) {// Prop isn't on that object, maybe a prototype?obj = Object.getPrototypeOf(obj);if (!obj) {throw new Error("can't find property");}return enableLogging(obj, name);}if (!descriptor.configurable) {throw new Error("can't reconfigure property");}if (descriptor.get) {var originalGet = descriptor.get;descriptor.get = function () {var result = originalGet.apply(this, arguments);console.log("got " + name, result);return result;};}if (descriptor.set) {var originalSet = descriptor.set;descriptor.set = function (v) {console.log("setting " + name, v);return originalSet.apply(this, arguments);};}
if ("value" in descriptor) {
To unsubscribe from this group and stop receiving emails from it, send an email to v8-...@googlegroups.com.
I've been exploring ic.cc as suggested by Jakob, and I found that in this source code:MaybeHandle<Object> LoadIC::Load(Handle<Object> object, Handle<Name> name) {}The name variable carries the name of the property. For example, for the code below,<script>console.log('test");window.name="new name";</script>I will get "console" and "window" if I print the name variable. By any chance do you know how to get log of console.log and name of window.name?
What if capturing a few targeted functions and properties only? I have a list of them (~30 built-in JS APIs or properties), including window.name, document.cookie, localStorage.setItem(), etc.
Will this make life easier? If yes, should I still follow the same direction as you suggested?