Skip to content

Commit

Permalink
- Implemented issue xdebug#517: Add a function trace trigger like for…
Browse files Browse the repository at this point in the history
… the profiler.

  Patch by Patrick Allaert <patrickallaert@php.net>.

SVN Rev: 3433
  • Loading branch information
derickr committed Mar 30, 2011
1 parent 0f31c8f commit c058887
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions php_xdebug.h
Expand Up @@ -180,6 +180,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
FILE *trace_file; FILE *trace_file;
zend_bool do_trace; zend_bool do_trace;
zend_bool auto_trace; zend_bool auto_trace;
zend_bool trace_enable_trigger;
char *trace_output_dir; char *trace_output_dir;
char *trace_output_name; char *trace_output_name;
long trace_options; long trace_options;
Expand Down
34 changes: 33 additions & 1 deletion xdebug.c
Expand Up @@ -85,6 +85,8 @@ 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_header_handler)(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC);


static int xdebug_trigger_enabled(int setting, char *var_name);

zend_function_entry xdebug_functions[] = { zend_function_entry xdebug_functions[] = {
PHP_FE(xdebug_get_stack_depth, NULL) PHP_FE(xdebug_get_stack_depth, NULL)
PHP_FE(xdebug_get_function_stack, NULL) PHP_FE(xdebug_get_function_stack, NULL)
Expand Down Expand Up @@ -236,6 +238,7 @@ static PHP_INI_MH(OnUpdateDebugMode)
PHP_INI_BEGIN() PHP_INI_BEGIN()
/* Debugger settings */ /* 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.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_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_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_format", "0", PHP_INI_ALL, OnUpdateLong, trace_format, zend_xdebug_globals, xdebug_globals)
Expand Down Expand Up @@ -809,7 +812,10 @@ PHP_RINIT_FUNCTION(xdebug)
XG(remote_enabled) = 0; XG(remote_enabled) = 0;
XG(profiler_enabled) = 0; XG(profiler_enabled) = 0;
XG(breakpoints_allowed) = 1; XG(breakpoints_allowed) = 1;
if (XG(auto_trace) && XG(trace_output_dir) && strlen(XG(trace_output_dir))) { if (
(XG(auto_trace) || xdebug_trigger_enabled(XG(trace_enable_trigger), "XDEBUG_TRACE"))
&& XG(trace_output_dir) && strlen(XG(trace_output_dir))
) {
/* In case we do an auto-trace we are not interested in the return /* In case we do an auto-trace we are not interested in the return
* value, but we still have to free it. */ * value, but we still have to free it. */
xdfree(xdebug_start_trace(NULL, XG(trace_options) TSRMLS_CC)); xdfree(xdebug_start_trace(NULL, XG(trace_options) TSRMLS_CC));
Expand Down Expand Up @@ -947,6 +953,32 @@ PHP_MINFO_FUNCTION(xdebug)
DISPLAY_INI_ENTRIES(); DISPLAY_INI_ENTRIES();
} }


static int xdebug_trigger_enabled(int setting, char *var_name)
{
zval **dummy;

if (!setting) {
return 0;
}

if (
(
PG(http_globals)[TRACK_VARS_GET] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_GET]->value.ht, var_name, strlen(var_name) + 1, (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_POST] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_POST]->value.ht, var_name, strlen(var_name) + 1, (void **) &dummy) == SUCCESS
) || (
PG(http_globals)[TRACK_VARS_COOKIE] &&
zend_hash_find(PG(http_globals)[TRACK_VARS_COOKIE]->value.ht, var_name, strlen(var_name) + 1, (void **) &dummy) == SUCCESS
)
) {
return 1;
}

return 0;
}

static void add_used_variables(function_stack_entry *fse, zend_op_array *op_array) static void add_used_variables(function_stack_entry *fse, zend_op_array *op_array)
{ {
int i = 0; int i = 0;
Expand Down

0 comments on commit c058887

Please sign in to comment.