• Main Page
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

/home/ondras/svn/v8/include/v8-debug.h

00001 // Copyright 2008 the V8 project authors. All rights reserved.
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions are
00004 // met:
00005 //
00006 //     * Redistributions of source code must retain the above copyright
00007 //       notice, this list of conditions and the following disclaimer.
00008 //     * Redistributions in binary form must reproduce the above
00009 //       copyright notice, this list of conditions and the following
00010 //       disclaimer in the documentation and/or other materials provided
00011 //       with the distribution.
00012 //     * Neither the name of Google Inc. nor the names of its
00013 //       contributors may be used to endorse or promote products derived
00014 //       from this software without specific prior written permission.
00015 //
00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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;  // NOLINT
00037 typedef long long int64_t;  // NOLINT
00038 
00039 // Setup for Windows DLL export/import. See v8.h in this directory for
00040 // information on how to build/use V8 as a DLL.
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 // Setup for Linux shared library export. See v8.h in this directory for
00057 // information on how to build/use V8 as shared library.
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 // Debug events which can occur in the V8 JavaScript engine.
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   // Set a C debug event listener.
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   // Set a JavaScript debug event listener.
00254   static bool SetDebugEventListener(v8::Handle<v8::Object> that,
00255                                     Handle<Value> data = Handle<Value>());
00256 
00257   // Schedule a debugger break to happen when JavaScript code is run
00258   // in the given isolate. If no isolate is provided the default
00259   // isolate is used.
00260   static void DebugBreak(Isolate* isolate = NULL);
00261 
00262   // Remove scheduled debugger break in given isolate if it has not
00263   // happened yet. If no isolate is provided the default isolate is
00264   // used.
00265   static void CancelDebugBreak(Isolate* isolate = NULL);
00266 
00267   // Break execution of JavaScript in the given isolate (this method
00268   // can be invoked from a non-VM thread) for further client command
00269   // execution on a VM thread. Client data is then passed in
00270   // EventDetails to EventCallback at the moment when the VM actually
00271   // stops. If no isolate is provided the default isolate is used.
00272   static void DebugBreakForCommand(ClientData* data = NULL,
00273                                    Isolate* isolate = NULL);
00274 
00275   // Message based interface. The message protocol is JSON. NOTE the message
00276   // handler thread is not supported any more parameter must be false.
00277   static void SetMessageHandler(MessageHandler handler,
00278                                 bool message_handler_thread = false);
00279   static void SetMessageHandler2(MessageHandler2 handler);
00280 
00281   // If no isolate is provided the default isolate is
00282   // used.
00283   static void SendCommand(const uint16_t* command, int length,
00284                           ClientData* client_data = NULL,
00285                           Isolate* isolate = NULL);
00286 
00287   // Dispatch interface.
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 }  // namespace v8
00390 
00391 
00392 #undef EXPORT
00393 
00394 
00395 #endif  // V8_V8_DEBUG_H_

Generated on Thu Oct 6 2011 12:01:33 for V8 by  doxygen 1.7.1