Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #847: %s doesn't work in xdebug.trace_output_name #326

Merged
merged 2 commits into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/bug00847-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test for bug #847: %s doesn't work in xdebug.trace_output_name (auto_trace)
--INI--
xdebug.trace_output_name=trace.%s
xdebug.trace_options=1
xdebug.auto_trace=1
--FILE--
<?php
$trace_file = xdebug_get_tracefile_name();
echo $trace_file, "\n";
xdebug_stop_trace();
unlink($trace_file);
?>
--EXPECTF--
%strace.%s_tests_bug00847-001_php.xt
15 changes: 15 additions & 0 deletions tests/bug00847-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test for bug #847: %s doesn't work in xdebug.trace_output_name (xdebug_start_trace)
--INI--
xdebug.trace_output_name=trace.%s
xdebug.trace_options=1
xdebug.auto_trace=0
--FILE--
<?php
xdebug_start_trace();
$trace_file = xdebug_get_tracefile_name();
echo $trace_file, "\n";
xdebug_stop_trace();
?>
--EXPECTF--
%strace.%s_tests_bug00847-002_php.xt
7 changes: 4 additions & 3 deletions tests/bug01112.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Test for bug #1112: Setting an invalid xdebug.trace_format causes Xdebug to cras
xdebug.trace_format=42
xdebug.auto_trace=1
xdebug.default_enable=1
log_errors=1
log_errors=0
--FILE--
<?php
echo strlen("45"), "\n";
?>
--EXPECT--
PHP Notice: A wrong value for xdebug.trace_format was selected (42), defaulting to the textual format. in Unknown on line 0
--EXPECTF--
Notice: A wrong value for xdebug.trace_format was selected (42), defaulting to the textual format in %s/bug01112.php on line 2

2
17 changes: 9 additions & 8 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,14 +1127,6 @@ PHP_RINIT_FUNCTION(xdebug)
XG(remote_enabled) = 0;
XG(profiler_enabled) = 0;
XG(breakpoints_allowed) = 1;
if (
(XG(auto_trace) || xdebug_trigger_enabled(XG(trace_enable_trigger), "XDEBUG_TRACE", XG(trace_enable_trigger_value) TSRMLS_CC))
&& 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));
}

/* Initialize some debugger context properties */
XG(context).program_name = NULL;
Expand Down Expand Up @@ -1661,6 +1653,15 @@ void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
XG(profiler_enabled) = 1;
}
}

if (
(XG(auto_trace) || xdebug_trigger_enabled(XG(trace_enable_trigger), "XDEBUG_TRACE", XG(trace_enable_trigger_value) TSRMLS_CC))
&& 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, STR_NAME_VAL(op_array->filename), XG(trace_options) TSRMLS_CC));
}
}

XG(level)++;
Expand Down
4 changes: 2 additions & 2 deletions xdebug_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "TSRM.h"
#endif

char* xdebug_start_trace(char* fname, long options TSRMLS_DC);
char* xdebug_start_trace(char* fname, char *script_filename, long options TSRMLS_DC);
void xdebug_stop_trace(TSRMLS_D);

