Permalink
Browse files

- Implemented issue #517: Add a function trace trigger like for the p…

…rofiler.

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

SVN Rev: 3433
  • Loading branch information...
1 parent 0f31c8f commit c058887e110bff7edc03a06ffda575ab411558b5 @derickr derickr committed Mar 30, 2011
Showing with 34 additions and 1 deletion.
  1. +1 −0 php_xdebug.h
  2. +33 −1 xdebug.c
View
1 php_xdebug.h
@@ -180,6 +180,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
FILE *trace_file;
zend_bool do_trace;
zend_bool auto_trace;
+ zend_bool trace_enable_trigger;
char *trace_output_dir;
char *trace_output_name;
long trace_options;
View
34 xdebug.c
@@ -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);
+static int xdebug_trigger_enabled(int setting, char *var_name);
+
zend_function_entry xdebug_functions[] = {
PHP_FE(xdebug_get_stack_depth, NULL)
PHP_FE(xdebug_get_function_stack, NULL)
@@ -236,6 +238,7 @@ static PHP_INI_MH(OnUpdateDebugMode)
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)
@@ -809,7 +812,10 @@ PHP_RINIT_FUNCTION(xdebug)
XG(remote_enabled) = 0;
XG(profiler_enabled) = 0;
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
* value, but we still have to free it. */
xdfree(xdebug_start_trace(NULL, XG(trace_options) TSRMLS_CC));
@@ -947,6 +953,32 @@ PHP_MINFO_FUNCTION(xdebug)
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)
{
int i = 0;

0 comments on commit c058887

Please sign in to comment.