Skip to content

Commit

Permalink
Merged pull request #344
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Dec 28, 2017
2 parents 912eaeb + 6e49e6d commit 97e69ab
Show file tree
Hide file tree
Showing 35 changed files with 1,413 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .appveyor/build_task.cmd
Expand Up @@ -51,7 +51,7 @@ setlocal enableextensions enabledelayedexpansion
set SKIP_IPV6_TESTS=1
set REPORT_EXIT_STATUS=1
echo !TEST_PHP_EXECUTABLE! !TEST_PHP_ARGS! -v
echo !TEST_PHP_EXECUTABLE! -n run-tests.php -q -x --show-diff %APPVEYOR_BUILD_FOLDER%\tests
echo !TEST_PHP_EXECUTABLE! -n run-tests.php -q -x --show-diff --show-slow 1000 --set-timeout 120 -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP --temp-source c:\tests_tmp --temp-target c:\tests_tmp %APPVEYOR_BUILD_FOLDER%\tests
!TEST_PHP_EXECUTABLE! !TEST_PHP_ARGS! -v
!TEST_PHP_EXECUTABLE! -n run-tests.php -q -x --show-diff %APPVEYOR_BUILD_FOLDER%\tests

Expand Down
2 changes: 1 addition & 1 deletion config.m4
Expand Up @@ -30,7 +30,7 @@ if test "$PHP_XDEBUG" != "no"; then

CPPFLAGS=$old_CPPFLAGS

PHP_NEW_EXTENSION(xdebug, xdebug.c xdebug_branch_info.c xdebug_code_coverage.c xdebug_com.c xdebug_compat.c xdebug_handler_dbgp.c xdebug_handlers.c xdebug_llist.c xdebug_monitor.c xdebug_hash.c xdebug_private.c xdebug_profiler.c xdebug_set.c xdebug_stack.c xdebug_str.c xdebug_superglobals.c xdebug_tracing.c xdebug_trace_textual.c xdebug_trace_computerized.c xdebug_trace_html.c xdebug_var.c xdebug_xml.c usefulstuff.c, $ext_shared,,,,yes)
PHP_NEW_EXTENSION(xdebug, xdebug.c xdebug_branch_info.c xdebug_code_coverage.c xdebug_com.c xdebug_compat.c xdebug_filter.c xdebug_handler_dbgp.c xdebug_handlers.c xdebug_llist.c xdebug_monitor.c xdebug_hash.c xdebug_private.c xdebug_profiler.c xdebug_set.c xdebug_stack.c xdebug_str.c xdebug_superglobals.c xdebug_tracing.c xdebug_trace_textual.c xdebug_trace_computerized.c xdebug_trace_html.c xdebug_var.c xdebug_xml.c usefulstuff.c, $ext_shared,,,,yes)
PHP_SUBST(XDEBUG_SHARED_LIBADD)
PHP_ADD_MAKEFILE_FRAGMENT
fi
2 changes: 1 addition & 1 deletion config.w32
Expand Up @@ -5,7 +5,7 @@ ARG_WITH("xdebug", "Xdebug support", "no");

