I have the following overly simplistic code which tries to enable the
"wait for debugger attach" behavior of the V8 debug agent, so that I
can attach a remote debugger to the process (via Eclipse and the
ChromDevTools remote debugger):

#include <iostream>
#include "v8/v8.h"
#include "v8/v8-debug.h"

v8::Persistent<v8::Context> gDebugContext;
const std::string gSampleScript = "'Hello,' + ' World'";

// Never called, unfortunately...
void OnV8DebugMessage(void)
{
        std::cout << "OnV8DebugMessage" << std::endl;
        v8::Context::Scope contextScope(gDebugContext);
        v8::Debug::ProcessDebugMessages();
}

int main(int argc, char* argv[])
{
        v8::V8::Initialize();

        // V8 should pause on first statement (but doesn't)
        v8::Debug::EnableAgent("My Debugee", 9222, true);
        v8::Debug::SetDebugMessageDispatchHandler(OnV8DebugMessage, true);

        gDebugContext = v8::Context::New();

        // Simulate v8 usage elsewhere in the codebase that main() knows
nothing
        // about (actual scenario is via a dynamically loaded module/plugin/
class
        // in this process space).
        {
                v8::Locker lock;
                v8::HandleScope handleScope;
                v8::Persistent<v8::Context> context = v8::Context::New();
                v8::Context::Scope contextScope(context);
                v8::Handle<v8::String> source =
v8::String::New(gSampleScript.c_str());
                v8::Handle<v8::Script> script = v8::Script::Compile(source);

                // Here's where I'd expect script execution to pause until a
debugger
                // attaches, but that's not the case...
                v8::Handle<v8::Value> result = script->Run();

                context.Dispose();
                v8::String::AsciiValue ascii(result);
                std::cout << *ascii << std::endl;
        }

        gDebugContext.Dispose();

        return 0;
}


I get the console output of "Hello, World", but the process never
blocks to allow a debugger to attach.  Additionally, the
OnV8DebugMessage() method is never called.

There is bound to be something obvious I'm not understanding.  Can
anybody enlighten me?

Cheers,
David

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to