Permalink
Browse files

Implemented issue #406: Added support for remote debugging user-defin…

…ed constants.
  • Loading branch information...
derickr committed Jan 10, 2014
1 parent 6242ae1 commit 6ff33fcd4d452a06d4a80b995a5630abd9c11158
@@ -88,7 +88,7 @@ dbgpRun( $data, $commands );

-> context_names -i 15
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="15"><context name="Locals" id=""></context><context name="Superglobals" id=""></context></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="15"><context name="Locals" id=""></context><context name="Superglobals" id=""></context><context name="User defined constants" id=""></context></response>

-> run -i 16
<?xml version="1.0" encoding="iso-8859-1"?>
@@ -0,0 +1,4 @@
<?php
define("YES", M_PI); $NO = 42;
echo "hi\n";
?>
@@ -0,0 +1,40 @@
--TEST--
DBGP: context_get
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/dbgp-context-get.inc');
$commands = array(
'step_into',
'step_into',
'step_into',
'context_get -c 0',
'context_get -c 2',
);
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-2013 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>

-> step_into -i 2
<?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="2" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="2"></xdebug:message></response>

-> step_into -i 3
<?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="3" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="3"></xdebug:message></response>

-> context_get -i 4 -c 0
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="0"><property name="$NO" fullname="$NO" address="" type="int"><![CDATA[42]]></property></response>

-> context_get -i 5 -c 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="5" context="2"><property name="YES" fullname="YES" address="" type="float" facet="constant"><![CDATA[3.1415926535898]]></property></response>
@@ -0,0 +1,50 @@
--TEST--
DBGP: property_get (constants)
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/dbgp-context-get.inc');
$commands = array(
'step_into',
'step_into',
'step_into',
'context_get -c 2',
'property_get -c 2 -n YES',
'property_get -c 2 -n NO',
'property_get -c 2 -n $YES',
);
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-2013 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>

-> step_into -i 2
<?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="2" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="2"></xdebug:message></response>

-> step_into -i 3
<?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="3" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="3"></xdebug:message></response>

-> context_get -i 4 -c 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="2"><property name="YES" fullname="YES" address="" type="float" facet="constant"><![CDATA[3.1415926535898]]></property></response>

-> property_get -i 5 -c 2 -n YES
<?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="YES" fullname="YES" address="" type="float" facet="constant"><![CDATA[3.1415926535898]]></property></response>

-> property_get -i 6 -c 2 -n NO
<?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="6" status="break" reason="ok"><error code="300"><message><![CDATA[can not get property]]></message></error></response>

-> property_get -i 7 -c 2 -n $YES
<?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" status="break" reason="ok"><error code="300"><message><![CDATA[can not get property]]></message></error></response>
@@ -714,7 +714,7 @@ void xdebug_open_log(TSRMLS_D)
fprintf(XG(remote_log_file), "Log opened at %s\n", timestr);
fflush(XG(remote_log_file));
xdfree(timestr);
} else {
} else if (strlen(XG(remote_log))) {
php_log_err(xdebug_sprintf("XDebug could not open the remote debug file '%s'.", XG(remote_log)) TSRMLS_CC);
}
}
@@ -1279,6 +1279,19 @@ DBGP_FUNC(typemap_get)
}
}

static int add_constant_node(xdebug_xml_node *node, char *name, int name_lenth, zval *const_val, xdebug_var_export_options *options TSRMLS_DC)
{
xdebug_xml_node *contents;

contents = xdebug_get_zval_value_xml_node_ex(name, const_val, XDEBUG_VAR_TYPE_CONSTANT, options TSRMLS_CC);
if (contents) {
xdebug_xml_add_attribute(contents, "facet", "constant");
xdebug_xml_add_child(node, contents);
return SUCCESS;
}
return FAILURE;
}

static int add_variable_node(xdebug_xml_node *node, char *name, int name_length, int var_only, int non_null, int no_eval, xdebug_var_export_options *options TSRMLS_DC)
{
xdebug_xml_node *contents;
@@ -1333,8 +1346,12 @@ DBGP_FUNC(property_get)
} else {
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID);
}
} else { /* superglobals */
} else if (context_nr == 1) { /* superglobals */
XG(active_symbol_table) = &EG(symbol_table);
} else if (context_nr == 2) { /* constants */
/* Do nothing */
} else {
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_INVALID_ARGS);
}