if (PHP_XDEBUG != 'no') {
var files = 'xdebug.c xdebug_branch_info.c xdebug_code_coverage.c ' +
'xdebug_com.c xdebug_compat.c xdebug_handler_dbgp.c ' +
'xdebug_com.c xdebug_compat.c xdebug_filter.c xdebug_handler_dbgp.c ' +
'xdebug_handlers.c xdebug_llist.c xdebug_monitor.c ' +
'xdebug_hash.c xdebug_private.c xdebug_profiler.c ' +
'xdebug_set.c xdebug_stack.c xdebug_str.c xdebug_superglobals.c ' +
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Expand Up @@ -148,6 +148,8 @@ Sat, Dec 2, 2018 - xdebug 2.6.0alpha1
<file name="xdebug_com.h" role="src" />
<file name="xdebug_compat.c" role="src" />
<file name="xdebug_compat.h" role="src" />
<file name="xdebug_filter.c" role="src" />
<file name="xdebug_filter.h" role="src" />
<file name="xdebug_handlers.c" role="src" />
<file name="xdebug_handlers.h" role="src" />
<file name="xdebug_handler_dbgp.c" role="src" />
Expand Down
11 changes: 11 additions & 0 deletions php_xdebug.h
Expand Up @@ -124,6 +124,9 @@ PHP_FUNCTION(xdebug_memory_usage);
PHP_FUNCTION(xdebug_peak_memory_usage);
PHP_FUNCTION(xdebug_time_index);

/* filter functions */
PHP_FUNCTION(xdebug_set_filter);

ZEND_BEGIN_MODULE_GLOBALS(xdebug)
int status;
int reason;
Expand Down Expand Up @@ -193,6 +196,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
unsigned int function_count;
int dead_code_analysis_tracker_offset;
long dead_code_last_start_id;
long code_coverage_filter_offset;
char *previous_filename;
xdebug_coverage_file *previous_file;
char *previous_mark_filename;
Expand Down Expand Up @@ -289,6 +293,13 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
/* in-execution checking */
zend_bool in_execution;
zend_bool in_var_serialisation;

/* filters */
zend_long filter_type_tracing;
zend_long filter_type_profiler;
zend_long filter_type_code_coverage;
xdebug_llist *filters_tracing;
xdebug_llist *filters_code_coverage;
ZEND_END_MODULE_GLOBALS(xdebug)

#ifdef ZTS
Expand Down
65 changes: 65 additions & 0 deletions tests/coverage-filter-path-black-1.phpt
@@ -0,0 +1,65 @@
--TEST--
Filtered code coverage: path blacklist [1]
--INI--
xdebug.auto_trace=0
xdebug.collect_return=1
xdebug.collect_params=4
xdebug.collect_assignments=0
xdebug.trace_format=0
--FILE--
<?php
$cwd = __DIR__; $s = DIRECTORY_SEPARATOR;
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_PATH_BLACKLIST, [ "{$cwd}{$s}filter{$s}xdebug" ] );

$tf = xdebug_start_code_coverage( XDEBUG_CC_DEAD_CODE | XDEBUG_CC_UNUSED );

include "$cwd/filter/foobar/foobar.php";
include "$cwd/filter/xdebug/xdebug.php";

Foobar::foo("hi");
XDEBUG::foo("hi");
Xdebug::foo("hi");

$result = xdebug_get_code_coverage();
ksort( $result );

var_dump( $result );
?>
--EXPECTF--
ello!
ello!
ello!
array(2) {
["%scoverage-filter-path-black-1.php"]=>
array(7) {
[5]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(1)
[14]=>
int(1)
}
["%sfilter%efoobar%efoobar.php"]=>
array(6) {
[2]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[11]=>
int(-1)
[12]=>
int(-1)
[14]=>
int(1)
}
}
65 changes: 65 additions & 0 deletions tests/coverage-filter-path-white-1.phpt
@@ -0,0 +1,65 @@
--TEST--
Filtered code coverage: path whitelist [1]
--INI--
xdebug.auto_trace=0
xdebug.collect_return=1
xdebug.collect_params=4
xdebug.collect_assignments=0
xdebug.trace_format=0
--FILE--
<?php
$cwd = __DIR__; $s = DIRECTORY_SEPARATOR;
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_PATH_WHITELIST, [ "{$cwd}{$s}filter{$s}xdebug" ] );

$tf = xdebug_start_code_coverage( XDEBUG_CC_DEAD_CODE | XDEBUG_CC_UNUSED );

include "$cwd/filter/foobar/foobar.php";
include "$cwd/filter/xdebug/xdebug.php";

Foobar::foo("hi");
XDEBUG::foo("hi");
Xdebug::foo("hi");

$result = xdebug_get_code_coverage();
ksort( $result );

