Execution hooks

37 views
Skip to first unread message

Deepak Subramanian

unread,
Oct 22, 2015, 9:21:51 AM10/22/15
to v8-users
Hi,

When a JS is executing in v8. I would like to know which line it is.

eg.

function f1()
{
print - line 1 starting
expr;
print -line 1 ended
print- line 2 starting
expt;
print -line 2 ended
..
}

Any pointers are highly appreciated.


Thanks

Best Regards,
Deepak Subramanian

Ben Noordhuis

unread,
Oct 23, 2015, 7:38:37 AM10/23/15
to v8-u...@googlegroups.com
On Thu, Oct 22, 2015 at 3:21 PM, Deepak Subramanian
<subud...@gmail.com> wrote:
> Hi,
>
> When a JS is executing in v8. I would like to know which line it is.
>
> eg.
>
> function f1()
> {
> print - line 1 starting
> expr;
> print -line 1 ended
> print- line 2 starting
> expt;
> print -line 2 ended
> ..
> }
>
> Any pointers are highly appreciated.

You can step through the code using the debug API. Pass
--expose_debug_as=debug and check src/debug/debug.js for step actions.
You'll need to install a debug event listener first with
debug.Debug.setListener().

Deepak Subramanian

unread,
Oct 26, 2015, 5:06:59 AM10/26/15
to v8-users
Thanks a lot. 

Could you give me a very short sample of a debugListener.

Thanks again

Ben Noordhuis

unread,
Oct 26, 2015, 8:57:08 AM10/26/15
to v8-u...@googlegroups.com
On Mon, Oct 26, 2015 at 10:06 AM, Deepak Subramanian
<subud...@gmail.com> wrote:
> Could you give me a very short sample of a debugListener.

A very simple example:

// Flags: --expose_debug_as=debug
debug.Debug.setListener(listener);
debug.Debug.setBreakPoint(main);
main();

function listener(evt, state, info) {
if (evt !== debug.Debug.DebugEvent.Break) return;
state.prepareStep(); // defaults to StepIn
}

function main() {
// main program goes here
}
Reply all
Reply to author
Forward
0 new messages