v8-debug.h revision 3e5fa29ddb82551500b118e9bf37af3966277b70
1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2008 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_V8_DEBUG_H_
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_V8_DEBUG_H_
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "v8.h"
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN32
34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int int32_t;
35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned int uint32_t;
36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned short uint16_t;  // NOLINT
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef long long int64_t;  // NOLINT
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Windows DLL export/import. See v8.h in this directory for
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// information on how to build/use V8 as a DLL.
41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  build configuration to ensure that at most one of these is set
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef BUILDING_V8_SHARED
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define EXPORT __declspec(dllexport)
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#elif USING_V8_SHARED
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define EXPORT __declspec(dllimport)
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define EXPORT
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // _WIN32
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Linux shared library export. See v8.h in this directory for
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// information on how to build/use V8 as shared library.
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define EXPORT __attribute__ ((visibility("default")))
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // defined(__GNUC__) && (__GNUC__ >= 4)
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define EXPORT
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // defined(__GNUC__) && (__GNUC__ >= 4)
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // _WIN32
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Debugger support for the V8 JavaScript engine.
69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Debug events which can occur in the V8 JavaScript engine.
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum DebugEvent {
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Break = 1,
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Exception = 2,
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  NewFunction = 3,
77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  BeforeCompile = 4,
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  AfterCompile  = 5,
793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  ScriptCollected = 6,
803bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  BreakForCommand = 7
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass EXPORT Debug {
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A client object passed to the v8 debugger whose ownership will be taken by
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * it. v8 is always responsible for deleting the object.
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class ClientData {
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ClientData() {}
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A message object passed to the debug message handler.
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class Message {
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Check type of message.
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual bool IsEvent() const = 0;
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual bool IsResponse() const = 0;
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual DebugEvent GetEvent() const = 0;
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Indicate whether this is a response to a continue command which will
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * start the VM running after this is processed.
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual bool WillStartRunning() const = 0;
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Access to execution state and event data. Don't store these cross
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * callbacks as their content becomes invalid. These objects are from the
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * debugger event that started the debug message loop.
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual Handle<Object> GetExecutionState() const = 0;
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual Handle<Object> GetEventData() const = 0;
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Get the debugger protocol JSON.
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual Handle<String> GetJSON() const = 0;
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Get the context active when the debug event happened. Note this is not
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * the current active context as the JavaScript part of the debugger is
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * running in it's own context which is entered at this point.
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual Handle<Context> GetEventContext() const = 0;
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Client data passed with the corresponding request if any. This is the
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * client_data data value passed into Debug::SendCommand along with the
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * request that led to the message or NULL if the message is an event. The
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * debugger takes ownership of the data and will delete it even if there is
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * no message handler.
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ClientData* GetClientData() const = 0;
142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~Message() {}
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1453e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
148f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * An event details object passed to the debug event listener.
149f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
150f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  class EventDetails {
151f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   public:
152f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    /**
153f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * Event type.
154f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     */
155f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual DebugEvent GetEvent() const = 0;
156f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
157f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    /**
158f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * Access to execution state and event data of the debug event. Don't store
159f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * these cross callbacks as their content becomes invalid.
160f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     */
161f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual Handle<Object> GetExecutionState() const = 0;
162f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual Handle<Object> GetEventData() const = 0;
163f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
164f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    /**
165f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * Get the context active when the debug event happened. Note this is not
166f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * the current active context as the JavaScript part of the debugger is
167f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * running in it's own context which is entered at this point.
168f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     */
169f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual Handle<Context> GetEventContext() const = 0;
170f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
171f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    /**
172f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     * Client data passed with the corresponding callbak whet it was registered.
173f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke     */
174f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual Handle<Value> GetCallbackData() const = 0;
175f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1763bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    /**
1773bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch     * Client data passed to DebugBreakForCommand function. The
1783bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch     * debugger takes ownership of the data and will delete it even if
1793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch     * there is no message handler.
1803bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch     */
1813bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    virtual ClientData* GetClientData() const = 0;
1823bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
183f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke    virtual ~EventDetails() {}
184f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  };
185f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
186f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
187f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Debug event callback function.
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param event the type of the debug event that triggered the callback
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   (enum DebugEvent)
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param exec_state execution state (JavaScript object)
193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param event_data event specific data (JavaScript object)
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data value passed by the user to SetDebugEventListener
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef void (*EventCallback)(DebugEvent event,
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Object> exec_state,
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Object> event_data,
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Value> data);
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
201f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
202f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Debug event callback function.
203f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
204f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param event_details object providing information about the debug event
205f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
206f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * A EventCallback2 does not take possession of the event data,
207f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * and must not rely on the data persisting after the handler returns.
208f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
209f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  typedef void (*EventCallback2)(const EventDetails& event_details);
210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Debug message callback function.
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param message the debug message handler message object
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param length length of the message
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param client_data the data value passed when registering the message handler
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
218f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * A MessageHandler does not take possession of the message string,
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and must not rely on the data persisting after the handler returns.
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This message handler is deprecated. Use MessageHandler2 instead.
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef void (*MessageHandler)(const uint16_t* message, int length,
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 ClientData* client_data);
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Debug message callback function.
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param message the debug message handler message object
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
231f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * A MessageHandler does not take possession of the message data,
232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and must not rely on the data persisting after the handler returns.
233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef void (*MessageHandler2)(const Message& message);
235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Debug host dispatch callback function.
238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef void (*HostDispatchHandler)();
240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
241d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /**
242d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * Callback function for the host to ensure debug messages are processed.
243d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   */
244d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  typedef void (*DebugMessageDispatchHandler)();
245d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set a C debug event listener.
247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool SetDebugEventListener(EventCallback that,
248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    Handle<Value> data = Handle<Value>());
249f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  static bool SetDebugEventListener2(EventCallback2 that,
250f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                                     Handle<Value> data = Handle<Value>());
251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set a JavaScript debug event listener.
253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool SetDebugEventListener(v8::Handle<v8::Object> that,
254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    Handle<Value> data = Handle<Value>());
255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
256f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  // Schedule a debugger break to happen when JavaScript code is run.
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void DebugBreak();
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
259f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  // Remove scheduled debugger break if it has not happened yet.
260f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static void CancelDebugBreak();
261f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
2623bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // Break execution of JavaScript (this method can be invoked from a
2633bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // non-VM thread) for further client command execution on a VM
2643bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // thread. Client data is then passed in EventDetails to
2653bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // EventCallback at the moment when the VM actually stops.
2663bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static void DebugBreakForCommand(ClientData* data = NULL);
2673bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Message based interface. The message protocol is JSON. NOTE the message
269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // handler thread is not supported any more parameter must be false.
270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetMessageHandler(MessageHandler handler,
271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                bool message_handler_thread = false);
272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetMessageHandler2(MessageHandler2 handler);
273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SendCommand(const uint16_t* command, int length,
274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                          ClientData* client_data = NULL);
275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatch interface.
277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetHostDispatchHandler(HostDispatchHandler handler,
278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                     int period = 100);
279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
280d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /**
281d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * Register a callback function to be called when a debug message has been
282d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * received and is ready to be processed. For the debug messages to be
283d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * processed V8 needs to be entered, and in certain embedding scenarios this
284d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * callback can be used to make sure V8 is entered for the debug message to
285d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * be processed. Note that debug messages will only be processed if there is
286d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * a V8 break. This can happen automatically by using the option
287d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * --debugger-auto-break.
288e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * \param provide_locker requires that V8 acquires v8::Locker for you before
289e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *        calling handler
290d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   */
291d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static void SetDebugMessageDispatchHandler(
292e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      DebugMessageDispatchHandler handler, bool provide_locker = false);
293d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /**
295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * Run a JavaScript function in the debugger.
296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \param fun the function to call
297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \param data passed as second argument to the function
298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * With this call the debugger is entered and the function specified is called
299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * with the execution state as the first argument. This makes it possible to
300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * get access to information otherwise not available during normal JavaScript
3016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  * execution e.g. details on stack frames. Receiver of the function call will
3026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  * be the debugger context global object, however this is a subject to change.
3033e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  * The following example show a JavaScript function which when passed to
3046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  * v8::Debug::Call will return the current line of JavaScript execution.
305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  *
306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \code
307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  *   function frame_source_line(exec_state) {
308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  *     return exec_state.frame(0).sourceLine();
309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  *   }
310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \endcode
311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  */
312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> Call(v8::Handle<v8::Function> fun,
313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                            Handle<Value> data = Handle<Value>());
314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns a mirror object for the given object.
317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> GetMirror(v8::Handle<v8::Value> obj);
319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /**
321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * Enable the V8 builtin debug agent. The debugger agent will listen on the
322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * supplied TCP/IP port for remote debugger connection.
323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \param name the name of the embedding application
324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  * \param port the TCP/IP port to listen on
325e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  * \param wait_for_connection whether V8 should pause on a first statement
326e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  *   allowing remote debugger to connect before anything interesting happened
327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  */
328e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static bool EnableAgent(const char* name, int port,
329e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke                          bool wait_for_connection = false);
330e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
331e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  /**
332e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * Makes V8 process all pending debug messages.
333e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *
334e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * From V8 point of view all debug messages come asynchronously (e.g. from
335e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * remote debugger) but they all must be handled synchronously: V8 cannot
336e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * do 2 things at one time so normal script execution must be interrupted
337e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * for a while.
338e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *
339e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * Generally when message arrives V8 may be in one of 3 states:
340e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * 1. V8 is running script; V8 will automatically interrupt and process all
341e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * pending messages (however auto_break flag should be enabled);
342e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * 2. V8 is suspended on debug breakpoint; in this state V8 is dedicated
343e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * to reading and processing debug messages;
344e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * 3. V8 is not running at all or has called some long-working C++ function;
345e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * by default it means that processing of all debug message will be deferred
346e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * until V8 gets control again; however, embedding application may improve
347e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * this by manually calling this method.
348e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *
349e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * It makes sense to call this method whenever a new debug message arrived and
350e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * V8 is not already running. Method v8::Debug::SetDebugMessageDispatchHandler
351e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * should help with the former condition.
352e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *
353e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * Technically this method in many senses is equivalent to executing empty
354e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * script:
355e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * 1. It does nothing except for processing all pending debug messages.
356e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * 2. It should be invoked with the same precautions and from the same context
357e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * as V8 script would be invoked from, because:
358e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *   a. with "evaluate" command it can do whatever normal script can do,
359e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *   including all native calls;
360e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *   b. no other thread should call V8 while this method is running
361e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *   (v8::Locker may be used here).
362e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   *
363e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * "Evaluate" debug command behavior currently is not specified in scope
364e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   * of this method.
365e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   */
366e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static void ProcessDebugMessages();
3676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
3686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
3696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Debugger is running in it's own context which is entered while debugger
3706ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * messages are being dispatched. This is an explicit getter for this
3716ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * debugger context. Note that the content of the debugger context is subject
3726ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to change.
3736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
3746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static Local<Context> GetDebugContext();
375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}  // namespace v8
379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef EXPORT
382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_V8_DEBUG_H_
385