summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cli/tests/006.phpt3
-rw-r--r--sapi/phpdbg/phpdbg.c19
-rw-r--r--sapi/phpdbg/phpdbg_btree.c55
-rw-r--r--sapi/phpdbg/phpdbg_opcode.c6
-rw-r--r--sapi/phpdbg/phpdbg_opcode.h5
-rw-r--r--sapi/phpdbg/phpdbg_parser.y5
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c24
-rw-r--r--sapi/phpdbg/tests/exceptions_001.phpt4
-rw-r--r--sapi/phpdbg/tests/exceptions_002.phpt4
-rw-r--r--sapi/phpdbg/tests/phpdbg_oplog_001.phpt6
-rw-r--r--sapi/phpdbg/tests/print_001.phpt10
-rw-r--r--sapi/phpdbg/tests/print_002.phpt8
12 files changed, 95 insertions, 54 deletions
diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt
index b86c8a3197..1170ea217a 100644
--- a/sapi/cli/tests/006.phpt
+++ b/sapi/cli/tests/006.phpt
@@ -39,7 +39,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %d.%d.%d%a ] {
}
}
- - Constants [14] {
+ - Constants [15] {
Constant [ integer PREG_PATTERN_ORDER ] { 1 }
Constant [ integer PREG_SET_ORDER ] { 2 }
Constant [ integer PREG_OFFSET_CAPTURE ] { 256 }
@@ -53,6 +53,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %d.%d.%d%a ] {
Constant [ integer PREG_RECURSION_LIMIT_ERROR ] { 3 }
Constant [ integer PREG_BAD_UTF8_ERROR ] { 4 }
Constant [ integer PREG_BAD_UTF8_OFFSET_ERROR ] { 5 }
+ Constant [ integer PREG_JIT_STACKLIMIT_ERROR ] { 6 }
Constant [ string PCRE_VERSION ] { %s }
}
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index 51e6899e4e..ca86a29fcf 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -432,7 +432,9 @@ static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *ins
ZVAL_LONG(&zero, 0);
/* ignore autogenerated return (well, not too precise with finally branches, but that's okay) */
- if (op_array->last > 1 && (end - 1)->opcode == ZEND_RETURN && ((end - 2)->opcode == ZEND_RETURN || (end - 2)->opcode == ZEND_GENERATOR_RETURN || (end - 2)->opcode == ZEND_THROW)) {
+ if (op_array->last >= 1 && (end - 1)->opcode == ZEND_RETURN
+ && ((op_array->last > 1 && ((end - 2)->opcode == ZEND_RETURN || (end - 2)->opcode == ZEND_GENERATOR_RETURN || (end - 2)->opcode == ZEND_THROW))
+ || op_array->function_name == NULL)) {
end--;
}
@@ -615,25 +617,24 @@ static PHP_FUNCTION(phpdbg_end_oplog)
zend_long insert_idx;
do {
- zend_op_array *op_array = cur->op_array;
zval zero;
ZVAL_LONG(&zero, 0);
- if (op_array->filename != last_file) {
- last_file = op_array->filename;
+ if (cur->filename != last_file) {
+ last_file = cur->filename;
file_ht = insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), last_file);
}
if (by_function) {
- if (op_array->function_name == NULL) {
+ if (cur->function_name == NULL) {
if (last_function != NULL) {
insert_ht = file_ht;
}
last_function = NULL;
- } else if (op_array->function_name != last_function || op_array->scope != last_scope) {
+ } else if (cur->function_name != last_function || cur->scope != last_scope) {
zend_string *fn_name;
- last_function = op_array->function_name;
- last_scope = op_array->scope;
+ last_function = cur->function_name;
+ last_scope = cur->scope;
if (last_scope == NULL) {
fn_name = zend_string_copy(last_function);
} else {
@@ -645,7 +646,7 @@ static PHP_FUNCTION(phpdbg_end_oplog)
}
if (by_opcode) {
- insert_idx = cur->op - op_array->opcodes;
+ insert_idx = cur->op - cur->opcodes;
} else {
insert_idx = cur->op->lineno;
}
diff --git a/sapi/phpdbg/phpdbg_btree.c b/sapi/phpdbg/phpdbg_btree.c
index 2311f05126..99ea7c0a0f 100644
--- a/sapi/phpdbg/phpdbg_btree.c
+++ b/sapi/phpdbg/phpdbg_btree.c
@@ -66,7 +66,6 @@ phpdbg_btree_result *phpdbg_btree_find(phpdbg_btree *tree, zend_ulong idx) {
phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong idx) {
phpdbg_btree_branch *branch = tree->branch;
int i = tree->depth - 1, last_superior_i = -1;
- zend_bool had_alternative_branch = 0;
if (branch == NULL) {
return NULL;
@@ -74,30 +73,33 @@ phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong id
/* find nearest watchpoint */
do {
- /* an impossible branch was found if: */
- if (!had_alternative_branch && (idx >> i) % 2 == 0 && !branch->branches[0]) {
- /* there's no lower branch than idx */
- if (last_superior_i == -1) {
- /* failure */
- return NULL;
- }
- /* reset state */
- branch = tree->branch;
- i = tree->depth - 1;
- /* follow branch according to bits in idx until the last lower branch before the impossible branch */
- do {
- CHOOSE_BRANCH((idx >> i) % 2 == 1 && branch->branches[1]);
- } while (--i > last_superior_i);
- /* use now the lower branch of which we can be sure that it contains only branches lower than idx */
- CHOOSE_BRANCH(0);
- /* and choose the highest possible branch in the branch containing only branches lower than idx */
- while (i--) {
- CHOOSE_BRANCH(branch->branches[1]);
+ if ((idx >> i) % 2 == 0) {
+ if (branch->branches[0]) {
+ CHOOSE_BRANCH(0);
+ /* an impossible branch was found if: */
+ } else {
+ /* there's no lower branch than idx */
+ if (last_superior_i == -1) {
+ /* failure */
+ return NULL;
+ }
+ /* reset state */
+ branch = tree->branch;
+ i = tree->depth - 1;
+ /* follow branch according to bits in idx until the last lower branch before the impossible branch */
+ do {
+ CHOOSE_BRANCH((idx >> i) % 2 == 1 && branch->branches[1]);
+ } while (--i > last_superior_i);
+ /* use now the lower branch of which we can be sure that it contains only branches lower than idx */
+ CHOOSE_BRANCH(0);
+ /* and choose the highest possible branch in the branch containing only branches lower than idx */
+ while (i--) {
+ CHOOSE_BRANCH(branch->branches[1]);
+ }
+ break;
}
- break;
- }
/* follow branch according to bits in idx until having found an impossible branch */
- if (had_alternative_branch || (idx >> i) % 2 == 1) {
+ } else {
if (branch->branches[1]) {
if (branch->branches[0]) {
last_superior_i = i;
@@ -105,10 +107,11 @@ phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong id
CHOOSE_BRANCH(1);
} else {
CHOOSE_BRANCH(0);
- had_alternative_branch = 1;
+ while (i--) {
+ CHOOSE_BRANCH(branch->branches[1]);
+ }
+ break;
}
- } else {
- CHOOSE_BRANCH(0);
}
} while (i--);
diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c
index 092fcb985c..d8e8ebf1ce 100644
--- a/sapi/phpdbg/phpdbg_opcode.c
+++ b/sapi/phpdbg/phpdbg_opcode.c
@@ -202,8 +202,12 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_fl
if (PHPDBG_G(oplog_list)) {
phpdbg_oplog_entry *cur = zend_arena_alloc(&PHPDBG_G(oplog_arena), sizeof(phpdbg_oplog_entry));
+ zend_op_array *op_array = &execute_data->func->op_array;
cur->op = (zend_op *) execute_data->opline;
- cur->op_array = &execute_data->func->op_array;
+ cur->opcodes = op_array->opcodes;
+ cur->filename = op_array->filename;
+ cur->scope = op_array->scope;
+ cur->function_name = op_array->function_name;
cur->next = NULL;
PHPDBG_G(oplog_cur)->next = cur;
PHPDBG_G(oplog_cur) = cur;
diff --git a/sapi/phpdbg/phpdbg_opcode.h b/sapi/phpdbg/phpdbg_opcode.h
index 34c9c37e50..10d8be3f42 100644
--- a/sapi/phpdbg/phpdbg_opcode.h
+++ b/sapi/phpdbg/phpdbg_opcode.h
@@ -30,7 +30,10 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_fl
typedef struct _phpdbg_oplog_entry phpdbg_oplog_entry;
struct _phpdbg_oplog_entry {
phpdbg_oplog_entry *next;
- zend_op_array *op_array;
+ zend_string *function_name;
+ zend_class_entry *scope;
+ zend_string *filename;
+ zend_op *opcodes;
zend_op *op;
};
diff --git a/sapi/phpdbg/phpdbg_parser.y b/sapi/phpdbg/phpdbg_parser.y
index 8b3ab27f85..f25749ceed 100644
--- a/sapi/phpdbg/phpdbg_parser.y
+++ b/sapi/phpdbg/phpdbg_parser.y
@@ -23,6 +23,11 @@ static int yyerror(const char *msg);
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+#ifdef _MSC_VER
+#define YYMALLOC malloc
+#define YYFREE free
+#endif
+
%}
%pure-parser
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 89e8d027f6..e920f30cdf 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -443,14 +443,36 @@ PHPDBG_COMMAND(exec) /* {{{ */
int phpdbg_compile(void) /* {{{ */
{
zend_file_handle fh;
+ char *buf;
+ size_t len;
if (!PHPDBG_G(exec)) {
phpdbg_error("inactive", "type=\"nocontext\"", "No execution context");
return FAILURE;
}
- if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS) {
+ if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS && zend_stream_fixup(&fh, &buf, &len) == SUCCESS) {
+ /* Skip #! line */
+ if (len >= 3 && buf[0] == '#' && buf[1] == '!') {
+ char *end = buf + len;
+ do {
+ switch (fh.handle.stream.mmap.buf++[0]) {
+ case '\r':
+ if (fh.handle.stream.mmap.buf[0] == '\n') {
+ fh.handle.stream.mmap.buf++;
+ }
+ case '\n':
+ CG(start_lineno) = 2;
+ fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf;
+ end = fh.handle.stream.mmap.buf;
+ }
+ } while (fh.handle.stream.mmap.buf + 1 < end);
+ }
+
PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE);
+
+ fh.handle.stream.mmap.buf = buf;
+ fh.handle.stream.mmap.len = len;
zend_destroy_file_handle(&fh);
if (EG(exception)) {
zend_exception_error(EG(exception), E_ERROR);
diff --git a/sapi/phpdbg/tests/exceptions_001.phpt b/sapi/phpdbg/tests/exceptions_001.phpt
index fca94f512c..d5646ad40d 100644
--- a/sapi/phpdbg/tests/exceptions_001.phpt
+++ b/sapi/phpdbg/tests/exceptions_001.phpt
@@ -14,12 +14,12 @@ prompt> handle first
00017: } catch (\Exception $e) {
00018: var_dump($e);
prompt> frame #0: {closure}() at %s:16
-frame #1: {main} at %s:18
+frame #1: {main} at %s:20
prompt> 3
prompt> Uncaught Error in %s on line 16
Error: Call to undefined function foo() in %s:16
Stack trace:
-#0 %s(18): {closure}()
+#0 %s(20): {closure}()
#1 {main}
[Script ended normally]
prompt>
diff --git a/sapi/phpdbg/tests/exceptions_002.phpt b/sapi/phpdbg/tests/exceptions_002.phpt
index 9d3d805a5f..6c11c58db6 100644
--- a/sapi/phpdbg/tests/exceptions_002.phpt
+++ b/sapi/phpdbg/tests/exceptions_002.phpt
@@ -17,13 +17,13 @@ prompt>
Fatal error: Uncaught Error: Call to undefined function next_error() in eval()'d code:1
Stack trace:
#0 %s(16): unknown()
-#1 %s(18): {closure}()
+#1 %s(20): {closure}()
#2 {main}
thrown in eval()'d code on line 1
prompt> Uncaught Error in %s on line 16
Error: Call to undefined function foo() in %s:16
Stack trace:
-#0 %s(18): {closure}()
+#0 %s(20): {closure}()
#1 {main}
[Script ended normally]
prompt> [The stack contains nothing !]
diff --git a/sapi/phpdbg/tests/phpdbg_oplog_001.phpt b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
index 15eeea5ebe..e4e558b9fa 100644
--- a/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
+++ b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
@@ -22,11 +22,13 @@ prompt> halloarray(2) {
int(4)
}
["A::b"]=>
- array(2) {
+ array(3) {
[4]=>
int(1)
[5]=>
- int(5)
+ int(3)
+ [8]=>
+ int(2)
}
}
[Script ended normally]
diff --git a/sapi/phpdbg/tests/print_001.phpt b/sapi/phpdbg/tests/print_001.phpt
index 5bcc08184b..1f7a5ac0b9 100644
--- a/sapi/phpdbg/tests/print_001.phpt
+++ b/sapi/phpdbg/tests/print_001.phpt
@@ -13,20 +13,20 @@ q
prompt> [User Function foo (8 ops)]
L14-16 foo() %s - %s + 8 ops
L14 #0 RECV 1 $baz
- L15 #1 INIT_FCALL%s 112 "var_dump"
- L15 #2 INIT_FCALL%s 112 "strrev"
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
L15 #3 SEND_VAR $baz 1
L15 #4 DO_%cCALL @0
L15 #5 SEND_VAR @0 1
L15 #6 DO_%cCALL
- L15 #7 RETURN null
+ L16 #7 RETURN null
prompt> [User Class: Foo\Bar (2 methods)]
L5-7 Foo\Bar::Foo() %s - %s + 5 ops
L5 #0 RECV 1 $bar
L6 #1 INIT_NS_FCALL_BY_NAME "Foo\\var_dump"
L6 #2 SEND_VAR_EX $bar 1
L6 #3 DO_FCALL
- L6 #4 RETURN null
+ L7 #4 RETURN null
L9-9 Foo\Bar::baz() %s - %s + 1 ops
L9 #0 RETURN null
prompt> [Not Executing!]
@@ -39,7 +39,7 @@ L1-19 {main}() %s - %s + 11 ops
L18 #4 INIT_METHOD_CALL @1 "Foo"
L18 #5 SEND_VAL_EX "test" 1
L18 #6 DO_FCALL
- L19 #7 INIT_FCALL%s 144 "foo"
+ L19 #7 INIT_FCALL%s %d %s "foo"
L19 #8 SEND_VAL "test" 1
L19 #9 DO_FCALL
L19 #10 RETURN 1
diff --git a/sapi/phpdbg/tests/print_002.phpt b/sapi/phpdbg/tests/print_002.phpt
index 8225c4e0a5..3a824986c1 100644
--- a/sapi/phpdbg/tests/print_002.phpt
+++ b/sapi/phpdbg/tests/print_002.phpt
@@ -19,14 +19,14 @@ prompt> string(4) "test"
prompt> [Stack in foo() (8 ops)]
L14-16 foo() %s - %s + 8 ops
L14 #0 RECV 1 $baz
- L15 #1 INIT_FCALL%s 112 "var_dump"
- L15 #2 INIT_FCALL%s 112 "strrev"
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
L15 #3 SEND_VAR $baz 1
L15 #4 DO_%cCALL @0
L15 #5 SEND_VAR @0 1
L15 #6 DO_%cCALL
- L15 #7 RETURN null
-prompt> [L15 %s INIT_FCALL%s 112 "var_dump" %s]
+ L16 #7 RETURN null
+prompt> [L15 %s INIT_FCALL%s %d %s "var_dump" %s]
prompt>
--FILE--
<?php