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

Fix issue1385: IS_INDIRECT when fetching private properties #316

Merged
merged 1 commit into from Jan 8, 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
3 changes: 3 additions & 0 deletions tests/bug01073-php55.phpt
Expand Up @@ -11,6 +11,9 @@ xdebug.collect_vars=0
xdebug.collect_params=4
xdebug.collect_return=0
xdebug.collect_assignments=0
xdebug.var_display_max_children=128
xdebug.var_display_max_data=512
xdebug.var_display_max_depth=3
--FILE--
<?php
$tf = xdebug_start_trace(sys_get_temp_dir() . '/'. uniqid('xdt', TRUE));
Expand Down
22 changes: 22 additions & 0 deletions tests/bug01385.inc
@@ -0,0 +1,22 @@
<?php
$v = "";

class Foo
{
private $a;
public function __construct($a) {
$this->a = $a;
}
}
class Bar extends Foo
{
public $a;
public function __construct($fooA, $a) {
parent::__construct($fooA);
$this->a = $a;
}
}

$v = new Foo(new Bar(new Foo(new Foo(2)), 1));

var_dump($v); // breakpoint
42 changes: 42 additions & 0 deletions tests/bug01385.phpt
@@ -0,0 +1,42 @@
--TEST--
DBGP: property_value
--SKIPIF--
<?php if (getenv("SKIP_DBGP_TESTS")) { exit("skip Excluding DBGp tests"); } ?>
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/bug01385.inc');

$commands = array(
'step_into',
'breakpoint_set -t line -n 22',
'run',
'property_get -d 0 -c 0 -n $v->a->*Foo*a->a',
'property_get -d 0 -c 0 -n $v->a->a'
);

dbgpRun( $data, $commands );
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///%sxdebug-dbgp-test.php" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" idekey=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-%d by Derick Rethans]]></copyright></init>

-> step_into -i 1
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="1" status="break" reason="ok"><xdebug:message filename="file:///%sxdebug-dbgp-test.php" lineno="2"></xdebug:message></response>

-> breakpoint_set -i 2 -t line -n 22
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id=""></response>

-> run -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file:///%sxdebug-dbgp-test.php" lineno="22"></xdebug:message></response>

-> property_get -i 4 -d 0 -c 0 -n $v->a->*Foo*a->a
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$v-&gt;a-&gt;*Foo*a-&gt;a" fullname="$v-&gt;a-&gt;*Foo*a-&gt;a" type="object" classname="Foo" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$v-&gt;a-&gt;*Foo*a-&gt;a-&gt;a" facet="private" type="int"><![CDATA[2]]></property></property></response>

-> property_get -i 5 -d 0 -c 0 -n $v->a->a
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="5"><property name="$v-&gt;a-&gt;a" fullname="$v-&gt;a-&gt;a" type="int"><![CDATA[1]]></property></response>
15 changes: 12 additions & 3 deletions tests/dbgp/dbgpclient.php
Expand Up @@ -4,7 +4,8 @@

class DebugClient
{
protected $port = 9991;
// free port will be selected automatically by the operating system
protected $port = 0;

private $tmpDir;

Expand Down Expand Up @@ -33,9 +34,15 @@ public function __construct()
$this->tmpDir = sys_get_temp_dir();
}

private function open()
private function open( &$errno, &$errstr )
{
$socket = @stream_socket_server( $this->getAddress(), $errno, $errstr );
if ($socket)
{
$name = stream_socket_get_name( $socket, false );
$name = explode( ":", $name );
$this->port = array_pop( $name );
}
return $socket;
}

Expand Down Expand Up @@ -106,10 +113,12 @@ function runTest( $data, array $commands, array $ini_options = null )
{
file_put_contents( $this->tmpDir . '/xdebug-dbgp-test.php', $data );
$i = 1;
$socket = $this->open();
$socket = $this->open( $errno, $errstr );
if ( $socket === false )
{
echo "Could not create socket server - already in use?\n";
echo "Error: {$errstr}, errno: {$errno}\n";
echo "Address: {$this->getAddress()}\n";
return;
}
$php = $this->launchPhp( $ppipes, $ini_options );
Expand Down
22 changes: 17 additions & 5 deletions xdebug_var.c
Expand Up @@ -243,11 +243,6 @@ zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *n

inline static HashTable *fetch_ht_from_zval(zval *z TSRMLS_DC)
{
#if PHP_VERSION_ID >= 70000
if (Z_TYPE_P(z) == IS_REFERENCE) {
z = &z->value.ref->val;
}
#endif
switch (Z_TYPE_P(z)) {
case IS_ARRAY:
return Z_ARRVAL_P(z);
Expand All @@ -264,6 +259,13 @@ inline static char *fetch_classname_from_zval(zval *z, int *length, zend_class_e
{
zend_string *class_name;

if (Z_TYPE_P(z) == IS_INDIRECT) {
z = z->value.zv;
}
if (Z_TYPE_P(z) == IS_REFERENCE) {
z = &z->value.ref->val;
}

if (Z_TYPE_P(z) != IS_OBJECT) {
return NULL;
}
Expand Down Expand Up @@ -405,6 +407,15 @@ static zval* fetch_zval_from_symbol_table(zval *parent, char* name, unsigned int
zend_property_info *zpp;

if (parent) {
#if PHP_VERSION_ID >= 70000
if (Z_TYPE_P(parent) == IS_INDIRECT) {
parent = parent->value.zv;
}
if (Z_TYPE_P(parent) == IS_REFERENCE) {
parent = &parent->value.ref->val;
}
#endif

ht = fetch_ht_from_zval(parent TSRMLS_CC);
}

Expand Down Expand Up @@ -648,6 +659,7 @@ static zval* fetch_zval_from_symbol_table(zval *parent, char* name, unsigned int
if (element) {
free(element);
}

return retval_p;
}

Expand Down