Skip to content

Commit e629434

Browse files
committed
Merged pull request xdebug#1016
2 parents c79284b + f2e411a commit e629434

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

src/debugger/debugger.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,39 @@ static void resolve_breakpoints_for_function(xdebug_lines_list *lines_list, zend
862862
add_function_to_lines_list(lines_list, opa);
863863
}
864864

865+
#if PHP_VERSION_ID >= 80400
866+
static void resolve_breakpoints_for_property_hooks(xdebug_lines_list *file_function_lines_list, zend_class_entry *ce, zend_string *filename)
867+
{
868+
int i;
869+
zend_property_info *prop_info;
870+
871+
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop_info) {
872+
if (!prop_info->hooks) {
873+
continue;
874+
}
875+
876+
for (i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
877+
if (!prop_info->hooks[i]) {
878+
continue;
879+
}
880+
881+
if (!ZEND_USER_CODE((&prop_info->hooks[i]->op_array)->type)) {
882+
continue;
883+
}
884+
/* Only resolve if the file names are the same. This is needed in case
885+
* of inheritance or traits where op arrays from other files might get introduced */
886+
if (ZSTR_LEN(filename) != ZSTR_LEN((&prop_info->hooks[i]->op_array)->filename)) {
887+
continue;
888+
}
889+
if (strcmp(ZSTR_VAL(filename), ZSTR_VAL((&prop_info->hooks[i]->op_array)->filename)) != 0) {
890+
continue;
891+
}
892+
resolve_breakpoints_for_function(file_function_lines_list, &prop_info->hooks[i]->op_array);
893+
}
894+
} ZEND_HASH_FOREACH_END();
895+
}
896+
#endif
897+
865898
static void resolve_breakpoints_for_class(xdebug_lines_list *file_function_lines_list, zend_class_entry *ce, zend_string *filename)
866899
{
867900
zend_op_array *function_op_array;
@@ -880,6 +913,10 @@ static void resolve_breakpoints_for_class(xdebug_lines_list *file_function_lines
880913
}
881914
resolve_breakpoints_for_function(file_function_lines_list, function_op_array);
882915
} ZEND_HASH_FOREACH_END();
916+
917+
#if PHP_VERSION_ID >= 80400
918+
resolve_breakpoints_for_property_hooks(file_function_lines_list, ce, filename);
919+
#endif
883920
}
884921

885922
void xdebug_debugger_compile_file(zend_op_array *op_array)

tests/debugger/bug02348.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
$example = new class {
3+
public function __construct() {}
4+
5+
public DateTimeImmutable $datetime {
6+
get {
7+
return new DateTimeImmutable();
8+
}
9+
set (mixed $void) {}
10+
}
11+
};
12+
13+
echo $example->datetime->format("c");

