Adding debugger support to a v8-based application

257 views
Skip to first unread message

Petar Dobrev

unread,
Aug 24, 2014, 6:00:16 AM8/24/14
to v8-u...@googlegroups.com
Hello!

I'd like to add debugger support to an application that uses v8 and tried following the resource on the topic from the wiki: https://code.google.com/p/v8/wiki/AddDebuggerSupport

However, it seems that in v8-debug.h in trunk (https://code.google.com/p/v8/source/browse/trunk/include/v8-debug.h) there is neither v8::Debug::EnableAgent, nor v8::Debug::SetDebugMessageDispatchHandler.

Does anyone know what the current API to achieve that is?

Thanks!

Petar

Ben Noordhuis

unread,
Aug 24, 2014, 4:33:10 PM8/24/14
to v8-u...@googlegroups.com
You feed in JSON debug commands[0] with v8::Debug::SendCommand().
It's safe to call from another thread; the main thread will interrupt
currently executing JS code in order to process the debug command.

If the main thread spends most of its time in native code, then call
v8::Debug::ProcessDebugMessages() periodically to flush queued
commands.

Everything else, like creating a listen socket and managing
connections from debugger clients, is up to the embedder. The wire
representation of the debug protocol looks a lot like HTTP, but with
the notable differences that:

1. There is no status or request line, and

2. The server (the process being debugged) sends headers first. They
look like this:

Type: connect
V8-Version: 3.26.33
Protocol-Version: 1
Embedding-Host: node v0.13.0-pre
Content-Length: 0

It should be noted that V8's native debugger protocol is being phased
out in favor of Chromium's remote debugger protocol; for a longer-term
solution, that's probably what you want to be looking at.

Hope that helps!

[0] https://code.google.com/p/v8/wiki/DebuggerProtocol

[1] https://developer.chrome.com/devtools/docs/debugger-protocol

Bit Cortex

unread,
Aug 25, 2014, 4:02:51 PM8/25/14
to v8-u...@googlegroups.com
Hi Ben,

A couple of questions:

1. How does the embedder know what reponse to send to the debugger? v8::Debug::SendCommand() doesn't return anything.

2. Do you know if the debug protocol change will affect V8's debugging API?

Thanks!

Ben Noordhuis

unread,
Aug 26, 2014, 7:52:56 AM8/26/14
to v8-u...@googlegroups.com
On Mon, Aug 25, 2014 at 10:02 PM, Bit Cortex <bitc...@gmail.com> wrote:
> 1. How does the embedder know what reponse to send to the debugger?
> v8::Debug::SendCommand() doesn't return anything.

You send or collect the response in the message handler that you
register with v8::Debug::SetMessageHandler():

void HandleMessage(const v8::Debug::Message& message) {
v8::String::Utf8Value response(message.GetJSON());
// do something with |response|
}

> 2. Do you know if the debug protocol change will affect V8's debugging API?

I'm not really the right person to answer that question but my guess
is no or not much. I understand Chromium talks to the debugger using
the C++ API so whatever functionality it uses, V8 needs to keep.
Chromium is of course continuously updated but I don't expect radical
changes in the short term.

Bit Cortex

unread,
Aug 26, 2014, 10:53:41 AM8/26/14
to v8-u...@googlegroups.com
Thank you very much, Ben!

Petar Dobrev

unread,
Aug 26, 2014, 11:13:09 AM8/26/14
to v8-u...@googlegroups.com
Thanks Ben, that's helpful!



--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/rp1ElLaGqlo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages