-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathxdebug.php.txt
248 lines (187 loc) · 15.6 KB
/
xdebug.php.txt
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
┏━━━━━━━━━━━━┓
┃ XDEBUG ┃
┗━━━━━━━━━━━━┛
VERSION ==> #2.5.0 (supports PHP 7.1.0)
SUMMARY ==> #Breakpoints, e.g. with an IDE
#Logging:
# - enhanced
# - scope: local variables, global variables, HTTP headers
# - stack trace
# - garbage collection (refcounts)
#Tracing:
# - function call|return|exit
# - calls to a specific function
# - notices
#Profiling: CPU, memory, time
#Code coverage (e.g. for unit testing)
xdebug-helper-for-chrome #Chrome extension that allow to easily set parameters (like XDEBUG_TRACE, XDEBUG_PROFILE, XDEBUG_CONFIG) from browser
┌───────────────┐
│ REPORTING │
└───────────────┘
MISCONFIGURATION ==> #For it to work:
# - CONFVAR display_errors must be on, unless CONFVAR xdebug.force_display_errors 1
# - CONFVAR error_reporting must be on, unless CONFVAR xdebug.force_error_reporting on
# - for HTML ouput, CONFVAR html_errors must be on
# - there should be no set_error_handler()
xdebug.scream #CONFVAR 0|1 (def: 0). Ignore @ operator
┌─────────────────┐
│ BREAKPOINTS │
└─────────────────┘
REMOTE DEBUGGING ==> #Also called "remote debugging" because it follows client/server architecture:
# - a server (e.g. IDE, through plugin) sends stepping commands
# - client is any invocation of php binary (because XDebug is embedded in PHP)
# - it will sends debugging information (stack trace, etc.)
# - e.g. breakpoint in IDE will trigger after running "php FILE" in CLI
# - must set either:
# - from HTTP, XDEBUG_SESSION_START=SESSION_NAME as request parameter (GET|POST|cookie)
# - in CLI, ENVVAR XDEBUG_CONFIG="VAR=VAL ..." for each xdebug.VAR VAL
#Protocol is "DBGp"
xdebug.remote_enable #CONFVAR 1|0 (def: 0)
xdebug.remote_autostart #CONFVAR 1|0 (def: 0). Always start remote debugging with any client (no need for XDEBUG_CONFIG, etc.)
xdebug.remote_mode #CONFVAR. Whether to connect as soon as possible ('req', def) or after notice or exception ('jit')
xdebug.remote_host #CONVAR STR|NUM (def: localhost:9000). Server address.
xdebug.remote_port #Leave as is for local development. FastCGI FPM use same port, which might conflict
xdebug.remote_connect_back
xdebug.remote_addr_header #CONVAR used if need multiple clients. See online doc
xdebug.idekey #CONVAR "SESSION_NAME" (def: ENVVAR DGBP_IDEKEY, or USER[NAME]). Required
xdebug.remote_cookie_expire_time #CONVAR NUM (in secs, def: 3600)
xdebug.remote_log #CONFVAR 'FILE', to print DGBp log messages, in append mode
xdebug_break() #Set a breakpoint. GUI clients can usually do this through GUI
┌─────────────────────┐
│ CONSOLE LOGGING │
└─────────────────────┘
[xdebug_]var_dump(VAL) #Enhanced version
xdebug.cli_color #CONFVAR NUM. Whether to color output: 0 (def) (none), 1 (in tty), 2 (always)
xdebug.overload_var_dump #CONFVAR NUM. Whether to patch var_dump() with xdebug_var_dump(): 0 (no) or 1|2 (yes)
#If 2 (def), also prepends __FILENAME__:__LINE__
xdebug.var_display_max_depth #CONFVAR NUM. Max OBJ|ARR depth (def: 3). -1 for unlim
xdebug.var_display_max_children #CONFVAR NUM. Max OBJ|ARR members max length (def: 128). -1 for unlim
xdebug.var_display_max_data #CONFVAR NUM. Max STR display max length (def: 512). -1 for unlim
┌───────────────────┐
│ SCOPE LOGGING │
└───────────────────┘
xdebug_dump.VAR VAR2,... #CONFVAR STR. Superglobals, printed:
# - with xdebug_dump_superglobals()
# - on notice or uncaught exceptions:
# - if CONFVAR xdebug.dump_globals 1 (def)
# - only the first time, if CONFVAR xdebug.dump_once 1 (def)
#Prints only variable name (not value) if undefined and CONFVAR xdebug.dump_undefined 0 (def)
#For $GLOBALS["VAR"]["VAR2"], where VAR2 can be * for all
xdebug_get_declared_vars()->ARR #Returns current scope variables.
#Must set CONFVAR xdebug.collect_vars to 1 (def: 0)
xdebug.show_local_vars #CONFVAR 0|1 (def: 0). Show current scope variables in stack traces
xdebug_get_headers()->STR_ARR #Retrieves all HTTP headers set with header()
┌────────────────────────────────┐
│ GARBAGE COLLECTION LOGGING │
└────────────────────────────────┘
xdebug_debug_zval[_stdout]('VAR') #Prints info about $VAR: refcount, whether reference, type, length, value
#"_stdout" prints directly to stdout, even when using web server API layer, but does not seem to work in console
┌─────────────────┐
│ STACK TRACE │
└─────────────────┘
xdebug_enable|disable() #Prints stack traces on notices or uncaught exceptions
xdebug_is_enabled()->BOOL #
xdebug.default_enable #CONFVAR NUM 0|1 (def: 1)
xdebug.show_exception_trace #If 1 (def: 0), prints stack traces on [un]caught exceptions
xdebug.show_error_trace #If 1 (def: 0), prints stack traces on [un]caught exceptions|errors
xdebug.collect_params #CONFVAR. What to print about current function parameters:
# - 0 (def): nothing
# - 1: type + arity
# - 2: type + arity + extra info as tooltip (not in CLI)
# - 3: type + arity + content
# - 4: type + arity + content + variable name
# - 5: serialize()'d
xdebug.collect_return #CONFVAR 0|1 (def: 1). Whether to print return value
xdebug.collect_includes #CONFVAR 0|1 (def: 1). Whether to print filenames of included files
xdebug.max_nesting_level #CONFVAR NUM. Max function depth (def: 256)
xdebug.max_stack_frames #CONFVAR NUM. Max stack depth (def: -1, i.e. unlim)
xdebug.file_link_format #CONFVAR STR. How filename + line number are formatted, using %f and %l escape sequences.
#Used with IDEs that would parse special format as a hyperlink to specific place in the code.
xdebug.manual_url #CONFVAR STR (def: 'http://www.php.net'). Base URL to manual pages links present in some notice messages
xdebug_get_function_stack()->ARR #Stack trace, as ARR_ARR2:
# - file STR
# - line NUM
# - class STR
# - function STR
# - params ARR3
xdebug_print_function_stack #Print stack trace in user-friendly format with:
([STR[, NUM]]) # - file, line, class, function, params
# - execution time
# - amount of memory
#There is also header (unless NUM 1), which can include STR if specified
xdebug_get_stack_depth()->NUM #I.e. Stack trace length (0 for top-level)
xdebug_call_class|function|file|
line()->STR #Similar to __CLASS|FUNCTION|FILE|LINE__
┌────────────────────┐
│ FUNCTION TRACE │
└────────────────────┘
xdebug_start_trace(['FILE'[,NUM]])#Function tracing, i.e. information on each function call|return|exit: format identifier|name, stack depth,
xdebug_stop_trace() #type (function call|return|exit), timestamp, memory usage, return value, stack trace
#Writes it to 'FILE':
# - def DIR: CONFVAR xdebug.trace_output_dir (def: /tmp)
# - def FILENAME: CONFVAR xdebug.trace_output_name STR (def: 'trace.%c') + '.xt'
# - can contain escape sequence (see online doc)
#NUM are bitwise options (all off by def):
# - XDEBUG_TRACE_APPEND: like xdebug.trace_options 1
# - XDEBUG_TRACE_COMPUTERIZED|HTML: like xdebug.trace_format 1|2
# - XDEBUG_TRACE_NAKED_FILENAME: does not append ".xt" to 'FILE'
xdebug_get_tracefile_name()->'FIL'#
xdebug.trace_format #CONFVAR NUM. How function tracing looks like among:
# - 0 (def): human-friendly CLI
# - 1: parse-friendly CLI
# - 2: HTML
xdebug.trace_options #CONFVAR NUM. If 1 (def: 0), append instead of overwrite file
xdebug.auto_trace #CONFVAR NUM. If 1 (def: 0), does xdebug_start_trace() at beginning of script
xdebug.trace_enable_trigger #CONFVAR NUM. If 1 (def: 0), does xdebug_start_trace() by setting query variable, request body variable or cookie XDEBUG_TRACE
#XDEBUG_TRACE must have value set to xdebug.trace_enable_trigger_value CONFVAR STR (def: "", i.e. any)
xdebug.collect_assignments #CONFVAR 0|1 (def: 1). Whether to print assignments
┌────────────────┐
│ CALL TRACE │
└────────────────┘
xdebug_start_function_monitor
('[CLASS::]FUNC'_ARR)
xdebug_stop_function_monitor() #Specifies functions to print with xdebug_get_monitored_functions()
xdebug_get_monitored_functions() #Returns ARR of when the functions were called:
->ARR # - function STR
# - filename STR
# - lineno NUM
┌──────────────────┐
│ NOTICE TRACE │
└──────────────────┘
xdebug.halt_level #CONFVAR E_* (def: none). Make notice >= that level throw an error instead.
xdebug_start_error_collection()
xdebug_stop_error_collection() #Start|stop error tracing, i.e. collects any notice.
xdebug_get_collected_errors #Gets all collected notices as STR (notice + its stack trace)
([BOOL])->STR_ARR #If BOOL true, empties.
┌───────────────────┐
│ CPU PROFILING │
└───────────────────┘
PROFILING ==> #Creates profiling file, in Cachegrid format (like Valgrind). Can visualize with tools like "webgrind"
#Will show which function took how much percentage of execution time, and how many times called.
#Options are similar to function trace's ones, but for profiling:
# - xdebug.profiler_enable: similar to xdebug.auto_trace
# - xdebug.profiler_enable_trigger[_value]: similar to xdebug.trace_enable_trigger[_value], using XDEBUG_PROFILE
# - xdebug.profiler_output_dir|name: similar to xdebug.trace_dir|name
# - xdebug.profiler_append: similar to xdebug.trace_options
xdebug.profiler_aggregate #CONFVAR NUM. If 0 (def), use one file per script execution. Otherwise, keep same one and do average.
┌──────────────────────┐
│ MEMORY PROFILING │
└──────────────────────┘
xdebug_memory_usage()->NUM #In bytes. Current one
xdebug_peak_memory_usage()->NUM #In bytes. Max for that session
xdebug.show_mem_delta #CONFVAR 0|1 (def: 0). Show memory usage in stack traces
┌────────────────────┐
│ TIME PROFILING │
└────────────────────┘
xdebug_time_index()->FLOAT #In seconds, nanoseconds-precise. Since beginning of session
┌───────────────────┐
│ CODE COVERAGE │
└───────────────────┘
xdebug_start_code_coverage([NUM]) #Start code coverage analysis, e.g. during unit testing
xdebug_stop_code_coverage([BOOL]) #NUM is bitwise options:
# - XDEBUG_CC_UNUSED|DEAD_CODE: enable -1 or -2 values (see below). Much slower
#Must pass BOOL false if want to start again later, or to use xdebug_get_code_coverage() later.
xdebug_get_code_coverage()->ARR #ARR.FILE.LINENUMBER VAL, where VAL can be: 1 (covered), -1 (not covered), -2 (no code on this line)
xdebug_code_coverage_started()
->BOOL #
xdebug.coverage_enable #CONVAR 1|0 (def: 1). Does not start coverage, just allow it.