about javascript debugger object exposed with --expose_debug_as=<name>

292 views
Skip to first unread message

Camilo Aguilar

unread,
May 3, 2012, 5:30:35 PM5/3/12
to v8-users
Hi there,

I've been trying to use the javascript object exposed with --expose_debug_as=<name> and I got stuck trying to determine how to stop the main thread upon pause. Also I still can't find a function to continue the execution. This is the only black hole right now. The rest of the functionality is pretty straight forward, may anybody shed some light on this please?. 

Thanks in advance. 
Camilo

Yang Guo

unread,
May 4, 2012, 8:51:17 AM5/4/12
to v8-users
Hi,

I'm not entirely sure what you are referring to. By exposing the debug
object using --expose-debug-as, you gain access to various debugger
features from within javascript. Javascript however is not
multithreaded, which is why "to stop the main thread upon pause"
puzzles me.

Cheers,

Yang

Camilo Aguilar

unread,
May 6, 2012, 11:20:24 AM5/6/12
to v8-u...@googlegroups.com
Yang Guo, lol, that did puzzle me too, that's why I started https://github.com/c4milo/node-debugger a while ago too, it's heavily based on what you guys have in webkit. It isn't fully working yet tho.

Camilo Aguilar

unread,
May 6, 2012, 11:27:35 AM5/6/12
to Karl Skomski, v8-users
Yeah, I thought v8 was handling the thread under the hood keeping the paused context and state available for us through the
JS Debug object. Karl, if you want to fork https://github.com/c4milo/node-debugger and send pull requests that will be awesome.


On Sun, May 6, 2012 at 4:36 AM, Karl Skomski <ka...@skomski.com> wrote:
Hi  Camilo,

yeah I tried the same thing in my fork. :D But when you think about it
twice it's pretty clear why you need a separate thread for the agent
when you use the debugger.
I consider to use the debugger agent from v8 or to implement my own
C++ module that replicates some v8 debugger agent features but what
better integrates with the rest of the module.

Maybe we could collaborate on this.

Kind regards,

Karl Skomski




---------- Forwarded message ----------
From: Camilo Aguilar <cam...@cloudescape.com>
Date: Thu, May 3, 2012 at 11:30 PM
Subject: [v8-users] about javascript debugger object exposed with
--expose_debug_as=<name>

Søren Gjesse

unread,
May 7, 2012, 3:03:51 AM5/7/12
to v8-u...@googlegroups.com, Karl Skomski
There is a way to break the JS execution. In the C++ API (include/v8-debug.h) there is the function Debug::DebugBreak(). This function can be called from any thread. When --expose_debug_as=<name> is used that function can be called from JavaScript using <name>.Debug.breakExecution. Calling it from JavaScript is not that interesting as it is almost the same as inserting a debugger statement.

The way Debug::DebugBreak() works is that it piggy-bags on the stack check. For each function call and backwards branch V8 performs a stack check. Debug::DebugBreak() artificially lowers the stack size so that these stack check always fail. The handling of a failing stack check can then see that the failing stack check is due to a debugger break and handle it accordingly.

Regards,
Søren

Camilo Aguilar

unread,
May 7, 2012, 12:39:53 PM5/7/12
to v8-u...@googlegroups.com, sgj...@chromium.org
Hey Søren, thanks for your explanation, I was really looking forward to your comments. 

At this point, based in your and Yang answers, it seems like using --expose_debug_as is not a good idea in order to implement a fully working debugger backend for WebKit DevTools, using only javascript in nodejs. 

Søren, Debug::DebugBreak() seems pretty straightforward from a user standpoint. What about resuming the execution?

Søren Gjesse

unread,
May 11, 2012, 4:37:25 AM5/11/12
to v8-u...@googlegroups.com
So basically there are two ways of handling debugging with V8

1. Handle debugging inside the VM using callback
2. Handle debugging outside the VM using the debugger protocol.

The d8 developer shell supports both modes of operation.

Running

$ ./d8 --debugger

Will enable the debugging inside the VM. Typing debugger (the debugger statement) will enter the debugger.

Running

$ ./d8 --debugger-agent

Will enable debugging through a socket connection. Typing debugger now will have no effect as no debugger is attached. d8 can also act as a remote debugger, so running

$ ./d8 --remote-debugger

in a separate shell will connect to the first V8. Now typing debugger in d8 will enter the debugger in the remote debugger.

Take a look at the debugger header include/v8-debug.h and the d8 source code in src/d8*. The debugger protocol is documented in http://code.google.com/p/v8/wiki/DebuggerProtocol.

Regards,
Søren
Reply all
Reply to author
Forward
0 new messages