tests/debugger/bug02348.phpt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
--TEST--
2+
Test for bug #2348: Breakpoints in property hooks are not resolved
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../utils.inc';
6+
check_reqs('PHP >= 8.4; dbgp');
7+
?>
8+
--FILE--
9+
<?php
10+
require 'dbgp/dbgpclient.php';
11+
$filename = dirname(__FILE__) . '/bug02348.inc';
12+
13+
$commands = array(
14+
'feature_set -n resolved_breakpoints -v 1',
15+
"breakpoint_set -t line -f file://{$filename} -n 7",
16+
'run',
17+
'detach',
18+
);
19+
20+
$xdebugLogFileName = sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'remote-log-2343.txt';
21+
@unlink( $xdebugLogFileName );
22+
23+
dbgpRunFile( $filename, $commands, [ 'xdebug.log' => $xdebugLogFileName, 'xdebug.log_level' => 10 ] );
24+
25+
echo file_get_contents( $xdebugLogFileName );
26+
@unlink( $xdebugLogFileName );
27+
?>
28+
--EXPECTF--
29+
<?xml version="1.0" encoding="iso-8859-1"?>
30+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug02348.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>
31+
32+
-> feature_set -i 1 -n resolved_breakpoints -v 1
33+
<?xml version="1.0" encoding="iso-8859-1"?>
34+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>
35+
36+
-> breakpoint_set -i 2 -t line -f file://bug02348.inc -n 7
37+
<?xml version="1.0" encoding="iso-8859-1"?>
38+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="{{PID}}0001" resolved="resolved"></response>
39+
40+
-> run -i 3
41+
<?xml version="1.0" encoding="iso-8859-1"?>
42+
<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://bug02348.inc" lineno="7"></xdebug:message></response>
43+
44+
-> detach -i 4
45+
<?xml version="1.0" encoding="iso-8859-1"?>
46+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="4" status="stopping" reason="ok"></response>
47+
48+
[%d] Log opened at %s
49+
[%d] [Step Debug] INFO: Connecting to configured address/port: 127.0.0.1:%d.
50+
[%d] [Step Debug] INFO: Connected to debugging client: 127.0.0.1:%d (through xdebug.client_host/xdebug.client_port).
51+
[%d] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="%sbug02348.inc" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%d"><engine version="%s"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[%s]]></copyright></init>
52+
53+
[%d] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
54+
[%d] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>
55+
56+
[%d] [Step Debug] <- breakpoint_set -i 2 -t line -f %sbug02348.inc -n 7
57+
[%d] [Step Debug] DEBUG: R: Line number (7) out of range (3-3).
58+
[%d] [Step Debug] DEBUG: R: Line number (7) out of range (9-9).
59+
[%d] [Step Debug] DEBUG: R: Line number (7) in smallest range of range (6-8).
60+
[%d] [Step Debug] DEBUG: F: Breakpoint line (7) found in set of executable lines.
61+
[%d] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="%d" resolved="resolved"></response>
62+
63+
[%d] [Step Debug] <- run -i 3
64+
[%d] [Step Debug] DEBUG: Setting 'has_line_breakpoints on {main} (%sbug02348.inc:0)
65+
[%d] [Step Debug] DEBUG: Checking whether to break on %sbug02348.inc:7.
66+
[%d] [Step Debug] DEBUG: I: Current location: %sbug02348.inc:2.
67+
[%d] [Step Debug] DEBUG: I: Matching breakpoint '%sbug02348.inc:7' against location '%sbug02348.inc:2'.
68+
[%d] [Step Debug] DEBUG: R: Line number (2) doesn't match with breakpoint (7).
69+
[%d] [Step Debug] DEBUG: Checking whether to break on %sbug02348.inc:7.
70+
[%d] [Step Debug] DEBUG: I: Current location: %sbug02348.inc:13.
71+
[%d] [Step Debug] DEBUG: I: Matching breakpoint '%sbug02348.inc:7' against location '%sbug02348.inc:13'.
72+
[%d] [Step Debug] DEBUG: R: Line number (13) doesn't match with breakpoint (7).
73+
[%d] [Step Debug] DEBUG: Setting 'has_line_breakpoints on $datetime::get (%sbug02348.inc:13)
74+
[%d] [Step Debug] DEBUG: Checking whether to break on %sbug02348.inc:7.
75+
[%d] [Step Debug] DEBUG: I: Current location: %sbug02348.inc:7.
76+
[%d] [Step Debug] DEBUG: I: Matching breakpoint '%sbug02348.inc:7' against location '%sbug02348.inc:7'.
77+
[%d] [Step Debug] DEBUG: F: File names match (%sbug02348.inc).
78+
[%d] [Step Debug] -> <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="%sbug02348.inc" lineno="7"></xdebug:message></response>
79+
80+
[%d] [Step Debug] <- detach -i 4
81+
[%d] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="4" status="stopping" reason="ok"></response>
82+
83+
[%d] Log closed at %s

0 commit comments

Comments
 (0)