"Fossies" - the Fresh Open Source Software Archive 
Member "dbg-2.15.5/php_dbg.h" (21 Apr 2007, 14844 Bytes) of package /linux/www/old/dbg-2.15.5.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "php_dbg.h" see the
Fossies "Dox" file reference documentation.
1 /***************************************************************************
2 php_dbg.h - description
3 -------------------
4 begin : Sun Sep 24 2000
5 copyright : (C) 2001 by Dmitri Dmitrienko
6 : (C) 2002, 2007 NuSphere Corp.
7 www : http://dd.cron.ru
8 : http://www.nusphere.com/
9 author : written by Dmitri Dmitrienko
10 license : This source file is subject to version 3.0 of
11 the License, that is bundled with this package
12 in the file LICENSE, and is available at through
13 the world-wide-web at http://www.nusphere.com/dbg
14 ***************************************************************************/
15
16 #ifndef _PHP_DBG_H_
17 #define _PHP_DBG_H_
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #ifdef PHP_WIN32
24 #if defined(ZEND_ENGINE_2)
25 #include <winsock2.h>
26 #else
27 #include <winsock.h>
28 #endif
29 #include "config.w32.h"
30 #else
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #if HAVE_ARPA_INET_H
34 #include <arpa/inet.h>
35 #endif
36 #include <netdb.h>
37 #endif
38
39 #if HAVE_STDARG_H
40 #include <stdarg.h>
41 #endif
42
43 #include "php.h"
44 #include "php_network.h"
45
46 #ifdef HAVE_DBG
47
48 #ifdef PHP_WIN32
49 #ifdef DBG_DEBUG_MEM
50 #ifndef _CRTDBG_MAP_ALLOC
51 #define _CRTDBG_MAP_ALLOC
52 #endif
53 #include <malloc.h>
54 #include <stdlib.h>
55 #include <crtdbg.h>
56 #endif
57 #endif
58
59
60 #include "dbg_net.h"
61 #include "zend_llist.h"
62 #include "zend_extensions.h"
63 #include "zend_API.h"
64 #include "SAPI.h"
65
66 #if ZEND_MODULE_API_NO > 20050922
67 #define ZEND_ENGINE_2_2
68 #endif
69 #if ZEND_MODULE_API_NO > 20050921
70 #define ZEND_ENGINE_2_1
71 #endif
72
73
74 extern zend_module_entry dbg_module_entry;
75 #define phpext_dbg_ptr &dbg_module_entry
76
77 /* dbg module functions */
78 ZEND_MINIT_FUNCTION(dbg);
79 ZEND_RINIT_FUNCTION(dbg);
80 ZEND_MINFO_FUNCTION(dbg);
81
82
83
84 typedef struct tag_ext_compat_item {
85 int flg1;
86 int flg2;
87 int flg3;
88 char *compat_ext_name;
89 } ext_compat_item;
90
91 typedef struct tag_ext_compat_info {
92 int ext_api_ver;
93 char *ext_name;
94 int ext_ver;
95 ext_compat_item *compat_list;
96 } ext_compat_info;
97
98 PHP_FUNCTION(debugbreak);
99 PHP_FUNCTION(outputdebugstring);
100 #ifdef HAVE_DBG_PROFILER
101 PHP_FUNCTION(dbg_get_profiler_results);
102 #endif
103 PHP_FUNCTION(dbg_get_all_module_names);
104 PHP_FUNCTION(dbg_get_module_name);
105 PHP_FUNCTION(dbg_get_all_contexts);
106 PHP_FUNCTION(dbg_get_context_name);
107 PHP_FUNCTION(dbg_get_all_source_lines);
108 PHP_FUNCTION(dbg_get_source_context);
109
110
111 #ifndef PHP_WIN32
112 #define stricmp strcasecmp
113 #define strnicmp strncasecmp
114 #endif
115
116
117 typedef enum tagBPSTATE {
118 BPS_DELETED = 0,
119 BPS_DISABLED = 1,
120 BPS_ENABLED = 2,
121 BPS_UNRESOLVED = 0x100
122 } BPSTATE;
123
124 /* Log type */
125 #define LT_ODS 1 /* OutputDebugString */
126 #define LT_ERROR 2 /* Error/Warning/Notice while executing */
127 #define LT_OUTPUT 3 /* Any echo(), print() or header() results */
128 #define LT_FATALERROR 256 /* Fatal error (currently if error occured while evaluating)*/
129
130
131 #define DBGACTV_ONSTART (0x001)
132 #define DBGACTV_ONERROR (0x002)
133 #define DBGACTV_ONLOG (0x004)
134 #define DBGACTV_ONHTTPGET (0x008)
135 #define DBGACTV_ONHTTPCOOKIE (0x010)
136 #define DBGACTV_ALL (0x0FF)
137
138 /* opt_flags */
139 #define SOF_BREAKONLOAD 0x00001
140 #define SOF_BREAKONFINISH 0x00002
141 #define SOF_MATCHFILESINLOWCASE 0x00004
142 #define SOF_SEND_LOGS 0x00010
143 #define SOF_SEND_ERRORS 0x00020
144 #define SOF_SEND_OUTPUT 0x00040
145 #define SOF_SEND_OUTPUT_DETAILED 0x00080
146 #define SOF_ERR_LEVEL_0 0x00100
147 #define SOF_ERR_LEVEL_1 0x00200
148 #define SOF_ERR_LEVEL_2 0x00300
149 #define SOF_ERR_LEVEL_4 0x00400
150 #define SOF_ERR_LEVEL_MASK 0x00700
151 #define SOF_ERR_LEVEL_SHIFT 8
152
153 #define SOF_DEFAULT (SOF_BREAKONLOAD | SOF_BREAKONFINISH | SOF_MATCHFILESINLOWCASE | SOF_SEND_LOGS | SOF_SEND_ERRORS | SOF_SEND_OUTPUT)
154
155 #define ERR_LEVEL0_MASK 0
156 #define ERR_LEVEL1_MASK (E_CORE)
157 #define ERR_LEVEL2_MASK (ERR_LEVEL1_MASK | E_ERROR | E_PARSE | E_COMPILE_ERROR | E_USER_ERROR)
158 #define ERR_LEVEL3_MASK (E_ALL & ~(E_NOTICE | E_USER_NOTICE))
159 #define ERR_LEVEL4_MASK (E_ALL)
160
161
162 #if ZEND_EXTENSION_API_NO >= 20001224 /* 4.0.5 */
163 #define ZEND_HASH_GET_CURRENT_KEY_EX(a,b,c,d,e) zend_hash_get_current_key_ex(a, b, c, d, 1, e)
164 #define NOPRM(a) void a(void)
165 #else
166 #define ZEND_HASH_GET_CURRENT_KEY_EX zend_hash_get_current_key_ex
167 #define NOPRM(a) void a()
168 #endif
169
170 #ifndef va_copy
171 # ifdef __va_copy
172 # define va_copy(dest, src) __va_copy((dest), (src))
173 # else
174 # define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
175 # endif
176 #endif
177
178
179 #define CLIENT_HOST "clienthost"
180
181 #ifdef PHP_WIN32
182 /* Win 32 */
183 #include <windows.h>
184 #else
185 /* Linux / Unix */
186 #include <time.h>
187 #endif
188
189 typedef struct tag_ctxlines_item {
190 int ctx_id;
191 int start_line_no;
192 int lines_cnt;
193 int mod_no;
194 char *mod_name;
195 } ctxlines_item;
196
197 typedef struct tag_ctx_item {
198 int ctx_id;
199 char *function_name;
200 char *mod_name;
201 zend_op_array *op_array;
202 } ctx_item;
203
204 typedef struct tag_profdata_item {
205 int hitcount;
206 dbgint64 tm_min;
207 dbgint64 tm_max;
208 dbgint64 tm_sum;
209 } profdata_item;
210
211 typedef struct tag_bp_item {
212 int mod_no;
213 int line_no;
214 int skiphits;
215 int hitcount;
216 BPSTATE state;
217 int istemp;
218 int bp_no;
219 char *mod_name;
220 char *condition;
221 int isunderhit;
222 } bp_item;
223
224 typedef struct tag_bpl_arr_item {
225 int line_no;
226 bp_item *item;
227 } bpl_arr_item;
228
229 typedef struct tag_bpl_array {
230 int count;
231 int limit;
232 bpl_arr_item *item;
233 } bpl_array;
234
235 typedef struct tag_mod_item {
236 char *mod_name;
237 int mod_no;
238 int rsrv1;
239 profdata_item *profdata_arr;
240 int profdata_items;
241 bpl_array bp_arr;
242 int lines_changed;
243 } mod_item;
244
245 typedef struct tag_back_trace_item {
246 int mod_no;
247 int line_no;
248 HashTable *active_sym_table;
249 zval *active_this;
250 char *descr;
251 } back_trace_item;
252
253
254 #define LLIST_FOREACH(alist, pitem, code) { \
255 if (alist.size>0) { \
256 zend_llist_element *item = alist.head, *nitem; \
257 pitem *data; \
258 while (item) { \
259 data = (pitem *)(&(item->data)); \
260 nitem = item->next; \
261 code \
262 if (item == alist.tail) break; \
263 item=nitem; \
264 } \
265 } \
266 }
267
268 #define LLIST_RFOREACH(alist, pitem, code) { \
269 if (alist.size>0) { \
270 zend_llist_element *item = alist.tail, *nitem; \
271 pitem *data; \
272 while (item) { \
273 data = (pitem *)(&(item->data)); \
274 nitem = item->prev; \
275 code \
276 if (item == alist.head) break; \
277 item=nitem; \
278 } \
279 } \
280 }
281
282 #define LLIST_ITEM_AT(alist,idx,ret_item, type) { \
283 int i = idx; \
284 ret_item = NULL; \
285 if (alist.size>0) { \
286 zend_llist_element *item = alist.head; \
287 while (i > 0) { \
288 i--; \
289 if (item == alist.tail) break; \
290 item = item->next; \
291 } \
292 if (i==0 && item) \
293 ret_item = (type)&(item->data); \
294 } \
295 }
296
297
298 ZEND_BEGIN_MODULE_GLOBALS(DBG)
299 /*First!*/
300 int is_extension_activated;
301 int is_globals_initialized;
302 int is_failed_connection;
303 long clientversion;
304 /*INI*/
305 long cfgprm_enabled;
306 long cfgprm_profiler_enabled;
307 long cfgprm_fail_silently;
308 long cfgprm_timeout_seconds;
309 long cfgprm_ignore_nops;
310 long cfgprm_session_cookie;
311 long cfgprm_session_nocache;
312 char *cfgprm_JIT_host;
313 long cfgprm_JIT_port;
314 long cfgprm_JIT_enabled;
315 long cfgprm_JIT_level;
316
317 /*run-time*/
318 long sesstype;
319 long error_filter;
320 long JIT_filter;
321 char *req_sess_var;
322 char *req_client_ip_address;
323 long req_client_port;
324 char *client_address;
325 long client_port;
326 char *session_id;
327 int debug_socket;
328 int curr_line_no;
329 zend_op *last_opline;
330 char *curr_mod_name;
331 int curr_mod_no;
332 mod_item* curr_mod;
333 unsigned int debugger_flags;
334 long opt_flags;
335 int debugger_step_depth;
336 int in_eval;
337 char *eval_error;
338 int pause_cntr;
339 int eval_nest;
340 int session_cookie_added;
341 zend_llist mod_list;
342 zend_llist back_trace;
343 int back_trace_count;
344 zend_llist breakpoint_list;
345 int breakpoint_list_inv;
346 bpl_array global_bp_arr;
347 zend_llist ctxlines_list;
348 zend_llist ctx_list;
349 int ctx_counter;
350 dbgint64 l_time;
351 dbgint64 e_time;
352 int deactivate_inprocess;
353 dbg_packet logpack;
354 char *output_str_nd;
355 int output_str_nd_len;
356 int output_str_nd_limit;
357 ZEND_END_MODULE_GLOBALS(DBG)
358
359 extern zend_DBG_globals *pDBG_globals; /* for debugging purpose only */
360
361 #if ZEND_EXTENSION_API_NO >= 20021010
362 #define DBG_CTX_SAVE_ED \
363 zend_execute_data *dbg_ctx_current_execute_data = EG(current_execute_data); \
364 zend_execute_data dbg_ctx_execute_data; \
365 if (dbg_ctx_current_execute_data) \
366 dbg_ctx_execute_data = *EG(current_execute_data);
367
368 #define DBG_CTX_RESTORE_ED \
369 EG(current_execute_data) = dbg_ctx_current_execute_data; \
370 if (dbg_ctx_current_execute_data) \
371 *EG(current_execute_data) = dbg_ctx_execute_data;
372 #else
373 #define DBG_CTX_SAVE_ED
374 #define DBG_CTX_RESTORE_ED
375 #endif
376
377 #if ZEND_EXTENSION_API_NO >= 20010710
378 #define DBG_CTX_SAVE \
379 zend_op_array *dbg_ctx_active_op_array = EG(active_op_array); \
380 zend_function_state *dbg_ctx_function_state_ptr = EG(function_state_ptr); \
381 zval **dbg_ctx_return_value_ptr_ptr = EG(return_value_ptr_ptr); \
382 HashTable *dbg_ctx_active_sym_table = EG(active_symbol_table); \
383 zend_op **dbg_ctx_opline_ptr = EG(opline_ptr); \
384 int dbg_ctx_handle_op_arrays = CG(handle_op_arrays); \
385 zend_bool dbg_ctx_in_execution = EG(in_execution); \
386 zend_bool dbg_ctx_in_compilation = CG(in_compilation); \
387 zend_bool dbg_ctx_unclean_shutdown = CG(unclean_shutdown); \
388 DBG_CTX_SAVE_ED;
389
390 #define DBG_CTX_TRY zend_try
391
392 #define DBG_CTX_CATCH zend_catch
393
394 #define DBG_CTX_RESTORE \
395 EG(no_extensions)=0; \
396 CG(handle_op_arrays) = dbg_ctx_handle_op_arrays; \
397 EG(active_symbol_table) = dbg_ctx_active_sym_table; \
398 EG(opline_ptr) = dbg_ctx_opline_ptr; \
399 EG(active_op_array) = dbg_ctx_active_op_array; \
400 EG(function_state_ptr) = dbg_ctx_function_state_ptr; \
401 EG(return_value_ptr_ptr) = dbg_ctx_return_value_ptr_ptr; \
402 EG(in_execution) = dbg_ctx_in_execution; \
403 CG(in_compilation) = dbg_ctx_in_compilation; \
404 CG(unclean_shutdown) = dbg_ctx_unclean_shutdown; \
405 DBG_CTX_RESTORE_ED;
406
407 #define DBG_CTX_ENDTRY zend_end_try();
408
409 #else
410
411 #define DBG_CTX_SAVE
412 #define DBG_CTX_TRY
413 #define DBG_CTX_CATCH if (0)
414 #define DBG_CTX_RESTORE
415 #define DBG_CTX_ENDTRY
416 #endif
417
418
419
420 #ifdef ZTS
421 #if ZEND_EXTENSION_API_NO >= 20010710
422 /* 4.0.7 TSRM */
423 #define TSRMLS_FETCH1(a) TSRMLS_FETCH();
424 #define TSRMLS_FETCH2(a, b) TSRMLS_FETCH();
425 #define TSRMLS_FETCH3(a, b, c) TSRMLS_FETCH();
426 #define TSRMLS_FETCH4(a, b, c, d) TSRMLS_FETCH();
427
428 #define TSRMLS_FETCH1_NOP(a)
429 #define TSRMLS_FETCH2_NOP(a, b)
430
431 #define TSRMLS_DC0 TSRMLS_DC
432 #define TSRMLS_DC1(a) TSRMLS_DC
433 #define TSRMLS_DC2(a, b) TSRMLS_DC
434 #define TSRMLS_DC3(a, b, c) TSRMLS_DC
435 #define TSRMLS_DC4(a, b, c, d) TSRMLS_DC
436
437 #define TSRMLS_D1(a) TSRMLS_D
438 #define TSRMLS_D2(a, b) TSRMLS_D
439 #define TSRMLS_D3(a, b, c) TSRMLS_D
440
441 #define TSRMLS_CC0 TSRMLS_CC
442 #define TSRMLS_CC1(a) TSRMLS_CC
443 #define TSRMLS_CC2(a, b) TSRMLS_CC
444 #define TSRMLS_CC3(a, b, c) TSRMLS_CC
445 #define TSRMLS_CC4(a, b, c, d) TSRMLS_CC
446
447 #define TSRMLS_C0 TSRMLS_C
448 #define TSRMLS_C1(a) TSRMLS_C
449 #define TSRMLS_C2(a, b) TSRMLS_C
450 #define TSRMLS_C3(a, b, c) TSRMLS_C
451
452 #define DBG(v) TSRMG(DBG_globals_id, zend_DBG_globals *, v)
453 extern int DBG_globals_id;
454 #else
455 /* 4.0.0 TSRM */
456 #define TSRMLS_FETCH1(a) a##LS_FETCH();
457
458 #define TSRMLS_FETCH2(a, b) \
459 a##LS_FETCH(); \
460 b##LS_FETCH();
461
462 #define TSRMLS_FETCH3(a, b, c) \
463 a##LS_FETCH(); \
464 b##LS_FETCH(); \
465 c##LS_FETCH();
466
467 #define TSRMLS_FETCH4(a, b, c, d) \
468 a##LS_FETCH(); \
469 b##LS_FETCH(); \
470 c##LS_FETCH(); \
471 d##LS_FETCH();
472
473 #define TSRMLS_FETCH1_NOP(a) \
474 a##LS_FETCH();
475
476 #define TSRMLS_FETCH2_NOP(a, b) \
477 a##LS_FETCH(); \
478 b##LS_FETCH();
479
480 #define TSRMLS_DC0
481 #define TSRMLS_DC1(a) a##LS_DC
482 #define TSRMLS_DC2(a, b) a##LS_DC b##LS_DC
483 #define TSRMLS_DC3(a, b, c) a##LS_DC b##LS_DC c##LS_DC
484 #define TSRMLS_DC4(a, b, c, d) a##LS_DC b##LS_DC c##LS_DC d##LS_DC
485
486 #define TSRMLS_D1(a) a##LS_D
487 #define TSRMLS_D2(a, b) a##LS_D b##LS_DC
488 #define TSRMLS_D3(a, b, c) a##LS_D b##LS_DC c##LS_DC
489
490 #define TSRMLS_CC0
491 #define TSRMLS_CC1(a) a##LS_CC
492 #define TSRMLS_CC2(a, b) a##LS_CC b##LS_CC
493 #define TSRMLS_CC3(a, b, c) a##LS_CC b##LS_CC c##LS_CC
494 #define TSRMLS_CC4(a, b, c, d) a##LS_CC b##LS_CC c##LS_CC d##LS_CC
495
496 #define TSRMLS_C0
497 #define TSRMLS_C1(a) a##LS_C
498 #define TSRMLS_C2(a, b) a##LS_C b##LS_CC
499 #define TSRMLS_C3(a, b, c) a##LS_C b##LS_CC c##LS_CC
500
501 #define DBGLS_D zend_DBG_globals *DBG_globals
502 #define DBGLS_DC , DBGLS_D
503 #define DBGLS_C DBG_globals
504 #define DBGLS_CC , DBGLS_C
505 #define DBG(v) (DBG_globals->v)
506 #define DBGLS_FETCH() zend_DBG_globals *DBG_globals = ts_resource(DBG_globals_id)
507 extern int DBG_globals_id;
508 #endif
509 #else
510 /* NO TSRM */
511
512 #define TSRMLS_FETCH1(a)
513 #define TSRMLS_FETCH2(a, b)
514 #define TSRMLS_FETCH3(a, b, c)
515 #define TSRMLS_FETCH4(a, b, c, d)
516
517 #define TSRMLS_FETCH1_NOP(a)
518 #define TSRMLS_FETCH2_NOP(a, b)
519
520 #define TSRMLS_DC0
521 #define TSRMLS_DC1(a)
522 #define TSRMLS_DC2(a, b)
523 #define TSRMLS_DC3(a, b, c)
524 #define TSRMLS_DC4(a, b, c, d)
525
526 #define TSRMLS_D1(a)
527 #define TSRMLS_D2(a, b)
528 #define TSRMLS_D3(a, b, c)
529
530 #define TSRMLS_CC0
531 #define TSRMLS_CC1(a)
532 #define TSRMLS_CC2(a, b)
533 #define TSRMLS_CC3(a, b, c)
534 #define TSRMLS_CC4(a, b, c, d)
535
536 #define TSRMLS_C0
537 #define TSRMLS_C1(a)
538 #define TSRMLS_C2(a, b)
539 #define TSRMLS_C3(a, b, c)
540
541
542 extern zend_DBG_globals DBG_globals;
543 #define DBG(v) (DBG_globals.v)
544
545 #endif
546
547
548 #define TS_ALLOC_CTOR(a) php_##a##_init_globals
549 #define TS_ALLOC_DTOR(a) php_##a##_uninit_globals
550
551
552 /* TSRM */
553 #if ZEND_EXTENSION_API_NO >= 20010710
554 /* TSRM 4.0.7 */
555 #ifdef ZTS
556 #define TS_ALLOC_CTOR_FUNCTION(a) void TS_ALLOC_CTOR(a)(zend_##a##_globals * a##_globals TSRMLS_DC1(a))
557 #define TS_ALLOC_DTOR_FUNCTION(a) void TS_ALLOC_DTOR(a)(zend_##a##_globals * a##_globals TSRMLS_DC1(a))
558 #else
559 #define TS_ALLOC_CTOR_FUNCTION(a) void TS_ALLOC_CTOR(a)(zend_##a##_globals * _p##a##_globals TSRMLS_DC1(a))
560 #define TS_ALLOC_DTOR_FUNCTION(a) void TS_ALLOC_DTOR(a)(zend_##a##_globals * _p##a##_globals TSRMLS_DC1(a))
561 #endif
562 #define TS_ALLOC_CTOR_CALL(a) TS_ALLOC_CTOR(a)(NULL TSRMLS_CC1(a))
563 #define TS_ALLOC_DTOR_CALL(a) TS_ALLOC_DTOR(a)(NULL TSRMLS_CC1(a))
564 #else
565 /* OLD TSRM */
566 #define TS_ALLOC_CTOR_FUNCTION(a) void TS_ALLOC_CTOR(a)(TSRMLS_D1(a))
567 #define TS_ALLOC_DTOR_FUNCTION(a) void TS_ALLOC_DTOR(a)(TSRMLS_D1(a))
568 #define TS_ALLOC_CTOR_CALL(a) TS_ALLOC_CTOR(a)(TSRMLS_C1(a))
569 #define TS_ALLOC_DTOR_CALL(a) TS_ALLOC_DTOR(a)(TSRMLS_C1(a))
570 #endif
571
572 #define DBGF(f) (DBG(debugger_flags) & (f))
573 #define DBGO(f) (DBG(opt_flags) & (f))
574
575 #else
576 #error YOU HAVE TO RE-RUN buildconf TO GET RIGHT /main/php_config.h
577 #endif /* HAVE_DBG */
578
579 #endif