Xdebug debugging notes

0x01 Xdebug Profile

Xdebug is an open source PHP Debugger

 

0x02 Xdebug Configuration

Journal
xdebug.trace_output_dir: 
log trace output directory 
Xdebug . trace_output_name 
log file name, provides a series of Xdebug identifier, generates a file name corresponding format 
Xdebug . trace_options There 
record added to the file mode: 1 = append (if the file exists). 0 ( default ) = coverage (if the file exists)
Display Data
. ** Xdebug collect_params 
nonzero = the control parameter of the function display options
 0 -------- not displayed
 . 1 -------- parameter type, values (e.g.: Array (. 9)). 
2- ------- with 1, differ only slightly in the CLI
 . 3 -------- all variables content
 . 4 -------- all variable names and variable contents 
Xdebug . collect_return
 l- ------- display function return values. the Default 0 does not display
 the -Xdebug. collect_vars
 1 -------- display the current scope of which variables to use, display variable names, the value of this option does not record variables
 Xdebug **. collect_ assignments'
 1 -------- add a line to display variable assignment

 

 

Track log output directory
Xdebug. trace_format
 0 ------------------- human readable
 1 ------------------- machine-readable
 2 ------------------- HTML format

 

 

behavior

There are two ways to track, one is automatically track all php script is running, will generate trace files; the other is the trigger track

. Xdebug auto_trace
 1 --------------- open automatically track 

Xdebug . trace_enable_trigger 
Note: This feature is only 2 .2+ version in order to set
 1 ----------- ------- use XDEGUG_TRACE GET / POST trigger track, or by setting a cookie XDEGUG_TRACE, in order to avoid every request will generate the appropriate trace trace file, you need to auto_trace set to 0

 

0x03 xdebug debug log

Marked with a breakpoint on the line to debug (click the blank space to the back of the line number, once again points to cancel a breakpoint), it should be noted that when the program runs to the breakpoint, the program will stay in the bank, but the bank itself will not be executed. Since you can see all the data the program runs to contained herein. Of course, the equivalent of using a php function to view information in the var_dump.

   

  Operating procedures:
  Break point -> click on the 'bug' -> click on the browser page breakpoint is triggered -> Automatic jump back PhpStorm-> to view the data (for debugging purposes) carry -> lookup can step through the problem -> click on the Run ( or F5) -> continue browser page -> commissioning.

 

Shortcut buttons:

 

第一个按钮:step over 步越
执行当前函数的下一步,如果有子函数,也不会进入,会一直执行到函数结束

第二个按钮:step into 步入
执行当前函数的下一步,如果有子函数,会从头到尾执行子函数,还原了程序执行的最详细的路线,从构造函数到结尾的每一步都会跳到。

第三个按钮:force step into
与step into 相同,执行当前函数的下一步,如果有子函数也会进入子函数,只不过不会从头到尾的还原函数执行的路线,会直接跳到子函数内第一步,构造函数等一些前置方法会忽略

第四个按钮:step out 步出
跳出当前执行的函数,跳到父函数的下一步。

第五个按钮:run to cursor 
执行到下一个断点处

Xdebug的其他作用

很明显,有了xdebug我们不再需要在代码调试时对一些关键变量一个一个echo或var_dump了,而且我们可以使程序运行到断点时挂起,从而更加精确地锁定出bug的代码的位置。同时Xdebug具有追溯代码的跟踪回溯功能,这样在一些大型的程序的中,即使调用逻辑很复杂,我们也能顺蔓摸瓜一步步到达错误发生的地方。

除此之外,我们可以使用xdebug_time_index()来显示脚本运行时间;可以使用xdebug_memory_usage()来测定脚本占用内存;同时我们还可以查询xdebug的输出日志来查询程序运行的相关信息。

Xdebug自带了一个函数xdebug_time_index()来显示时间。

 


 

 

Guess you like

Origin www.cnblogs.com/-qing-/p/11259195.html