Add string output escaping into zend dump (phpdbg + opcache debug) (#11337)

* Add string output escaping into zend dump (phpdbg + opcache debug)

* Use ZSTR_VAL macro instead direct string access

* Move "escaped_string" into local switch/case scope

* Add zend_string_release

* Add Z_STR_P macro instead direct string access

* Merge zend_string declaration and its assigment in one stmt
This commit is contained in:
Kirill Nesmeyanov 2023-05-29 16:45:00 +03:00 committed by GitHub
parent 99ec0c1acf
commit b495a916a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -23,6 +23,7 @@
#include "zend_func_info.h" #include "zend_func_info.h"
#include "zend_call_graph.h" #include "zend_call_graph.h"
#include "zend_dump.h" #include "zend_dump.h"
#include "ext/standard/php_string.h"
void zend_dump_ht(HashTable *ht) void zend_dump_ht(HashTable *ht)
{ {
@ -65,8 +66,12 @@ void zend_dump_const(const zval *zv)
case IS_DOUBLE: case IS_DOUBLE:
fprintf(stderr, " float(%g)", Z_DVAL_P(zv)); fprintf(stderr, " float(%g)", Z_DVAL_P(zv));
break; break;
case IS_STRING: case IS_STRING:;
fprintf(stderr, " string(\"%s\")", Z_STRVAL_P(zv)); zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2);
fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string));
zend_string_release(escaped_string);
break; break;
case IS_ARRAY: case IS_ARRAY:
fprintf(stderr, " array(...)"); fprintf(stderr, " array(...)");

View file

@ -29,7 +29,7 @@ Foo\Bar::Foo:
; (lines=5, args=1, vars=1, tmps=1) ; (lines=5, args=1, vars=1, tmps=1)
; %s:5-7 ; %s:5-7
L0005 0000 CV0($bar) = RECV 1 L0005 0000 CV0($bar) = RECV 1
L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\var_dump") L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\\var_dump")
L0006 0002 SEND_VAR_EX CV0($bar) 1 L0006 0002 SEND_VAR_EX CV0($bar) 1
L0006 0003 DO_FCALL L0006 0003 DO_FCALL
L0007 0004 RETURN null L0007 0004 RETURN null
@ -44,10 +44,10 @@ prompt> [Context %s (9 ops)]
$_main: $_main:
; (lines=9, args=0, vars=0, tmps=4) ; (lines=9, args=0, vars=0, tmps=4)
; %s:1-21 ; %s:1-21
L0018 0000 V0 = NEW 0 string("Foo\Bar") L0018 0000 V0 = NEW 0 string("Foo\\Bar")
L0018 0001 DO_FCALL L0018 0001 DO_FCALL
L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo") L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo")
L0018 0003 SEND_VAL_EX string("test") 1 L0018 0003 SEND_VAL_EX string("test \"quotes\"") 1
L0018 0004 DO_FCALL L0018 0004 DO_FCALL
L0019 0005 INIT_FCALL %d %d string("foo") L0019 0005 INIT_FCALL %d %d string("foo")
L0019 0006 SEND_VAL string("test") 1 L0019 0006 SEND_VAL string("test") 1
@ -72,6 +72,6 @@ namespace {
var_dump(strrev($baz)); var_dump(strrev($baz));
} }
(new \Foo\Bar)->Foo("test"); (new \Foo\Bar)->Foo('test "quotes"');
foo("test"); foo("test");
} }