Xdebug document (iii) stack tracing and xdebug document stack Tracing
When xdebug is activated, once PHP displays notifications, warnings, or errors, xdebug displays stack trace information. This stack information can be configured and displayed according to your needs.
The stack trace displayed in Xdebug displays information in a conservative quantity. Because a large amount of information processing and presentation will slow the script execution. It is possible to display more detailed information through different settings.
Stack trace Variables
Xdebug usually displays variable information during stack tracing. Variable information carries a large amount of resources when collected and displayed. However, in many cases, the display of these variables is very helpful, Which is why xdebug. clollect_params is set. The following script outputs different information when setting different values:
The script
<?phpfunction foo( $a ) { for ($i = 1; $i < $a['foo']; $i++) { if ($i == 500000) xdebug_break(); }}set_time_limit(1);$c = new stdClass;$c->bar = 100;$a = array( 42 => false, 'foo' => 912124, $c, new stdClass, fopen( '/etc/passwd', 'r' ));foo( $a );?>
Default Value:
(! )Fatal error: Maximum execution time of 1 second exceeded in/home/httpd/html/test/xdebug/docs/stack. php on line34 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0001 |
58564 |
{Main }() |
../Stack. php:0 |
2 |
0.0004 |
62764 |
Foo () |
../Stack. php:47 |
1 value:
Ini_set ('xdebug. collect_params ', '1 ');
(! )Fatal error: Maximum execution time of 1 second exceeded in/home/httpd/html/test/xdebug/docs/stack. php on line31 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0001 |
58132 |
{Main }() |
../Stack. php:0 |
2 |
0.0004 |
62380 |
Foo (array (5 )) |
../Stack. php:47 |
2 value:
Ini_set ('xdebug. collect_params ', '2 ');
(! )Fatal error: Maximum execution time of 1 second exceeded in/home/httpd/html/test/xdebug/docs/stack. php on line31 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0001 |
58564 |
{Main }() |
../Stack. php:0 |
2 |
0.0004 |
62812 |
Foo (array (5 )) |
../Stack. php:47 |
Value 3:
Ini_set ('xdebug. collect_params ', '3 ');
(! )Fatal error: Maximum execution time of 1 second exceeded in/home/httpd/html/test/xdebug/docs/stack. php on line31 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0001 |
58564 |
{Main }() |
../Stack. php:0 |
2 |
0.0004 |
62812 |
Foo (array (42 => FALSE, 'foo' => 912124, 43 => class stdClass {public $ bar = 100}, 44 => class stdClass {}, 45 => resource (2) of type (stream ))) |
../Stack. php:47 |
4 value:
ini_set('xdebug.collect_params', '4');
(! )Fatal error: Maximum execution time of 1 second exceeded in/home/httpd/html/test/xdebug/docs/stack. php on line31 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0001 |
58132 |
{Main }() |
../Stack. php:0 |
2 |
0.0004 |
62380 |
Foo ($ a = array (42 => FALSE, 'foo' => 912124, 43 => class stdClass {public $ bar = 100}, 44 => class stdClass {}, 45 => resource (2) of type (stream ))) |
../Stack. php:47 |
Related settings:
Xdebug. cli_color
Type: integer. Default Value: 0. It starts with version 2.2 or later.
When it is set to 1, xdebug displays the output text of the var_dump trace in CLI mode and when it is output on the tty terminal. The ANSICON tool must be installed in windows.
When set to 2, xdebug displays var_dump and debug trace information in color regardless of whether it is connected to the tty terminal or whether ANSICON is installed. In this case, you may see the escape code at the end.
Xdebug. collect_effecdes
Type:Boolean, Default value:1
By default, xdebug writes the file names referenced by the include (), include_once (), require (), or require_once () Methods to the trace file.
Xdebug. collect_params
Type:Integer, Default value:0
When the default value is 0, xdebug controls whether function tracing or stack tracing to collect parameters of function calls.
The default value 0 indicates that a large script occupies a large amount of memory, so it will not run for a large script. You can enable this setting safely, but you will expect some script problems, such as a large number of function calls and a large data structure, to be passed as parameters. Xdebug2 will not increase memory usage because it will not be stored in the memory, but will only be stored in the disk. You only need to have enough disk usage.
This setting has four setting values. Each type presents different information. The following table lists the set values:
Value |
Argument Information Shown |
0 |
None. |
1 |
The value type and value of the variable element. |
2 |
Displays the value type and value of the variable element, and displays complete information with a mouse prompt. (The mouse prompt does not exist in CLI mode) |
3 |
Complete variable content (content is subject to the following settings: xdebug. var_display_max_children, xdebug. var_display_max_data and xdebug. var_display_max_depth .) |
4 |
Complete variable content and name. |
5 |
PHP serialization variable content, excluding names.(2.3New version features) |
Xdebug. collect_vars
Type:Boolean, Default value:0
This setting allows xdebug to collect variable information within a certain range. This analysis is quite slow because xdebug will reverse parse the PHP code. This setting does not record the values of different variables. If you want to use the xdebug_get_declared_vars () function, you need to enable this setting.
Xdebug. dump .*
Type:String, Default value:Empty
* Can be replaced by any COOKIE, FILES, GET, POST, REQUEST, SERVER, and SESSION. These seven values control the data of the Super global variables when an error occurs.
In php. ini, each set value is separated by commas to form a list of variables, or the number * indicates all variables. Make sure that you have no space in the settings.
To receive REMOTE_ADDR and REQUEST_METHOD information and all GET parameters when an error occurs, you can set:
Xdebug. dump. SERVER = REMOTE_ADDR, REQUEST_METHOD
Xdebug. dump. GET = *
Xdebug. dump_globals
Type:Boolean, Default:1
Determines whether the value of the Super global variable is displayed, regardless of what is set in xdebug. dump.
Xdebug. dump_once
Type:Boolean, Default value:1
Determines whether to display the value of the Super global variable (set to 0) or only appears for the first time (set to 1) in case of all errors ).
Xdebug. dump_undefined
Type:Boolean, Default value:0
If you want to display undefined values in the super global variable, set this item to 1. Otherwise, the default value 0 is retained.
Xdebug. manual_url
Type:String, Default value:Http://www.php.net, StartsXdebug 2.2.1Versions below
Specifies the source of function tracing and error information links. We recommend that you set the latest image link.
Xdebug. show_exception_trace
Type:Integer, Default value:0
When it is set to 1, Xdebug displays its stack trace information when an exception occurs or even when the exception is caught.
Xdebug. show_local_vars
Type:Integer, Default value:0
When it is set to a non-zero value, the stack trace generated by Xdebug in case of an error will display information about all variables in the top range. This may produce a lot of information, so it is disabled by default.
Xdebug. show_mem_delta
Type:Integer, Default value:0
When this setting is not 0, the xdebug human readability tracking file displays the memory usage during function calling. If the xdebug configuration value is to generate machine readable tracing files, they often display this information. ,
Xdebug. var_display_max_children
Type: integer; default value: 128
When xdebug_var_dump (), xdebug. show_local_vars, or tracing function is used, this setting controls the display of the number of array elements and object attributes.
If not limited, it can be set to-1.
This setting is not affected by Remot_Debuggin remote debugging.
Xdebug. var_display_max_data
Type: integer; default value: 512
When xdebug_var_dump (), xdebug. show_local_vars, or tracing function is used, this setting controls the maximum value of String Length display.
If not limited, it can be set to-1.
This setting is not affected by Remot_Debugging remote debugging.
Xdebug. var_display_max_depth
Type:Integer, Default value:3
When xdebug_var_dump (), xdebug. show_local_vars, or tracing function is used, this setting controls the display level of array elements and object attributes.
The maximum value is 1023. You can set it to-1 to indicate its maximum value.
This setting is not affected by Remot_Debugging remote debugging.
Related functions:
Array Xdebug_get_declared_vars ()
Returns an array with the variable names defined in the current range. To make the function take effect, xdebug. collect_vars must be enabled.
Example:
<?php class strings { static function fix_strings($a, $b) { foreach ($b as $item) { } var_dump(xdebug_get_declared_vars()); } } strings::fix_strings(array(1,2,3), array(4,5,6));?>/**Returns:array 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'item' (length=4) */
In versions earlier than PHP5.1, the variable name "a" is not in the returned array, because the variable is not used when the xdebug_get_declared_vars () function is executed.
ArrayXdebug_get_function_stack ()
Returns an array containing information similar to stack trace displayed at the Function Point.
Example:
<?php class strings { function fix_string($a) { var_dump(xdebug_get_function_stack()); } function fix_strings($b) { foreach ($b as $item) { $this->fix_string($item); } } } $s = new strings(); $ret = $s->fix_strings(array('Derick'));?>/**Returns:array 0 => array 'function' => string '{main}' (length=6) 'file' => string '/var/www/xdebug_get_function_stack.php' (length=63) 'line' => int 0 'params' => array empty 1 => array 'function' => string 'fix_strings' (length=11) 'class' => string 'strings' (length=7) 'file' => string '/var/www/xdebug_get_function_stack.php' (length=63) 'line' => int 18 'params' => array 'b' => string 'array (0 => 'Derick')' (length=21) 2 => array 'function' => string 'fix_string' (length=10) 'class' => string 'strings' (length=7) 'file' => string '/var/www/xdebug_get_function_stack.php' (length=63) 'line' => int 12 'params' => array 'a' => string ''Derick'' (length=8) */
Integer Xdebug_get_stack_depth ()
Returns the stack depth level. The script subject is level 0, and a stack depth level is added for various reference or call functions.
None Xdebug_print_function_stack ( [String message [, int options] )
Display the tracing information of the current function in case of an error.
The "message" parameter allows you to customize the display information.(Started fromX-Debug 2.1Version).
Example:
<?phpfunction foo( $far, $out ){ xdebug_print_function_stack( 'Your own message' );}foo( 42, 3141592654 );?>
Returns:
(! )Xdebug: Your own message in/home/httpd/html/test/xdebug/print_function_stack.php on line5 |
Call Stack |
# |
Time |
Memory |
Function |
Location |
1 |
0.0006 |
653896 |
{Main }() |
../Print_function_stack.php:0 |
2 |
0.0007 |
654616 |
Fool (42,314 1592654) |
../Print_function_stack.php:7 |
3 |
0.0007 |
654736 |
Xdebug_print_function_stack ('your own message ') |
../Print_function_stack.php:5 |
The mask parameter "options" allows you to configure additional parameter options. The following options are supported:
XDEBUG_STACK_NO_DESC
If this option is set, the displayed tracing information does not contain the header. This is useful for displaying your own Error Tracking information from a custom error processor. In addition, you can call the xdebug_print_function_statck () function at the position to be displayed. (Started with xdebug2.3)
Void Xdebug_start_function_monitor (Array $ list_of_functions_to_monitor)
Start function monitoring.
Start with version2.4
This function monitors a series of function names when passing them as parameters. Function monitor will find out the code of the functions you provide. This method can be used to track old or obsolete functions.
Example:
<?phpxdebug_start_function_monitor( [ 'strrev', 'array_push' ] );?>
You can also add class methods or static methods to the array for monitoring. For example, to capture static calls to DramModel: canSee and dynamic calls to Whisky-> drink, you can start the following monitoring:
Example:
<?phpxdebug_start_function_monitor( [ 'DramModel::canSee', 'Whisky->drink'] );?>
The defined functions are case-sensitive. Static methods cannot be captured if they are dynamically called.
Void Xdebug_stop_function_monitor ()
Stop function monitoring
Start with version2.4
This function stops monitoring functions. To obtain the list of monitored functions, you can use the xdebug_get_monitored_functions () function.