typedef struct xdebug_var {
Expand Down Expand Up @@ -212,7 +212,7 @@ function_stack_entry *xdebug_get_stack_tail(TSRMLS_D);

typedef struct
{
void *(*init)(char *fname, long options TSRMLS_DC);
void *(*init)(char *fname, char *script_filename, long options TSRMLS_DC);
void (*deinit)(void *ctxt TSRMLS_DC);
void (*write_header)(void *ctxt TSRMLS_DC);
void (*write_footer)(void *ctxt TSRMLS_DC);
Expand Down
4 changes: 2 additions & 2 deletions xdebug_trace_computerized.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

extern ZEND_DECLARE_MODULE_GLOBALS(xdebug);

void *xdebug_trace_computerized_init(char *fname, long options TSRMLS_DC)
void *xdebug_trace_computerized_init(char *fname, char *script_filename, long options TSRMLS_DC)
{
xdebug_trace_computerized_context *tmp_computerized_context;
char *used_fname;

tmp_computerized_context = xdmalloc(sizeof(xdebug_trace_computerized_context));
tmp_computerized_context->trace_file = xdebug_trace_open_file(fname, options, (char**) &used_fname TSRMLS_CC);
tmp_computerized_context->trace_file = xdebug_trace_open_file(fname, script_filename, options, (char**) &used_fname TSRMLS_CC);
tmp_computerized_context->trace_filename = used_fname;

return tmp_computerized_context->trace_file ? tmp_computerized_context : NULL;
Expand Down
4 changes: 2 additions & 2 deletions xdebug_trace_html.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

extern ZEND_DECLARE_MODULE_GLOBALS(xdebug);

void *xdebug_trace_html_init(char *fname, long options TSRMLS_DC)
void *xdebug_trace_html_init(char *fname, char *script_filename, long options TSRMLS_DC)
{
xdebug_trace_html_context *tmp_html_context;
char *used_fname;

tmp_html_context = xdmalloc(sizeof(xdebug_trace_html_context));
tmp_html_context->trace_file = xdebug_trace_open_file(fname, options, (char**) &used_fname TSRMLS_CC);
tmp_html_context->trace_file = xdebug_trace_open_file(fname, script_filename, options, (char**) &used_fname TSRMLS_CC);
tmp_html_context->trace_filename = used_fname;

return tmp_html_context->trace_file ? tmp_html_context : NULL;
Expand Down
4 changes: 2 additions & 2 deletions xdebug_trace_textual.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

extern ZEND_DECLARE_MODULE_GLOBALS(xdebug);

void *xdebug_trace_textual_init(char *fname, long options TSRMLS_DC)
void *xdebug_trace_textual_init(char *fname, char *script_filename, long options TSRMLS_DC)
{
xdebug_trace_textual_context *tmp_textual_context;
char *used_fname;

tmp_textual_context = xdmalloc(sizeof(xdebug_trace_textual_context));
tmp_textual_context->trace_file = xdebug_trace_open_file(fname, options, (char**) &used_fname TSRMLS_CC);
tmp_textual_context->trace_file = xdebug_trace_open_file(fname, script_filename, options, (char**) &used_fname TSRMLS_CC);
tmp_textual_context->trace_filename = used_fname;

return tmp_textual_context->trace_file ? tmp_textual_context : NULL;
Expand Down
16 changes: 10 additions & 6 deletions xdebug_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ xdebug_trace_handler_t *xdebug_select_trace_handler(int options TSRMLS_DC)
case 1: tmp = &xdebug_trace_handler_computerized; break;
case 2: tmp = &xdebug_trace_handler_html; break;
default:
php_error(E_NOTICE, "A wrong value for xdebug.trace_format was selected (%d), defaulting to the textual format.", (int) XG(trace_format));
php_error(E_NOTICE, "A wrong value for xdebug.trace_format was selected (%d), defaulting to the textual format", (int) XG(trace_format));
tmp = &xdebug_trace_handler_textual; break;
}

Expand All @@ -53,7 +53,7 @@ xdebug_trace_handler_t *xdebug_select_trace_handler(int options TSRMLS_DC)
return tmp;
}

FILE *xdebug_trace_open_file(char *fname, long options, char **used_fname TSRMLS_DC)
FILE *xdebug_trace_open_file(char *fname, char *script_filename, long options, char **used_fname TSRMLS_DC)
{
FILE *file;
char *filename;
Expand All @@ -62,7 +62,7 @@ FILE *xdebug_trace_open_file(char *fname, long options, char **used_fname TSRMLS
filename = xdstrdup(fname);
} else {
if (!strlen(XG(trace_output_name)) ||
xdebug_format_output_filename(&fname, XG(trace_output_name), NULL) <= 0
xdebug_format_output_filename(&fname, XG(trace_output_name), script_filename) <= 0
) {
/* Invalid or empty xdebug.trace_output_name */
return NULL;
Expand All @@ -84,10 +84,10 @@ FILE *xdebug_trace_open_file(char *fname, long options, char **used_fname TSRMLS
return file;
}

char* xdebug_start_trace(char* fname, long options TSRMLS_DC)
char* xdebug_start_trace(char* fname, char *script_filename, long options TSRMLS_DC)
{
XG(trace_handler) = xdebug_select_trace_handler(options TSRMLS_CC);
XG(trace_context) = (void*) XG(trace_handler)->init(fname, options TSRMLS_CC);
XG(trace_context) = (void*) XG(trace_handler)->init(fname, script_filename, options TSRMLS_CC);

if (XG(trace_context)) {
XG(do_trace) = 1;
Expand Down Expand Up @@ -116,11 +116,15 @@ PHP_FUNCTION(xdebug_start_trace)
zend_long options = XG(trace_options);

if (XG(do_trace) == 0) {
function_stack_entry *fse;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &fname, &fname_len, &options) == FAILURE) {
return;
}

if ((trace_fname = xdebug_start_trace(fname, options TSRMLS_CC)) != NULL) {
fse = xdebug_get_stack_frame(0 TSRMLS_CC);

if ((trace_fname = xdebug_start_trace(fname, fse->filename, options TSRMLS_CC)) != NULL) {
XG(do_trace) = 1;
RETVAL_STRING(trace_fname);
xdfree(trace_fname);
Expand Down
2 changes: 1 addition & 1 deletion xdebug_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
char* xdebug_return_trace_stack_retval(function_stack_entry* i, int fnr, zval* retval TSRMLS_DC);
char* xdebug_return_trace_stack_generator_retval(function_stack_entry* i, zend_generator* generator TSRMLS_DC);
char* xdebug_return_trace_assignment(function_stack_entry *i, char *varname, zval *retval, char *op, char *file, int fileno TSRMLS_DC);
FILE *xdebug_trace_open_file(char *fname, long options, char **used_fname TSRMLS_DC);
FILE *xdebug_trace_open_file(char *fname, char *script_filename, long options, char **used_fname TSRMLS_DC);

void xdebug_trace_function_begin(function_stack_entry *fse, int function_nr TSRMLS_DC);
void xdebug_trace_function_end(function_stack_entry *fse, int function_nr TSRMLS_DC);
Expand Down