Skip to content

Commit

Permalink
Fixed issue #1105: Setting properties without specifying a type only …
Browse files Browse the repository at this point in the history
…works in topmost frame

To do this we have to backup and restore many executor globals,
since property_set without the -t (type) parameter internally
uses zend_eval_string() which needs to be at the correct frame
to work properly.
  • Loading branch information
ddelbondio authored and derickr committed Feb 15, 2015
1 parent 56ed250 commit bdba3ad
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/bug01105.inc
@@ -0,0 +1,19 @@
<?php
function scope0() {
$var = 'scope0';
$break = null;
}

function scope1() {
$var = 'scope1';
scope0();
}

function scope2() {
$var = 'scope2';
scope1();
}

scope2();

?>
65 changes: 65 additions & 0 deletions tests/bug01105.phpt
@@ -0,0 +1,65 @@
--TEST--
Test for bug #1105: Setting properties without specifying a type only works in topmost frame
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/bug01105.inc');

$commands = array(
'step_into',
'breakpoint_set -t line -n 5',
'run',
'property_set -n $var -d 0 -- ' . base64_encode('"scope0-modified"'),
'property_set -n $var -d 1 -- ' . base64_encode('"scope1-modified"'),
'property_set -n $var -d 2 -- ' . base64_encode('"scope2-modified"'),
'property_get -n $var -d 0',
'property_get -n $var -d 1',
'property_get -n $var -d 2',
'detach',
);

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:///tmp/xdebug-dbgp-test.php" language="PHP" 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-2099 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:///tmp/xdebug-dbgp-test.php" lineno="2"></xdebug:message></response>

-> breakpoint_set -i 2 -t line -n 5
<?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:///tmp/xdebug-dbgp-test.php" lineno="5"></xdebug:message></response>

-> property_set -i 4 -n $var -d 0 -- InNjb3BlMC1tb2RpZmllZCI=
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_set" transaction_id="4" success="1"></response>

-> property_set -i 5 -n $var -d 1 -- InNjb3BlMS1tb2RpZmllZCI=
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_set" transaction_id="5" success="1"></response>

-> property_set -i 6 -n $var -d 2 -- InNjb3BlMi1tb2RpZmllZCI=
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_set" transaction_id="6" success="1"></response>

-> property_get -i 7 -n $var -d 0
<?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="7"><property name="$var" fullname="$var" address="" type="string" size="15" encoding="base64"><![CDATA[c2NvcGUwLW1vZGlmaWVk]]></property></response>

-> property_get -i 8 -n $var -d 1
<?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="8"><property name="$var" fullname="$var" address="" type="string" size="15" encoding="base64"><![CDATA[c2NvcGUxLW1vZGlmaWVk]]></property></response>

-> property_get -i 9 -n $var -d 2
<?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="9"><property name="$var" fullname="$var" address="" type="string" size="15" encoding="base64"><![CDATA[c2NvcGUyLW1vZGlmaWVk]]></property></response>

-> detach -i 10
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="detach" transaction_id="10" status="stopping" reason="ok"></response>
31 changes: 31 additions & 0 deletions xdebug_handler_dbgp.c
Expand Up @@ -1811,6 +1811,8 @@ DBGP_FUNC(property_set)
function_stack_entry *fse;
xdebug_var_export_options *options = (xdebug_var_export_options*) context->options;
zval *symbol;
zend_execute_data *original_execute_data;
zval **original_return_value;
XDEBUG_STR_SWITCH_DECL;

if (!CMD_OPTION('n')) { /* name */
Expand Down Expand Up @@ -1898,10 +1900,39 @@ DBGP_FUNC(property_set)
}
}
} else {
/* backup executor state */
if(depth > 0) {
original_execute_data = EG(current_execute_data);
original_return_value = EG(return_value_ptr_ptr);

EG(current_execute_data) = XG(active_execute_data);

EG(opline_ptr) = &EG(current_execute_data)->opline;
EG(active_op_array) = EG(current_execute_data)->op_array;
EG(return_value_ptr_ptr) = EG(current_execute_data)->original_return_value;
EG(active_symbol_table) = EG(current_execute_data)->symbol_table;
EG(This) = EG(current_execute_data)->current_this;
EG(scope) = EG(current_execute_data)->current_scope;
EG(called_scope) = EG(current_execute_data)->current_called_scope;
}

/* Do the eval */
eval_string = xdebug_sprintf("%s = %s", CMD_OPTION('n'), new_value);
res = xdebug_do_eval(eval_string, &ret_zval TSRMLS_CC);

/* restore executor state */
if(depth > 0) {
EG(current_execute_data) = original_execute_data;

EG(opline_ptr) = &EG(current_execute_data)->opline;
EG(active_op_array) = EG(current_execute_data)->op_array;
EG(return_value_ptr_ptr) = original_return_value;
EG(active_symbol_table) = EG(current_execute_data)->symbol_table;
EG(This) = EG(current_execute_data)->current_this;
EG(scope) = EG(current_execute_data)->current_scope;
EG(called_scope) = EG(current_execute_data)->current_called_scope;
}

/* Free data */
xdfree(eval_string);
efree(new_value);
Expand Down

0 comments on commit bdba3ad

Please sign in to comment.