4

I'm trying to learn how to use the Debug object in V8 to debug javascript in an embedded-javascript c++ application.

I've called v8::Debug::SetDebugEventListener and set a callback. I then call v8::Debug::GetDebugContext to get a debug context, and then run something like: Debug.scripts()

If I print the results of that call from C++, I get:

 [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]

What I actually want to do is set a breakpoint for a given line number in a script, but can't get even the most basic things working.

I get callbacks to my debug event listener, but the callback input parameter (non-user-provided) data doesn't make any sense to me, either.

{script_: {context_: {data_: undefined, handle_: 0, type_: "context"}, handle_: 1, script_: {}, type_: "script"}, type_: 4}
{break_id: 2, selected_frame: 0}

Thank you.

3
  • One thing I didn't know when I posted this was that a bunch of information about a v8::Script is stored in v8::UnboundScript, which can be obtained from a script with v8::Script::GetUnboundScript(), even if you didn't explicitly make one with v8::ScriptCompiler first. Commented Oct 2, 2016 at 4:20
  • Did you ever find the answer? Commented Oct 4, 2016 at 21:32
  • @Qwertman I posetd a self-answer with what I've learned. Debugging javascript in v8 seems to be VERY difficult and extremely poorly (even for v8) documented. Commented Oct 4, 2016 at 23:03

1 Answer 1

1

(Note: this may or may not be the right way to do things, but it's working for me in some simple cases)

v8::DebugEvent debug_event_type = event_details.GetEvent();

then switch on the results:

if (debug_event_type == v8::DebugEvent::Break) {

Here's the passed in data for a pretty trivial breakpoint being hit:

 /* GetEventData() when a breakpoint is hit returns:
     * {
     *      break_points_hit_: [{active_: true, actual_location: {column: 4, line: 13, script_id: 55}, condition_: null,
     *      script_break_point_: {
     *          active_: true,
     *          break_points_: [],
     *          column_: undefined,
     *          condition_: undefined,
     *          groupId_: undefined,
     *          line_: 13,
     *          number_: 1, <== breakpoint number - v8-assigned
     *          position_alignment_: 0,
     *          script_id_: 55, <== script id passed in from v8::ScriptOrigin when compiled
     *          type_: 0
 *          },
 *          source_position_: 175}], frame_: {break_id_: 8, details_: {break_id_: 8, details_: [392424216, {}, function a(){
    println("Beginning of a()");
    let some_var = 5;
    some_var += 5;
    b(some_var);
    println("End of a()");
}, {sourceColumnStart_: [undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 4, undefined, undefined, undefined, undefined, undefined, undefined, undefined]}, 0, 1, 175, false, false, 0, "some_var", 5]}, index_: 0, type_: "frame"}}

shameless self promotion: You can see the progress I've made towards debugging v8 in my v8 integration simplification library v8toolkit here: https://github.com/xaxxon/v8toolkit/blob/master/src/debugger.cpp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.