On Wed, Aug 3, 2016 at 8:17 AM, Abhishek Singh
<singhabhishek....@gmail.com> wrote:
> Hi,
>
> Sorry to bother again about V8 JSON protocol debugger. I’ve looked through
> debug_agent.cc/.h and _debug_agent.js implementation in node.js in order to
> understand to understand correct way to enable breakpoints(and fire other
> different types of requests). But even after reading though node.js code, to
> be honest it’s difficult to arrive at minimal version of working v8 debugger
> even after reading node src(node.js has some additional Environment, Agent
> and AgentMessage object, I don’t think I need all of them). I guess if I
> spend few more days looking through their src, I could figure something.
>
> At present, my question is if anyone else has some sample code that
> simulates working V8 debugger support? Could you please share code for it?
>
> Currently I’m missing something in my implementation i.e. even when V8
> reports breakpoint is set - code execution doesn’t pause at the bp - more
> details https://groups.google.com/forum/#!topic/v8-users/5ZwslR6XMzk
>
> Thanks

Below is a script that uses the JS API to drive the debugger, maybe it
can help as a starting point?  Consult src/debug/debug.js and
src/debug/mirrors.js for more details.

Note that exceptions in the debug listener are silently swallowed by
the runtime.  Consider wrapping the body in a big try/catch that
prints the exception.

    // Flags: --expose_debug_as=debug
    'use strict';
    const Debug = debug.Debug;
    const DebugEvent = Debug.DebugEvent;

    function stringify(o) {
      try { return JSON.stringify(o); }
      catch (e) { return `<${e.message}>`; }
    }

    Debug.setListener(function(evt, state, data) {
      if (evt !== DebugEvent.Break && evt !== DebugEvent.Exception) return;
      print(evt, stringify(state), stringify(data));
    });

    Debug.setBreakOnException();
    Debug.setBreakPoint(f);  // Returns the breakpoint number.
    print(Debug.showBreakPoints(f));

    try { g(); }
    catch (e) {}

    function f() {
      print('breakpoint');  // Triggers event.
      throw new Error('boom');  // Triggers event.
    }

    function g() {
      debugger;  // Triggers event.
      f();
    }

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to