00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_V8_DEBUG_H_
00029 #define V8_V8_DEBUG_H_
00030
00031 #include "v8.h"
00032
00033 #ifdef _WIN32
00034 typedef int int32_t;
00035 typedef unsigned int uint32_t;
00036 typedef unsigned short uint16_t;
00037 typedef long long int64_t;
00038
00039
00040
00041 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
00042 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
00043 build configuration to ensure that at most one of these is set
00044 #endif
00045
00046 #ifdef BUILDING_V8_SHARED
00047 #define EXPORT __declspec(dllexport)
00048 #elif USING_V8_SHARED
00049 #define EXPORT __declspec(dllimport)
00050 #else
00051 #define EXPORT
00052 #endif
00053
00054 #else // _WIN32
00055
00056
00057
00058 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
00059 #define EXPORT __attribute__ ((visibility("default")))
00060 #else // defined(__GNUC__) && (__GNUC__ >= 4)
00061 #define EXPORT
00062 #endif // defined(__GNUC__) && (__GNUC__ >= 4)
00063
00064 #endif // _WIN32
00065
00066
00070 namespace v8 {
00071
00072
00073 enum DebugEvent {
00074 Break = 1,
00075 Exception = 2,
00076 NewFunction = 3,
00077 BeforeCompile = 4,
00078 AfterCompile = 5,
00079 ScriptCollected = 6,
00080 BreakForCommand = 7
00081 };
00082
00083
00084 class EXPORT Debug {
00085 public:
00090 class ClientData {
00091 public:
00092 virtual ~ClientData() {}
00093 };
00094
00095
00099 class Message {
00100 public:
00104 virtual bool IsEvent() const = 0;
00105 virtual bool IsResponse() const = 0;
00106 virtual DebugEvent GetEvent() const = 0;
00107
00112 virtual bool WillStartRunning() const = 0;
00113
00119 virtual Handle<Object> GetExecutionState() const = 0;
00120 virtual Handle<Object> GetEventData() const = 0;
00121
00125 virtual Handle<String> GetJSON() const = 0;
00126
00132 virtual Handle<Context> GetEventContext() const = 0;
00133
00141 virtual ClientData* GetClientData() const = 0;
00142
00143 virtual ~Message() {}
00144 };
00145
00146
00150 class EventDetails {
00151 public:
00155 virtual DebugEvent GetEvent() const = 0;
00156
00161 virtual Handle<Object> GetExecutionState() const = 0;
00162 virtual Handle<Object> GetEventData() const = 0;
00163
00169 virtual Handle<Context> GetEventContext() const = 0;
00170
00175 virtual Handle<Value> GetCallbackData() const = 0;
00176
00182 virtual ClientData* GetClientData() const = 0;
00183
00184 virtual ~EventDetails() {}
00185 };
00186
00187
00197 typedef void (*EventCallback)(DebugEvent event,
00198 Handle<Object> exec_state,
00199 Handle<Object> event_data,
00200 Handle<Value> data);
00201
00210 typedef void (*EventCallback2)(const EventDetails& event_details);
00211
00224 typedef void (*MessageHandler)(const uint16_t* message, int length,
00225 ClientData* client_data);
00226
00235 typedef void (*MessageHandler2)(const Message& message);
00236
00240 typedef void (*HostDispatchHandler)();
00241
00245 typedef void (*DebugMessageDispatchHandler)();
00246
00247
00248 static bool SetDebugEventListener(EventCallback that,
00249 Handle<Value> data = Handle<Value>());
00250 static bool SetDebugEventListener2(EventCallback2 that,
00251 Handle<Value> data = Handle<Value>());
00252
00253
00254 static bool SetDebugEventListener(v8::Handle<v8::Object> that,
00255 Handle<Value> data = Handle<Value>());
00256
00257
00258
00259
00260 static void DebugBreak(Isolate* isolate = NULL);
00261
00262
00263
00264
00265 static void CancelDebugBreak(Isolate* isolate = NULL);
00266
00267
00268
00269
00270
00271
00272 static void DebugBreakForCommand(ClientData* data = NULL,
00273 Isolate* isolate = NULL);
00274
00275
00276
00277 static void SetMessageHandler(MessageHandler handler,
00278 bool message_handler_thread = false);
00279 static void SetMessageHandler2(MessageHandler2 handler);
00280
00281
00282
00283 static void SendCommand(const uint16_t* command, int length,
00284 ClientData* client_data = NULL,
00285 Isolate* isolate = NULL);
00286
00287
00288 static void SetHostDispatchHandler(HostDispatchHandler handler,
00289 int period = 100);
00290
00302 static void SetDebugMessageDispatchHandler(
00303 DebugMessageDispatchHandler handler, bool provide_locker = false);
00304
00323 static Local<Value> Call(v8::Handle<v8::Function> fun,
00324 Handle<Value> data = Handle<Value>());
00325
00329 static Local<Value> GetMirror(v8::Handle<v8::Value> obj);
00330
00339 static bool EnableAgent(const char* name, int port,
00340 bool wait_for_connection = false);
00341
00377 static void ProcessDebugMessages();
00378
00385 static Local<Context> GetDebugContext();
00386 };
00387
00388
00389 }
00390
00391
00392 #undef EXPORT
00393
00394
00395 #endif // V8_V8_DEBUG_H_