var_dump( $result );
?>
--EXPECTF--
ello!
ello!
ello!
array(2) {
["%scoverage-filter-path-white-1.php"]=>
array(7) {
[5]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(1)
[14]=>
int(1)
}
["%sfilter%exdebug%exdebug.php"]=>
array(6) {
[2]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[11]=>
int(-1)
[12]=>
int(-1)
[14]=>
int(1)
}
}
22 changes: 22 additions & 0 deletions tests/filter-errors.phpt
@@ -0,0 +1,22 @@
--TEST--
xdebug_set_filter() wrong arguments
--INI--
html_errors=0
display_errors=1
--FILE--
<?php
xdebug_set_filter(42, XDEBUG_PATH_BLACKLIST, [ "xdebug" ] );

xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, 42, [ "xdebug" ] );

xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_BLACKLIST, [ "xdebug" ] );
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_WHITELIST, [ "xdebug" ] );
?>
--EXPECTF--
Warning: Filter group needs to be one of XDEBUG_FILTER_TRACING or XDEBUG_FILTER_CODE_COVERAGE in %sfilter-errors.php on line 2

Warning: Filter type needs to be one of XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, XDEBUG_NAMESPACE_WHITELIST, XDEBUG_NAMESPACE_BLACKLIST, or XDEBUG_FILTER_NONE in %sfilter-errors.php on line 4

Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 6

Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 7
13 changes: 13 additions & 0 deletions tests/filter/foobar/foobar.php
@@ -0,0 +1,13 @@
<?php
class Foobar
{
static function foo($s)
{
echo strstr("Hello!\n", "e");
}

static function not_used()
{
echo "this function does not get called\n";
}
}
20 changes: 20 additions & 0 deletions tests/filter/stack/one.php
@@ -0,0 +1,20 @@
<?php
namespace Stack;

class One
{
function __construct( $object )
{
$this->obj = $object;
}

function callObj( string $name, ...$arguments )
{
return $this->obj->$name( ...$arguments );
}

function error( $value )
{
trigger_error( $value, E_USER_WARNING );
}
}
20 changes: 20 additions & 0 deletions tests/filter/stack/three.php
@@ -0,0 +1,20 @@
<?php
namespace Stack;

class Three
{
function __construct( $object )
{
$this->obj = $object;
}

function callObj( string $name, ...$arguments )
{
return $this->obj->$name( ...$arguments );
}

function error( $value )
{
trigger_error( $value, E_USER_WARNING );
}
}
20 changes: 20 additions & 0 deletions tests/filter/stack/two.php
@@ -0,0 +1,20 @@
<?php
namespace Stack;

class Two
{
function __construct( $object )
{
$this->obj = $object;
}

function callObj( string $name, ...$arguments )
{
return $this->obj->$name( ...$arguments );
}

function error( $value )
{
trigger_error( $value, E_USER_WARNING );
}
}
13 changes: 13 additions & 0 deletions tests/filter/xdebug/xdebug.php
@@ -0,0 +1,13 @@
<?php
class Xdebug
{
static function foo($s)
{
echo strstr("Hello!\n", "e");
}

static function not_used()
{
echo "this function does not get called\n";
}
}
74 changes: 74 additions & 0 deletions tests/stack-filter-ns-black-1.phpt
@@ -0,0 +1,74 @@
--TEST--
Filtered stack traces: namespace blacklist [1]
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.collect_params=4
--FILE--
<?php
$cwd = __DIR__;

include "$cwd/filter/stack/one.php";
include "$cwd/filter/stack/two.php";
include "$cwd/filter/stack/three.php";

$three = new \Stack\Three( new stdClass );
$two = new \Stack\Two( $three );
$one = new \Stack\One( $two );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ 'Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '\Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '\Stack\One', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ 'Stack\Two', 'Stack\Three' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );
?>
--EXPECTF--
Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-1.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-1.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-1.php:0
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-1.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-black-1.php:22
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-1.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-black-1.php:25
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13

0 comments on commit 97e69ab

Please sign in to comment.