if (CMD_OPTION('p')) {
@@ -1348,9 +1365,22 @@ DBGP_FUNC(property_get)
if (CMD_OPTION('m')) {
options->max_data= strtol(CMD_OPTION('m'), NULL, 10);
}
if (add_variable_node(*retval, CMD_OPTION('n'), strlen(CMD_OPTION('n')) + 1, 1, 0, 0, options TSRMLS_CC) == FAILURE) {
options->max_data = old_max_data;
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
if (context_nr == 2) { /* constants */
zval const_val;

if (!zend_get_constant(CMD_OPTION('n'), strlen(CMD_OPTION('n')), &const_val TSRMLS_CC)) {
options->max_data = old_max_data;
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
}
if (add_constant_node(*retval, CMD_OPTION('n'), strlen(CMD_OPTION('n')) + 1, &const_val, options TSRMLS_CC) == FAILURE) {
options->max_data = old_max_data;
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
}
} else {
if (add_variable_node(*retval, CMD_OPTION('n'), strlen(CMD_OPTION('n')) + 1, 1, 0, 0, options TSRMLS_CC) == FAILURE) {
options->max_data = old_max_data;
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
}
}
XG(active_op_array) = NULL;
}
@@ -1599,8 +1629,8 @@ static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options
function_stack_entry *fse;
char *var_name;

/* right now, we only have zero or one, one being globals, which is
* always the head of the stack */
/* right now, we only have zero, one, or two with one being globals, which
* is always the head of the stack */
if (context_id == 1) {
/* add super globals */
XG(active_symbol_table) = &EG(symbol_table);
@@ -1618,6 +1648,31 @@ static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options
return 0;
}

/* add user defined constants */
if (context_id == 2) {
HashPosition pos;
zend_constant *val;

zend_hash_internal_pointer_reset_ex(EG(zend_constants), &pos);
while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &val, &pos) != FAILURE) {
if (!val->name) {
/* skip special constants */
goto next_constant;
}

if (val->module_number != PHP_USER_CONSTANT) {
/* we're only interested in user defined constants */
goto next_constant;
}

add_constant_node(node, val->name, val->name_len, &(val->value), options TSRMLS_CC);
next_constant:
zend_hash_move_forward_ex(EG(zend_constants), &pos);
}

return 0;
}

/* Here the context_id is 0 */
if ((fse = xdebug_get_stack_frame(depth TSRMLS_CC))) {
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
@@ -1723,10 +1778,16 @@ DBGP_FUNC(context_names)
xdebug_xml_add_attribute(child, "name", "Locals");
xdebug_xml_add_attribute(child, "id", "0");
xdebug_xml_add_child(*retval, child);

child = xdebug_xml_node_init("context");
xdebug_xml_add_attribute(child, "name", "Superglobals");
xdebug_xml_add_attribute(child, "id", "1");
xdebug_xml_add_child(*retval, child);

child = xdebug_xml_node_init("context");
xdebug_xml_add_attribute(child, "name", "User defined constants");
xdebug_xml_add_attribute(child, "id", "2");
xdebug_xml_add_child(*retval, child);
}

DBGP_FUNC(context_get)
@@ -1795,10 +1795,16 @@ xdebug_xml_node* xdebug_get_zval_value_xml_node_ex(char *name, zval *val, int va
full_name = xdstrdup(tmp_name);
xdfree(tmp_name);
} break;

case XDEBUG_VAR_TYPE_STATIC:
short_name = xdebug_sprintf("::%s", name);
full_name = xdebug_sprintf("::%s", name);
break;

case XDEBUG_VAR_TYPE_CONSTANT:
short_name = xdstrdup(name);
full_name = xdstrdup(name);
break;
}

xdebug_xml_add_attribute_ex(node, "name", short_name, 0, 1);
@@ -47,6 +47,7 @@ typedef struct xdebug_var_export_options {

#define XDEBUG_VAR_TYPE_NORMAL 0x00
#define XDEBUG_VAR_TYPE_STATIC 0x01
#define XDEBUG_VAR_TYPE_CONSTANT 0x02

zval* xdebug_get_php_symbol(char* name, int name_length TSRMLS_DC);
char* xdebug_get_property_info(char *mangled_property, int mangled_len, char **property_name, char **class_name);

0 comments on commit 6ff33fc

Please sign in to comment.