Skip to content

Commit 749ecb9

Browse files
committed
Merged pull request xdebug#1046
* pr/1046: Fixed issue #2381: Step debugger crashes when `eval` command statement throws fatal error
2 parents c931537 + 05376a4 commit 749ecb9

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

src/debugger/debugger.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ int xdebug_do_eval(char *eval_string, zval *ret_zval, zend_string **return_messa
166166
/* Do evaluation */
167167
zend_first_try {
168168
res = (zend_eval_string(eval_string, ret_zval, (char*) "xdebug://debug-eval") == SUCCESS);
169+
} zend_catch {
170+
res = 0;
169171
} zend_end_try();
170172

171173
if (EG(exception)) {

src/debugger/handler_dbgp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ DBGP_FUNC(eval)
11291129
size_t new_length = 0;
11301130
int res;
11311131
xdebug_var_export_options *options;
1132-
zend_string *return_message;
1132+
zend_string *return_message = NULL;
11331133

11341134
if (!CMD_OPTION_SET('-')) {
11351135
RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS);

tests/debugger/bug02381.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
class T {
4+
function __construct() {
5+
$this->a = [new stdClass()];
6+
7+
// Put a breakpoint on the echo and open the evaluator and type in the expression:
8+
// $this->a[0]::class
9+
echo $this->a[0]::class;
10+
}
11+
}
12+
13+
new T;
14+
?>

tests/debugger/bug02381.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
Test for bug #2381: Step debug evaluator crashes when using ::class to deference expression
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../utils.inc';
6+
check_reqs('dbgp');
7+
?>
8+
--FILE--
9+
<?php
10+
require 'dbgp/dbgpclient.php';
11+
$filename = dirname(__FILE__) . '/bug02381.inc';
12+
13+
$commands = array(
14+
'step_into',
15+
'breakpoint_set -t line -n 9',
16+
'run',
17+
'eval -- ' . base64_encode('$GLOBALS[\'IDE_EVAL_CACHE\'][\'fac1af2a-5e88-436b-87e6-8be95ef78d42\']=(isset($this,$this->a,$this->a[0]::class))?($this->a[0]::class):"IDE_EVAL_ERR"'),
18+
'context_get',
19+
'detach',
20+
);
21+
22+
dbgpRunFile( $filename, $commands );
23+
?>
24+
--EXPECTF--
25+
<?xml version="1.0" encoding="iso-8859-1"?>
26+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug02381.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
27+
28+
-> step_into -i 1
29+
<?xml version="1.0" encoding="iso-8859-1"?>
30+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="1" status="break" reason="ok"><xdebug:message filename="file://bug02381.inc" lineno="13"></xdebug:message></response>
31+
32+
-> breakpoint_set -i 2 -t line -n 9
33+
<?xml version="1.0" encoding="iso-8859-1"?>
34+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="{{PID}}0001"></response>
35+
36+
-> run -i 3
37+
<?xml version="1.0" encoding="iso-8859-1"?>
38+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file://bug02381.inc" lineno="9"></xdebug:message></response>
39+
40+
-> eval -i 4 -- JEdMT0JBTFNbJ0lERV9FVkFMX0NBQ0hFJ11bJ2ZhYzFhZjJhLTVlODgtNDM2Yi04N2U2LThiZTk1ZWY3OGQ0MiddPShpc3NldCgkdGhpcywkdGhpcy0+YSwkdGhpcy0+YVswXTo6Y2xhc3MpKT8oJHRoaXMtPmFbMF06OmNsYXNzKToiSURFX0VWQUxfRVJSIg==
41+
<?xml version="1.0" encoding="iso-8859-1"?>
42+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="4" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>
43+
44+
-> context_get -i 5
45+
<?xml version="1.0" encoding="iso-8859-1"?>
46+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="5" context="0"><property name="$this" fullname="$this" type="object" classname="T" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$this-&gt;a" facet="public" type="array" children="1" numchildren="1"></property></property></response>
47+
48+
-> detach -i 6
49+
<?xml version="1.0" encoding="iso-8859-1"?>
50+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="6" status="stopping" reason="ok"></response>

0 commit comments

Comments
 (0)