forked from xdebug/xdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdebug.c
2126 lines (1812 loc) · 67.8 KB
/
xdebug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2013 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.0 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://xdebug.derickrethans.nl/license.php |
| If you did not receive a copy of the Xdebug license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Derick Rethans <[email protected]> |
| Ilia Alshanetsky <[email protected]> |
| Harald Radi <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "main/php_version.h"
#include "xdebug_compat.h"
#if HAVE_XDEBUG
#ifndef PHP_WIN32
#include <sys/time.h>
#include <unistd.h>
#else
#include "win32/time.h"
#include <process.h>
#endif
#include "TSRM.h"
#include "SAPI.h"
#include "main/php_ini.h"
#include "ext/standard/head.h"
#include "ext/standard/html.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "php_globals.h"
#include "main/php_output.h"
#include "ext/standard/php_var.h"
#include "php_xdebug.h"
#include "xdebug_private.h"
#include "xdebug_code_coverage.h"
#include "xdebug_com.h"
#include "xdebug_llist.h"
#include "xdebug_mm.h"
#include "xdebug_var.h"
#include "xdebug_profiler.h"
#include "xdebug_stack.h"
#include "xdebug_superglobals.h"
#include "xdebug_tracing.h"
#include "usefulstuff.h"
/* execution redirection functions */
zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type TSRMLS_DC);
zend_op_array* xdebug_compile_file(zend_file_handle*, int TSRMLS_DC);
#if PHP_VERSION_ID < 50500
void (*xdebug_old_execute)(zend_op_array *op_array TSRMLS_DC);
void xdebug_execute(zend_op_array *op_array TSRMLS_DC);
void (*xdebug_old_execute_internal)(zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
void xdebug_execute_internal(zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
#else
void (*xdebug_old_execute_ex)(zend_execute_data *execute_data TSRMLS_DC);
void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC);
void (*xdebug_old_execute_internal)(zend_execute_data *current_execute_data, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
void xdebug_execute_internal(zend_execute_data *current_execute_data, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
#endif
/* error callback replacement functions */
void (*xdebug_old_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
void (*xdebug_new_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
static int xdebug_header_handler(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC);
static int xdebug_ub_write(const char *string, unsigned int lenght TSRMLS_DC);
static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
int zend_xdebug_initialised = 0;
int zend_xdebug_global_offset = -1;
int (*xdebug_orig_header_handler)(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC);
int (*xdebug_orig_ub_write)(const char *string, unsigned int len TSRMLS_DC);
static int xdebug_trigger_enabled(int setting, char *var_name TSRMLS_DC);
zend_function_entry xdebug_functions[] = {
PHP_FE(xdebug_get_stack_depth, NULL)
PHP_FE(xdebug_get_function_stack, NULL)
PHP_FE(xdebug_get_formatted_function_stack, NULL)
PHP_FE(xdebug_print_function_stack, NULL)
PHP_FE(xdebug_get_declared_vars, NULL)
PHP_FE(xdebug_call_class, NULL)
PHP_FE(xdebug_call_function, NULL)
PHP_FE(xdebug_call_file, NULL)
PHP_FE(xdebug_call_line, NULL)
PHP_FE(xdebug_var_dump, NULL)
PHP_FE(xdebug_debug_zval, NULL)
PHP_FE(xdebug_debug_zval_stdout, NULL)
PHP_FE(xdebug_enable, NULL)
PHP_FE(xdebug_disable, NULL)
PHP_FE(xdebug_is_enabled, NULL)
PHP_FE(xdebug_break, NULL)
PHP_FE(xdebug_start_trace, NULL)
PHP_FE(xdebug_stop_trace, NULL)
PHP_FE(xdebug_get_tracefile_name, NULL)
PHP_FE(xdebug_get_profiler_filename, NULL)
PHP_FE(xdebug_dump_aggr_profiling_data, NULL)
PHP_FE(xdebug_clear_aggr_profiling_data, NULL)
#if HAVE_PHP_MEMORY_USAGE
PHP_FE(xdebug_memory_usage, NULL)
PHP_FE(xdebug_peak_memory_usage, NULL)
#endif
PHP_FE(xdebug_time_index, NULL)
PHP_FE(xdebug_start_error_collection, NULL)
PHP_FE(xdebug_stop_error_collection, NULL)
PHP_FE(xdebug_get_collected_errors, NULL)
PHP_FE(xdebug_start_code_coverage, NULL)
PHP_FE(xdebug_stop_code_coverage, NULL)
PHP_FE(xdebug_get_code_coverage, NULL)
PHP_FE(xdebug_get_function_count, NULL)
PHP_FE(xdebug_dump_superglobals, NULL)
PHP_FE(xdebug_get_headers, NULL)
{NULL, NULL, NULL}
};
zend_module_entry xdebug_module_entry = {
STANDARD_MODULE_HEADER,
"xdebug",
xdebug_functions,
PHP_MINIT(xdebug),
PHP_MSHUTDOWN(xdebug),
PHP_RINIT(xdebug),
PHP_RSHUTDOWN(xdebug),
PHP_MINFO(xdebug),
XDEBUG_VERSION,
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6
NO_MODULE_GLOBALS,
#endif
ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xdebug),
STANDARD_MODULE_PROPERTIES_EX
};
ZEND_DECLARE_MODULE_GLOBALS(xdebug)
#if COMPILE_DL_XDEBUG
ZEND_GET_MODULE(xdebug)
#endif
static PHP_INI_MH(OnUpdateServer)
{
DUMP_TOK(server);
}
static PHP_INI_MH(OnUpdateGet)
{
DUMP_TOK(get);
}
static PHP_INI_MH(OnUpdatePost)
{
DUMP_TOK(post);
}
static PHP_INI_MH(OnUpdateCookie)
{
DUMP_TOK(cookie);
}
static PHP_INI_MH(OnUpdateFiles)
{
DUMP_TOK(files);
}
static PHP_INI_MH(OnUpdateEnv)
{
DUMP_TOK(env);
}
static PHP_INI_MH(OnUpdateRequest)
{
DUMP_TOK(request);
}
static PHP_INI_MH(OnUpdateSession)
{
DUMP_TOK(session);
}
static PHP_INI_MH(OnUpdateDebugMode)
{
if (!new_value) {
XG(remote_mode) = XDEBUG_NONE;
} else if (strcmp(new_value, "jit") == 0) {
XG(remote_mode) = XDEBUG_JIT;
} else if (strcmp(new_value, "req") == 0) {
XG(remote_mode) = XDEBUG_REQ;
} else {
XG(remote_mode) = XDEBUG_NONE;
}
return SUCCESS;
}
#ifdef P_tmpdir
# define XDEBUG_TEMP_DIR P_tmpdir
#else
# define XDEBUG_TEMP_DIR "/tmp"
#endif
PHP_INI_BEGIN()
/* Debugger settings */
STD_PHP_INI_BOOLEAN("xdebug.auto_trace", "0", PHP_INI_ALL, OnUpdateBool, auto_trace, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.trace_enable_trigger", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, trace_enable_trigger, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, trace_output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_output_name", "trace.%c", PHP_INI_ALL, OnUpdateString, trace_output_name, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_format", "0", PHP_INI_ALL, OnUpdateLong, trace_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trace_options", "0", PHP_INI_ALL, OnUpdateLong, trace_options, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.coverage_enable", "1", PHP_INI_SYSTEM, OnUpdateBool, coverage_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.collect_includes","1", PHP_INI_ALL, OnUpdateBool, collect_includes, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.collect_params", "0", PHP_INI_ALL, OnUpdateLong, collect_params, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.collect_return", "0", PHP_INI_ALL, OnUpdateBool, collect_return, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.collect_vars", "0", PHP_INI_ALL, OnUpdateBool, collect_vars, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.collect_assignments", "0", PHP_INI_ALL, OnUpdateBool, collect_assignments, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.default_enable", "1", PHP_INI_ALL, OnUpdateBool, default_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.extended_info", "1", PHP_INI_SYSTEM, OnUpdateBool, extended_info, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.file_link_format", "", PHP_INI_ALL, OnUpdateString, file_link_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "100", PHP_INI_ALL, OnUpdateLong, max_nesting_level, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.overload_var_dump", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, overload_var_dump, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.show_exception_trace", "0", PHP_INI_ALL, OnUpdateBool, show_ex_trace, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.show_local_vars", "0", PHP_INI_ALL, OnUpdateBool, show_local_vars, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.show_mem_delta", "0", PHP_INI_ALL, OnUpdateBool, show_mem_delta, zend_xdebug_globals, xdebug_globals)
/* Dump superglobals settings */
PHP_INI_ENTRY("xdebug.dump.COOKIE", NULL, PHP_INI_ALL, OnUpdateCookie)
PHP_INI_ENTRY("xdebug.dump.ENV", NULL, PHP_INI_ALL, OnUpdateEnv)
PHP_INI_ENTRY("xdebug.dump.FILES", NULL, PHP_INI_ALL, OnUpdateFiles)
PHP_INI_ENTRY("xdebug.dump.GET", NULL, PHP_INI_ALL, OnUpdateGet)
PHP_INI_ENTRY("xdebug.dump.POST", NULL, PHP_INI_ALL, OnUpdatePost)
PHP_INI_ENTRY("xdebug.dump.REQUEST", NULL, PHP_INI_ALL, OnUpdateRequest)
PHP_INI_ENTRY("xdebug.dump.SERVER", NULL, PHP_INI_ALL, OnUpdateServer)
PHP_INI_ENTRY("xdebug.dump.SESSION", NULL, PHP_INI_ALL, OnUpdateSession)
STD_PHP_INI_BOOLEAN("xdebug.dump_globals", "1", PHP_INI_ALL, OnUpdateBool, dump_globals, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.dump_once", "1", PHP_INI_ALL, OnUpdateBool, dump_once, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.dump_undefined", "0", PHP_INI_ALL, OnUpdateBool, dump_undefined, zend_xdebug_globals, xdebug_globals)
/* Profiler settings */
STD_PHP_INI_BOOLEAN("xdebug.profiler_enable", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.profiler_output_dir", XDEBUG_TEMP_DIR, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, profiler_output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.profiler_output_name", "cachegrind.out.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, profiler_output_name, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_enable_trigger", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_enable_trigger, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_append", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_append, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_aggregate", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, profiler_aggregate, zend_xdebug_globals, xdebug_globals)
/* Remote debugger settings */
STD_PHP_INI_BOOLEAN("xdebug.remote_enable", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, remote_enable, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_handler", "dbgp", PHP_INI_ALL, OnUpdateString, remote_handler, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_host", "localhost", PHP_INI_ALL, OnUpdateString, remote_host, zend_xdebug_globals, xdebug_globals)
PHP_INI_ENTRY("xdebug.remote_mode", "req", PHP_INI_ALL, OnUpdateDebugMode)
STD_PHP_INI_ENTRY("xdebug.remote_port", "9000", PHP_INI_ALL, OnUpdateLong, remote_port, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.remote_autostart","0", PHP_INI_ALL, OnUpdateBool, remote_autostart, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.remote_connect_back","0", PHP_INI_ALL, OnUpdateBool, remote_connect_back, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_log", "", PHP_INI_ALL, OnUpdateString, remote_log, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.idekey", "", PHP_INI_ALL, OnUpdateString, ide_key_setting, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.remote_cookie_expire_time", "3600", PHP_INI_ALL, OnUpdateLong, remote_cookie_expire_time, zend_xdebug_globals, xdebug_globals)
/* Variable display settings */
STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128", PHP_INI_ALL, OnUpdateLong, display_max_children, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_data", "512", PHP_INI_ALL, OnUpdateLong, display_max_data, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateLong, display_max_depth, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.cli_color", "0", PHP_INI_ALL, OnUpdateBool, cli_color, zend_xdebug_globals, xdebug_globals)
/* Scream support */
STD_PHP_INI_BOOLEAN("xdebug.scream", "0", PHP_INI_ALL, OnUpdateBool, do_scream, zend_xdebug_globals, xdebug_globals)
PHP_INI_END()
static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
{
xg->stack = NULL;
xg->level = 0;
xg->do_trace = 0;
xg->trace_file = NULL;
xg->coverage_enable = 0;
xg->previous_filename = "";
xg->previous_file = NULL;
xg->do_code_coverage = 0;
xg->breakpoint_count = 0;
xg->ide_key = NULL;
xg->output_is_tty = OUTPUT_NOT_CHECKED;
xg->stdout_mode = 0;
xg->in_at = 0;
xdebug_llist_init(&xg->server, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->get, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->post, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->cookie, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->files, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->env, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->request, xdebug_superglobals_dump_dtor);
xdebug_llist_init(&xg->session, xdebug_superglobals_dump_dtor);
/* Get reserved offset */
xg->reserved_offset = zend_xdebug_global_offset;
/* Override header generation in SAPI */
if (sapi_module.header_handler != xdebug_header_handler) {
xdebug_orig_header_handler = sapi_module.header_handler;
sapi_module.header_handler = xdebug_header_handler;
}
xg->headers = NULL;
/* Capturing output */
if (sapi_module.ub_write != xdebug_ub_write) {
xdebug_orig_ub_write = sapi_module.ub_write;
sapi_module.ub_write = xdebug_ub_write;
}
}
static void php_xdebug_shutdown_globals (zend_xdebug_globals *xg TSRMLS_DC)
{
xdebug_llist_empty(&xg->server, NULL);
xdebug_llist_empty(&xg->get, NULL);
xdebug_llist_empty(&xg->post, NULL);
xdebug_llist_empty(&xg->cookie, NULL);
xdebug_llist_empty(&xg->files, NULL);
xdebug_llist_empty(&xg->env, NULL);
xdebug_llist_empty(&xg->request, NULL);
xdebug_llist_empty(&xg->session, NULL);
}
char *xdebug_env_key(TSRMLS_D)
{
char *ide_key;
ide_key = XG(ide_key_setting);
if (ide_key && *ide_key) {
return ide_key;
}
ide_key = getenv("DBGP_IDEKEY");
if (ide_key && *ide_key) {
return ide_key;
}
ide_key = getenv("USER");
if (ide_key && *ide_key) {
return ide_key;
}
ide_key = getenv("USERNAME");
if (ide_key && *ide_key) {
return ide_key;
}
return NULL;
}
void xdebug_env_config(TSRMLS_D)
{
char *config = getenv("XDEBUG_CONFIG");
xdebug_arg *parts;
int i;
/*
XDEBUG_CONFIG format:
XDEBUG_CONFIG=var=val var=val
*/
if (!config) {
return;
}
parts = (xdebug_arg*) xdmalloc(sizeof(xdebug_arg));
xdebug_arg_init(parts);
xdebug_explode(" ", config, parts, -1);
for (i = 0; i < parts->c; ++i) {
char *name = NULL;
char *envvar = parts->args[i];
char *envval = NULL;
char *eq = strchr(envvar, '=');
if (!eq || !*eq) {
continue;
}
*eq = 0;
envval = eq + 1;
if (!*envval) {
continue;
}
if (strcasecmp(envvar, "remote_enable") == 0) {
name = "xdebug.remote_enable";
} else
if (strcasecmp(envvar, "remote_port") == 0) {
name = "xdebug.remote_port";
} else
if (strcasecmp(envvar, "remote_host") == 0) {
name = "xdebug.remote_host";
} else
if (strcasecmp(envvar, "remote_handler") == 0) {
name = "xdebug.remote_handler";
} else
if (strcasecmp(envvar, "remote_mode") == 0) {
name = "xdebug.remote_mode";
} else
if (strcasecmp(envvar, "idekey") == 0) {
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
XG(ide_key) = xdstrdup(envval);
} else
if (strcasecmp(envvar, "profiler_enable") == 0) {
name = "xdebug.profiler_enable";
} else
if (strcasecmp(envvar, "profiler_output_dir") == 0) {
name = "xdebug.profiler_output_dir";
} else
if (strcasecmp(envvar, "profiler_output_name") == 0) {
name = "xdebug.profiler_output_name";
} else
if (strcasecmp(envvar, "profiler_enable_trigger") == 0) {
name = "xdebug.profiler_enable_trigger";
} else
if (strcasecmp(envvar, "remote_log") == 0) {
name = "xdebug.remote_log";
} else
if (strcasecmp(envvar, "remote_cookie_expire_time") == 0) {
name = "xdebug.remote_cookie_expire_time";
}
else if (strcasecmp(envvar, "cli_color") == 0) {
name = "xdebug.cli_color";
}
if (name) {
zend_alter_ini_entry(name, strlen(name) + 1, envval, strlen(envval), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
}
xdebug_arg_dtor(parts);
}
static int xdebug_silence_handler(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *cur_opcode = *EG(opline_ptr);
if (XG(do_scream)) {
execute_data->opline++;
if (cur_opcode->opcode == ZEND_BEGIN_SILENCE) {
XG(in_at) = 1;
} else {
XG(in_at) = 0;
}
return ZEND_USER_OPCODE_CONTINUE;
}
return ZEND_USER_OPCODE_DISPATCH;
}
static int xdebug_include_or_eval_handler(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = execute_data->opline;
#if PHP_VERSION_ID >= 50399
if (opline->extended_value == ZEND_EVAL) {
#else
if (Z_LVAL(opline->op2.u.constant) == ZEND_EVAL) {
#endif
zval *inc_filename;
zval tmp_inc_filename;
int is_var;
inc_filename = xdebug_get_zval(execute_data, opline->XDEBUG_TYPE(op1), &opline->op1, &is_var);
/* If there is no inc_filename, we're just bailing out instead */
if (!inc_filename) {
return ZEND_USER_OPCODE_DISPATCH;
}
if (inc_filename->type != IS_STRING) {
tmp_inc_filename = *inc_filename;
zval_copy_ctor(&tmp_inc_filename);
convert_to_string(&tmp_inc_filename);
inc_filename = &tmp_inc_filename;
}
/* Now let's store this info */
if (XG(last_eval_statement)) {
efree(XG(last_eval_statement));
}
XG(last_eval_statement) = estrndup(Z_STRVAL_P(inc_filename), Z_STRLEN_P(inc_filename));
if (inc_filename == &tmp_inc_filename) {
zval_dtor(&tmp_inc_filename);
}
}
return ZEND_USER_OPCODE_DISPATCH;
}
int xdebug_is_output_tty(TSRMLS_D)
{
if (XG(output_is_tty) == OUTPUT_NOT_CHECKED) {
#ifndef PHP_WIN32
XG(output_is_tty) = isatty(STDOUT_FILENO);
#else
XG(output_is_tty) = getenv("ANSICON");
#endif
}
return (XG(output_is_tty));
}
#if 0
int static xdebug_stack_insert_top(zend_stack *stack, const void *element, int size)
{
int i;
if (stack->top >= stack->max) { /* we need to allocate more memory */
stack->elements = (void **) erealloc(stack->elements,
(sizeof(void **) * (stack->max += 64)));
if (!stack->elements) {
return FAILURE;
}
}
/* move all existing ones up */
for (i = stack->top; i >= 0; i--) {
stack->elements[i + 1] = stack->elements[i];
}
/* replace top handler */
stack->elements[0] = (void *) emalloc(size);
memcpy(stack->elements[0], element, size);
return stack->top++;
}
#endif
PHP_MINIT_FUNCTION(xdebug)
{
zend_extension dummy_ext;
ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals);
REGISTER_INI_ENTRIES();
/* initialize aggregate call information hash */
zend_hash_init_ex(&XG(aggr_calls), 50, NULL, (dtor_func_t) xdebug_profile_aggr_call_entry_dtor, 1, 0);
/* Redirect compile and execute functions to our own */
old_compile_file = zend_compile_file;
zend_compile_file = xdebug_compile_file;
#if PHP_VERSION_ID < 50500
xdebug_old_execute = zend_execute;
zend_execute = xdebug_execute;
#else
xdebug_old_execute_ex = zend_execute_ex;
zend_execute_ex = xdebug_execute_ex;
#endif
xdebug_old_execute_internal = zend_execute_internal;
zend_execute_internal = xdebug_execute_internal;
/* Replace error handler callback with our own */
xdebug_old_error_cb = zend_error_cb;
xdebug_new_error_cb = xdebug_error_cb;
/* Get reserved offset */
zend_xdebug_global_offset = zend_get_resource_handle(&dummy_ext);
/* Overload the "exit" opcode */
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(exit, ZEND_EXIT);
/* Overload opcodes for code coverage */
if (XG(coverage_enable)) {
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_JMP);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_JMPZ);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_JMPZ_EX);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_JMPNZ);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_IDENTICAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_NOT_IDENTICAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_NOT_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_SMALLER);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_IS_SMALLER_OR_EQUAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_BOOL_NOT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SUB);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_MUL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_DIV);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD_ARRAY_ELEMENT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_RETURN);
#if PHP_VERSION_ID >= 50400
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_RETURN_BY_REF);
#endif
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_EXT_STMT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_RAISE_ABSTRACT_ERROR);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SEND_VAR);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SEND_VAR_NO_REF);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SEND_VAL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_NEW);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_EXT_FCALL_BEGIN);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_CATCH);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_BOOL);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD_CHAR);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD_STRING);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_INIT_ARRAY);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_DIM_R);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_OBJ_R);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_OBJ_W);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_OBJ_FUNC_ARG);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_DIM_FUNC_ARG);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_DIM_UNSET);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_OBJ_UNSET);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_CLASS);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_FETCH_CONSTANT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_CONCAT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ISSET_ISEMPTY_DIM_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_PRE_INC_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SWITCH_FREE);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_QM_ASSIGN);
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_DECLARE_LAMBDA_FUNCTION);
#endif
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4)
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD_TRAIT);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_BIND_TRAITS);
#endif
}
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(include_or_eval, ZEND_INCLUDE_OR_EVAL);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign, ZEND_ASSIGN);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_add, ZEND_ASSIGN_ADD);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_sub, ZEND_ASSIGN_SUB);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_mul, ZEND_ASSIGN_MUL);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_div, ZEND_ASSIGN_DIV);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_mod, ZEND_ASSIGN_MOD);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_sl, ZEND_ASSIGN_SL);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_sr, ZEND_ASSIGN_SR);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_concat, ZEND_ASSIGN_CONCAT);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_bw_or, ZEND_ASSIGN_BW_OR);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_bw_and, ZEND_ASSIGN_BW_AND);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_bw_xor, ZEND_ASSIGN_BW_XOR);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_dim, ZEND_ASSIGN_DIM);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(assign_obj, ZEND_ASSIGN_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_inc, ZEND_PRE_INC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_inc, ZEND_POST_INC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_dec, ZEND_PRE_DEC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_dec, ZEND_POST_DEC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_inc_obj, ZEND_PRE_INC_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_inc_obj, ZEND_POST_INC_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_dec_obj, ZEND_PRE_DEC_OBJ);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_dec_obj, ZEND_POST_DEC_OBJ);
zend_set_user_opcode_handler(ZEND_BEGIN_SILENCE, xdebug_silence_handler);
zend_set_user_opcode_handler(ZEND_END_SILENCE, xdebug_silence_handler);
if (zend_xdebug_initialised == 0) {
zend_error(E_WARNING, "Xdebug MUST be loaded as a Zend extension");
}
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_APPEND", XDEBUG_TRACE_OPTION_APPEND, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_COMPUTERIZED", XDEBUG_TRACE_OPTION_COMPUTERIZED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_TRACE_HTML", XDEBUG_TRACE_OPTION_HTML, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT);
XG(breakpoint_count) = 0;
XG(output_is_tty) = OUTPUT_NOT_CHECKED;
#ifndef ZTS
if (sapi_module.header_handler != xdebug_header_handler) {
xdebug_orig_header_handler = sapi_module.header_handler;
sapi_module.header_handler = xdebug_header_handler;
}
if (sapi_module.ub_write != xdebug_ub_write) {
xdebug_orig_ub_write = sapi_module.ub_write;
sapi_module.ub_write = xdebug_ub_write;
}
#endif
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(xdebug)
{
if (XG(profiler_aggregate)) {
xdebug_profiler_output_aggr_data(NULL TSRMLS_CC);
}
/* Reset compile, execute and error callbacks */
zend_compile_file = old_compile_file;
#if PHP_VERSION_ID < 50500
zend_execute = xdebug_old_execute;
#else
zend_execute_ex = xdebug_old_execute_ex;
#endif
zend_execute_internal = xdebug_old_execute_internal;
zend_error_cb = xdebug_old_error_cb;
zend_hash_destroy(&XG(aggr_calls));
#ifdef ZTS
ts_free_id(xdebug_globals_id);
#else
php_xdebug_shutdown_globals(&xdebug_globals TSRMLS_CC);
#endif
return SUCCESS;
}
static void xdebug_llist_string_dtor(void *dummy, void *elem)
{
char *s = elem;
if (s) {
xdfree(s);
}
}
static void xdebug_used_var_dtor(void *dummy, void *elem)
{
char *s = elem;
if (s) {
xdfree(s);
}
}
static void xdebug_stack_element_dtor(void *dummy, void *elem)
{
int i;
function_stack_entry *e = elem;
e->refcount--;
if (e->refcount == 0) {
if (e->function.function) {
xdfree(e->function.function);
}
if (e->function.class) {
xdfree(e->function.class);
}
if (e->filename) {
xdfree(e->filename);
}
if (e->var) {
for (i = 0; i < e->varc; i++) {
if (e->var[i].name) {
xdfree(e->var[i].name);
}
}
xdfree(e->var);
}
if (e->include_filename) {
xdfree(e->include_filename);
}
if (e->used_vars) {
xdebug_llist_destroy(e->used_vars, NULL);
e->used_vars = NULL;
}
if (e->profile.call_list) {
xdebug_llist_destroy(e->profile.call_list, NULL);
e->profile.call_list = NULL;
}
xdfree(e);
}
}
#if PHP_VERSION_ID >= 50200
#define COOKIE_ENCODE , 1, 0
#elif PHP_API_VERSION >= 20030820
#define COOKIE_ENCODE , 1
#else
#define COOKIE_ENCODE
#endif
int xdebug_ub_write(const char *string, unsigned int length TSRMLS_DC)
{
if (XG(remote_enabled)) {
if (-1 == XG(context).handler->remote_stream_output(string, length TSRMLS_CC)) {
return 0;
}
}
return xdebug_orig_ub_write(string, length TSRMLS_CC);
}
PHP_RINIT_FUNCTION(xdebug)
{
zend_function *orig;
char *idekey;
zval **dummy;
/* Get the ide key for this session */
XG(ide_key) = NULL;
idekey = xdebug_env_key(TSRMLS_C);
if (idekey && *idekey) {
if (XG(ide_key)) {
xdfree(XG(ide_key));
}
XG(ide_key) = xdstrdup(idekey);
}
/* Get xdebug ini entries from the environment also,
this can override the idekey if one is set */
xdebug_env_config(TSRMLS_C);
XG(no_exec) = 0;
XG(level) = 0;
XG(do_trace) = 0;
XG(coverage_enable) = 0;
XG(do_code_coverage) = 0;
XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
XG(stack) = xdebug_llist_alloc(xdebug_stack_element_dtor);
XG(trace_file) = NULL;
XG(tracefile_name) = NULL;
XG(profile_file) = NULL;
XG(profile_filename) = NULL;
XG(prev_memory) = 0;
XG(function_count) = -1;
XG(active_symbol_table) = NULL;
XG(This) = NULL;
XG(last_exception_trace) = NULL;
XG(last_eval_statement) = NULL;
XG(do_collect_errors) = 0;
XG(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor);
XG(reserved_offset) = zend_xdebug_global_offset;
/* {{{ Initialize auto globals in Zend Engine 2 */
zend_is_auto_global("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
zend_is_auto_global("_GET", sizeof("_GET")-1 TSRMLS_CC);
zend_is_auto_global("_POST", sizeof("_POST")-1 TSRMLS_CC);
zend_is_auto_global("_COOKIE", sizeof("_COOKIE")-1 TSRMLS_CC);
zend_is_auto_global("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC);
zend_is_auto_global("_FILES", sizeof("_FILES")-1 TSRMLS_CC);
zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
zend_is_auto_global("_SESSION", sizeof("_SESSION")-1 TSRMLS_CC);
/* }}} */
/* Check if we have this special get variable that stops a debugging
* request without executing any code */
if (
(
(
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, "XDEBUG_SESSION_STOP_NO_EXEC", sizeof("XDEBUG_SESSION_STOP_NO_EXEC"), (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, "XDEBUG_SESSION_STOP_NO_EXEC", sizeof("XDEBUG_SESSION_STOP_NO_EXEC"), (void **) &dummy) == SUCCESS
)
)
&& !SG(headers_sent)
) {
php_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), "", 0, time(NULL) + XG(remote_cookie_expire_time), "/", 1, NULL, 0, 0 COOKIE_ENCODE TSRMLS_CC);
XG(no_exec) = 1;
}
/* Only enabled extended info when it is not disabled */
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
CG(compiler_options) = CG(compiler_options) | (XG(extended_info) ? ZEND_COMPILE_EXTENDED_INFO : 0);
#else
CG(extended_info) = XG(extended_info);
#endif
/* Hack: We check for a soap header here, if that's existing, we don't use
* Xdebug's error handler to keep soap fault from fucking up. */
if (XG(default_enable) && zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_SOAPACTION", 16, (void**)&dummy) == FAILURE) {
zend_error_cb = xdebug_new_error_cb;
zend_throw_exception_hook = xdebug_throw_exception_hook;
}
XG(remote_enabled) = 0;
XG(profiler_enabled) = 0;
XG(breakpoints_allowed) = 1;
if (
(XG(auto_trace) || xdebug_trigger_enabled(XG(trace_enable_trigger), "XDEBUG_TRACE" TSRMLS_CC))
&& XG(trace_output_dir) && strlen(XG(trace_output_dir))
) {
/* In case we do an auto-trace we are not interested in the return
* value, but we still have to free it. */
xdfree(xdebug_start_trace(NULL, XG(trace_options) TSRMLS_CC));
}
/* Initialize some debugger context properties */
XG(context).program_name = NULL;
XG(context).list.last_file = NULL;
XG(context).list.last_line = 0;
XG(context).do_break = 0;
XG(context).do_step = 0;
XG(context).do_next = 0;
XG(context).do_finish = 0;
/* Initialize dump superglobals */
XG(dumped) = 0;
/* Initialize start time */
XG(start_time) = xdebug_get_utime();
/* Override var_dump with our own function */
XG(var_dump_overloaded) = 0;
if (XG(overload_var_dump)) {
zend_hash_find(EG(function_table), "var_dump", 9, (void **)&orig);
XG(orig_var_dump_func) = orig->internal_function.handler;
orig->internal_function.handler = zif_xdebug_var_dump;
XG(var_dump_overloaded) = 1;
}
/* Override set_time_limit with our own function to prevent timing out while debugging */
zend_hash_find(EG(function_table), "set_time_limit", 15, (void **)&orig);
XG(orig_set_time_limit_func) = orig->internal_function.handler;
orig->internal_function.handler = zif_xdebug_set_time_limit;
XG(headers) = xdebug_llist_alloc(xdebug_llist_string_dtor);
/* Signal that we're in a request now */
XG(in_execution) = 1;
return SUCCESS;
}
ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug)
{
zend_function *orig;
TSRMLS_FETCH();
if (XG(remote_enabled)) {
XG(context).handler->remote_deinit(&(XG(context)));
xdebug_close_socket(XG(context).socket);
}
if (XG(context).program_name) {
xdfree(XG(context).program_name);
}
xdebug_llist_destroy(XG(stack), NULL);
XG(stack) = NULL;
if (XG(do_trace) && XG(trace_file)) {
xdebug_stop_trace(TSRMLS_C);
}
if (XG(profile_file)) {
fclose(XG(profile_file));
}
if (XG(profile_filename)) {
xdfree(XG(profile_filename));
}
if (XG(ide_key)) {
xdfree(XG(ide_key));
XG(ide_key) = NULL;
}
XG(level) = 0;
XG(do_trace) = 0;
XG(coverage_enable) = 0;
XG(do_code_coverage) = 0;
xdebug_hash_destroy(XG(code_coverage));
XG(code_coverage) = NULL;
if (XG(context.list.last_file)) {
xdfree(XG(context).list.last_file);
}
if (XG(last_exception_trace)) {
xdfree(XG(last_exception_trace));
}
if (XG(last_eval_statement)) {
efree(XG(last_eval_statement));
}