Skip to content

Commit af4a9bf

Browse files
committed
Fix #73927: phpdbg fails with windows error prompt at "watch array"
We expect zvals, so we should request zvals. We also suppress spurious watchpoint removal notices.
1 parent 4611350 commit af4a9bf

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212

1313
- phpdbg:
1414
. Fixed bug #73926 (phpdbg will not accept input on restart execution). (cmb)
15+
. Fixed bug #73927 (phpdbg fails with windows error prompt at "watch array").
16+
(cmb)
1517
. Fixed several mostly Windows related phpdbg bugs. (cmb)
1618

1719
11 Jun 2020, PHP 7.4.7

sapi/phpdbg/phpdbg_utils.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,7 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable
473473
if (new_index && index_len == 0) {
474474
zend_ulong numkey;
475475
zend_string *strkey;
476-
ZEND_HASH_FOREACH_KEY_PTR(parent, numkey, strkey, zv) {
477-
while (Z_TYPE_P(zv) == IS_INDIRECT) {
478-
zv = Z_INDIRECT_P(zv);
479-
}
480-
476+
ZEND_HASH_FOREACH_KEY_VAL_IND(parent, numkey, strkey, zv) {
481477
if (i == len || (i == len - 1 && input[len - 1] == ']')) {
482478
char *key, *propkey;
483479
size_t namelen, keylen;

sapi/phpdbg/phpdbg_watch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,9 @@ void phpdbg_automatic_dequeue_free(phpdbg_watch_element *element) {
713713
child = child->child;
714714
}
715715
PHPDBG_G(watchpoint_hit) = 1;
716-
phpdbg_notice("watchdelete", "variable=\"%.*s\" recursive=\"%s\"", "%.*s has been removed, removing watchpoint%s", (int) ZSTR_LEN(child->str), ZSTR_VAL(child->str), (child->flags & PHPDBG_WATCH_RECURSIVE_ROOT) ? " recursively" : "");
717-
zend_hash_index_del(&PHPDBG_G(watch_elements), child->id);
716+
if (zend_hash_index_del(&PHPDBG_G(watch_elements), child->id) == SUCCESS) {
717+
phpdbg_notice("watchdelete", "variable=\"%.*s\" recursive=\"%s\"", "%.*s has been removed, removing watchpoint%s", (int) ZSTR_LEN(child->str), ZSTR_VAL(child->str), (child->flags & PHPDBG_WATCH_RECURSIVE_ROOT) ? " recursively" : "");
718+
}
718719
phpdbg_free_watch_element_tree(element);
719720
}
720721

sapi/phpdbg/tests/bug73927.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Bug #73927 (phpdbg fails with windows error prompt at "watch array")
3+
--PHPDBG--
4+
b 19
5+
r
6+
c
7+
w $value
8+
w $lower[]
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s]
12+
prompt> [Breakpoint #0 added at %s:%d]
13+
prompt> [Breakpoint #0 at %s:%d, hits: 1]
14+
>00019: if ($value < 100) {
15+
00020: $lower[] = $value;
16+
00021: } else {
17+
prompt> [Breakpoint #0 at %s:%d, hits: 2]
18+
>00019: if ($value < 100) {
19+
00020: $lower[] = $value;
20+
00021: } else {
21+
prompt> [Added watchpoint #0 for $value]
22+
prompt> [Added watchpoint #1 for $lower[0]]
23+
prompt> [$lower[0] has been removed, removing watchpoint]
24+
[$value has been removed, removing watchpoint]
25+
--FILE--
26+
<?php
27+
28+
// Generate some mock data
29+
$example = [1, 23, 23423, 256436, 3463, 4363, 457];
30+
foreach (range(1, 1000) as $val) {
31+
$example[] = mt_rand(1, 10000);
32+
}
33+
34+
// Stuff to debug
35+
function doCoolStuff($value)
36+
{
37+
$value++;
38+
39+
return mt_rand(1, 1000);
40+
}
41+
42+
$lower = [];
43+
foreach ($example as $key => $value) {
44+
if ($value < 100) {
45+
$lower[] = $value;
46+
} else {
47+
doCoolStuff($value);
48+
}
49+
}
50+
51+
?>

0 commit comments

Comments
 (0)