OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Debug events which can occur in the V8 JavaScript engine. | 72 // Debug events which can occur in the V8 JavaScript engine. |
73 enum DebugEvent { | 73 enum DebugEvent { |
74 Break = 1, | 74 Break = 1, |
75 Exception = 2, | 75 Exception = 2, |
76 NewFunction = 3, | 76 NewFunction = 3, |
77 BeforeCompile = 4, | 77 BeforeCompile = 4, |
78 AfterCompile = 5 | 78 AfterCompile = 5 |
79 }; | 79 }; |
80 | 80 |
81 | 81 |
82 /** | |
83 * Debug event callback function. | |
84 * | |
85 * \param event the type of the debug event that triggered the callback | |
86 * (enum DebugEvent) | |
87 * \param exec_state execution state (JavaScript object) | |
88 * \param event_data event specific data (JavaScript object) | |
89 * \param data value passed by the user to SetDebugEventListener | |
90 */ | |
91 typedef void (*DebugEventCallback)(DebugEvent event, | |
92 Handle<Object> exec_state, | |
93 Handle<Object> event_data, | |
94 Handle<Value> data); | |
95 | |
96 | |
97 /** | |
98 * Debug message callback function. | |
99 * | |
100 * \param message the debug message | |
101 * \param length length of the message | |
102 * \param data the data value passed when registering the message handler | |
103 * A DebugMessageHandler does not take posession of the message string, | |
104 * and must not rely on the data persisting after the handler returns. | |
105 */ | |
106 typedef void (*DebugMessageHandler)(const uint16_t* message, int length, | |
107 void* data); | |
108 | |
109 /** | |
110 * Debug host dispatch callback function. | |
111 * | |
112 * \param dispatch the dispatch value | |
113 * \param data the data value passed when registering the dispatch handler | |
114 */ | |
115 typedef void (*DebugHostDispatchHandler)(void* dispatch, | |
116 void* data); | |
117 | |
118 | |
119 | |
120 class EXPORT Debug { | 82 class EXPORT Debug { |
121 public: | 83 public: |
| 84 /** |
| 85 * A client object passed to the v8 debugger whose ownership will be taken by |
| 86 * it. v8 is always responsible for deleting the object. |
| 87 */ |
| 88 class ClientData { |
| 89 public: |
| 90 virtual ~ClientData() {} |
| 91 }; |
| 92 |
| 93 |
| 94 /** |
| 95 * Debug event callback function. |
| 96 * |
| 97 * \param event the type of the debug event that triggered the callback |
| 98 * (enum DebugEvent) |
| 99 * \param exec_state execution state (JavaScript object) |
| 100 * \param event_data event specific data (JavaScript object) |
| 101 * \param data value passed by the user to SetDebugEventListener |
| 102 */ |
| 103 typedef void (*EventCallback)(DebugEvent event, |
| 104 Handle<Object> exec_state, |
| 105 Handle<Object> event_data, |
| 106 Handle<Value> data); |
| 107 |
| 108 |
| 109 /** |
| 110 * Debug message callback function. |
| 111 * |
| 112 * \param message the debug message |
| 113 * \param length length of the message |
| 114 * \param data the data value passed when registering the message handler |
| 115 * \param client_data the data value passed into Debug::SendCommand along |
| 116 * with the request that led to the message or NULL if the message is an |
| 117 * asynchronous event. The debugger takes ownership of the data and will |
| 118 * delete it before dying even if there is no message handler. |
| 119 * A MessageHandler does not take posession of the message string, |
| 120 * and must not rely on the data persisting after the handler returns. |
| 121 */ |
| 122 typedef void (*MessageHandler)(const uint16_t* message, int length, |
| 123 ClientData* client_data); |
| 124 |
| 125 /** |
| 126 * Debug host dispatch callback function. |
| 127 * |
| 128 * \param dispatch the dispatch value |
| 129 * \param data the data value passed when registering the dispatch handler |
| 130 */ |
| 131 typedef void (*HostDispatchHandler)(ClientData* dispatch); |
| 132 |
| 133 |
122 // Set a C debug event listener. | 134 // Set a C debug event listener. |
123 static bool SetDebugEventListener(DebugEventCallback that, | 135 static bool SetDebugEventListener(EventCallback that, |
124 Handle<Value> data = Handle<Value>()); | 136 Handle<Value> data = Handle<Value>()); |
125 | 137 |
126 // Set a JavaScript debug event listener. | 138 // Set a JavaScript debug event listener. |
127 static bool SetDebugEventListener(v8::Handle<v8::Object> that, | 139 static bool SetDebugEventListener(v8::Handle<v8::Object> that, |
128 Handle<Value> data = Handle<Value>()); | 140 Handle<Value> data = Handle<Value>()); |
129 | 141 |
130 // Break execution of JavaScript. | 142 // Break execution of JavaScript. |
131 static void DebugBreak(); | 143 static void DebugBreak(); |
132 | 144 |
133 // Message based interface. The message protocol is JSON. | 145 // Message based interface. The message protocol is JSON. |
134 static void SetMessageHandler(DebugMessageHandler handler, void* data = NULL, | 146 static void SetMessageHandler(MessageHandler handler, |
135 bool message_handler_thread = true); | 147 bool message_handler_thread = true); |
136 static void SendCommand(const uint16_t* command, int length); | 148 static void SendCommand(const uint16_t* command, int length, |
| 149 ClientData* client_data = NULL); |
137 | 150 |
138 // Dispatch interface. | 151 // Dispatch interface. |
139 static void SetHostDispatchHandler(DebugHostDispatchHandler handler, | 152 static void SetHostDispatchHandler(HostDispatchHandler handler); |
140 void* data = NULL); | 153 static void SendHostDispatch(ClientData* dispatch); |
141 static void SendHostDispatch(void* dispatch); | |
142 | 154 |
143 /** | 155 /** |
144 * Run a JavaScript function in the debugger. | 156 * Run a JavaScript function in the debugger. |
145 * \param fun the function to call | 157 * \param fun the function to call |
146 * \param data passed as second argument to the function | 158 * \param data passed as second argument to the function |
147 * With this call the debugger is entered and the function specified is called | 159 * With this call the debugger is entered and the function specified is called |
148 * with the execution state as the first argument. This makes it possible to | 160 * with the execution state as the first argument. This makes it possible to |
149 * get access to information otherwise not available during normal JavaScript | 161 * get access to information otherwise not available during normal JavaScript |
150 * execution e.g. details on stack frames. The following example show a | 162 * execution e.g. details on stack frames. The following example show a |
151 * JavaScript function which when passed to v8::Debug::Call will return the | 163 * JavaScript function which when passed to v8::Debug::Call will return the |
(...skipping 18 matching lines...) Expand all Loading... |
170 }; | 182 }; |
171 | 183 |
172 | 184 |
173 } // namespace v8 | 185 } // namespace v8 |
174 | 186 |
175 | 187 |
176 #undef EXPORT | 188 #undef EXPORT |
177 | 189 |
178 | 190 |
179 #endif // V8_DEBUG_H_ | 191 #endif // V8_DEBUG_H_ |
OLD | NEW |