From 001ecd3198a19aa52513c78468ffbd6e767e1ac1 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 6 Jul 2015 17:56:48 +0300 Subject: Simplify TMP var number decoding (without HashTable) --- sapi/phpdbg/phpdbg_prompt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index db44a2ef32..540706eae1 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1418,9 +1418,6 @@ void phpdbg_clean(zend_bool full) /* {{{ */ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ { zend_bool original_in_execution = PHPDBG_G(in_execution); - HashTable vars; - - zend_hash_init(&vars, execute_data->func->op_array.last, NULL, NULL, 0); if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) && !(PHPDBG_G(flags) & PHPDBG_IS_RUNNING)) { zend_bailout(); @@ -1531,7 +1528,7 @@ ex_is_caught: } /* not while in conditionals */ - phpdbg_print_opline_ex(execute_data, &vars, 0); + phpdbg_print_opline_ex(execute_data, 0); if (PHPDBG_G(flags) & PHPDBG_IS_STEPPING && (PHPDBG_G(flags) & PHPDBG_STEP_OPCODE || execute_data->opline->lineno != PHPDBG_G(last_line))) { PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING; @@ -1581,7 +1578,6 @@ next: if (PHPDBG_G(vmret) != 0) { if (PHPDBG_G(vmret) < 0) { - zend_hash_destroy(&vars); PHPDBG_G(in_execution) = original_in_execution; return; } else { -- cgit v1.2.1 From c13124cc0f489f0fd8f1b3f3f7cab0f3331b2059 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Thu, 16 Jul 2015 10:28:59 +0200 Subject: Cleanup exception displaying code in phpdbg --- sapi/phpdbg/phpdbg_prompt.c | 52 ++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 540706eae1..a553255b4a 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -25,6 +25,7 @@ #include "zend_exceptions.h" #include "zend_vm.h" #include "zend_generators.h" +#include "zend_interfaces.h" #include "phpdbg.h" #include "phpdbg_help.h" @@ -585,41 +586,31 @@ PHPDBG_COMMAND(frame) /* {{{ */ static inline void phpdbg_handle_exception(void) /* {{{ */ { - zend_fcall_info fci; - zval trace; zend_object *ex = EG(exception); - - /* get filename and linenumber before unsetting exception */ - /* not really useful??? see blow - const char *filename = zend_get_executed_filename(); - uint32_t lineno = zend_get_executed_lineno(); - */ + zend_string *msg, *file; + zend_long line; + zval zv, rv, tmp; EG(exception) = NULL; - /* call __toString */ - ZVAL_STRINGL(&fci.function_name, "__tostring", sizeof("__tostring") - 1); - fci.size = sizeof(fci); - fci.function_table = &ex->ce->function_table; - fci.symbol_table = NULL; - fci.object = ex; - fci.retval = &trace; - fci.param_count = 0; - fci.params = NULL; - fci.no_separation = 1; - if (zend_call_function(&fci, NULL) == SUCCESS) { - phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", ZSTR_VAL(ex->ce->name), Z_STRLEN(trace), Z_STRVAL(trace)); - - zval_ptr_dtor(&trace); + ZVAL_OBJ(&zv, ex); + zend_call_method_with_0_params(&zv, ex->ce, NULL, "__tostring", &tmp); + file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv)); + line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); + + if (EG(exception)) { + EG(exception) = NULL; + msg = ZSTR_EMPTY_ALLOC(); } else { - phpdbg_error("exception", "name=\"%s\"", "Uncaught %s!", ZSTR_VAL(ex->ce->name)); + zend_update_property_string(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), Z_STRVAL(tmp)); + zval_ptr_dtor(&tmp); + msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), 1, &rv)); } - /* output useful information about address */ -/* not really useful ??? - phpdbg_writeln("exception", "opline=\"%p\" file=\"%s\" line=\"%u\"", "Stack entered at %p in %s on line %u", PHPDBG_G(ops)->opcodes, filename, lineno); */ + phpdbg_writeln("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught %s in %s on line %lld\n%s", ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line, ZSTR_VAL(msg)); + zend_string_release(msg); + zend_string_release(file); - zval_dtor(&fci.function_name); if (EG(prev_exception)) { OBJ_RELEASE(EG(prev_exception)); EG(prev_exception) = 0; @@ -1443,7 +1434,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ if (exception && PHPDBG_G(handled_exception) != exception) { zend_execute_data *prev_ex = execute_data; zval zv, rv; - zend_string *file; + zend_string *file, *msg; zend_long line; do { @@ -1463,9 +1454,12 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ ZVAL_OBJ(&zv, exception); file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv)); line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); + msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("message"), 1, &rv)); - phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught exception %s in %s on line %lld", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line); + phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught %s in %s on line %lld: %.*s", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, ZSTR_LEN(msg) < 80 ? ZSTR_LEN(msg) : 80, ZSTR_VAL(msg)); + zend_string_release(msg); zend_string_release(file); + DO_INTERACTIVE(1); } ex_is_caught: -- cgit v1.2.1 From 75a3de0cd8b79e2f813eaa663d90bb57edc7a146 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 20 Jul 2015 17:52:57 +0200 Subject: Fix misbehaviors with uncaught exceptions and finally or eval --- sapi/phpdbg/phpdbg_prompt.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index a553255b4a..b00952c07b 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -659,6 +659,7 @@ PHPDBG_COMMAND(run) /* {{{ */ char **argv = emalloc(5 * sizeof(char *)); int argc = 0; int i; + /* TODO allow proper escaping with \, "" and '' here */ char *argv_str = strtok(param->str, " "); while (argv_str) { @@ -767,15 +768,19 @@ PHPDBG_COMMAND(ev) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IN_EVAL; zend_try { if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code") == SUCCESS) { - phpdbg_xml(""); - if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { - zval *zvp = &retval; - phpdbg_xml_var_dump(zvp); + if (EG(exception)) { + zend_exception_error(EG(exception), E_ERROR); + } else { + phpdbg_xml(""); + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + zval *zvp = &retval; + phpdbg_xml_var_dump(zvp); + } + zend_print_zval_r(&retval, 0); + phpdbg_xml(""); + phpdbg_out("\n"); + zval_ptr_dtor(&retval); } - zend_print_zval_r(&retval, 0); - phpdbg_xml(""); - phpdbg_out("\n"); - zval_ptr_dtor(&retval); } } zend_catch { EG(current_execute_data) = original_execute_data; @@ -784,6 +789,7 @@ PHPDBG_COMMAND(ev) /* {{{ */ EG(vm_stack_end) = original_stack->end; EG(vm_stack) = original_stack; } zend_end_try(); + PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL; /* switch stepping back on */ @@ -1391,18 +1397,17 @@ void phpdbg_clean(zend_bool full) /* {{{ */ \ switch (phpdbg_interactive(allow_async_unsafe)) { \ zval zv; \ - default: \ + case PHPDBG_LEAVE: \ + case PHPDBG_FINISH: \ + case PHPDBG_UNTIL: \ + case PHPDBG_NEXT: \ if (exception) { \ Z_OBJ(zv) = exception; \ zend_throw_exception_internal(&zv); \ } \ /* fallthrough */ \ - case PHPDBG_LEAVE: \ - case PHPDBG_FINISH: \ - case PHPDBG_UNTIL: \ - case PHPDBG_NEXT:{ \ + default: \ goto next; \ - } \ } \ } while (0) @@ -1431,7 +1436,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ #endif /* check for uncaught exceptions */ - if (exception && PHPDBG_G(handled_exception) != exception) { + if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { zend_execute_data *prev_ex = execute_data; zval zv, rv; zend_string *file, *msg; @@ -1464,16 +1469,14 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ } ex_is_caught: - /* allow conditional breakpoints and - initialization to access the vm uninterrupted */ - if ((PHPDBG_G(flags) & PHPDBG_IN_COND_BP) || - (PHPDBG_G(flags) & PHPDBG_IS_INITIALIZING)) { + /* allow conditional breakpoints and initialization to access the vm uninterrupted */ + if (PHPDBG_G(flags) & (PHPDBG_IN_COND_BP | PHPDBG_IS_INITIALIZING)) { /* skip possible breakpoints */ goto next; } /* perform seek operation */ - if (PHPDBG_G(flags) & PHPDBG_SEEK_MASK) { + if ((PHPDBG_G(flags) & PHPDBG_SEEK_MASK) && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { /* current address */ zend_ulong address = (zend_ulong) execute_data->opline; -- cgit v1.2.1 From b7e8f659728ffd6434d4d2ce692c9a4f5fe054a1 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Thu, 23 Jul 2015 14:23:24 +0200 Subject: Fix printf format issues on 32 bit --- sapi/phpdbg/phpdbg_prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index b00952c07b..5ad3fea79d 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -607,7 +607,7 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), 1, &rv)); } - phpdbg_writeln("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught %s in %s on line %lld\n%s", ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line, ZSTR_VAL(msg)); + phpdbg_writeln("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT "\n%s", ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line, ZSTR_VAL(msg)); zend_string_release(msg); zend_string_release(file); @@ -1461,7 +1461,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("message"), 1, &rv)); - phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught %s in %s on line %lld: %.*s", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, ZSTR_LEN(msg) < 80 ? ZSTR_LEN(msg) : 80, ZSTR_VAL(msg)); + phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT ": %.*s", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, ZSTR_LEN(msg) < 80 ? ZSTR_LEN(msg) : 80, ZSTR_VAL(msg)); zend_string_release(msg); zend_string_release(file); -- cgit v1.2.1 From 13525328ede9db6f8235b4e7f91f7bce80235880 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 24 Jul 2015 17:17:09 +0200 Subject: Cleanup shutdown, enable proper memory leak displaying phpdbg should not memory leak... --- sapi/phpdbg/phpdbg_prompt.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 5ad3fea79d..5b5ac2a075 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -418,12 +418,13 @@ PHPDBG_COMMAND(exec) /* {{{ */ VCWD_CHDIR_FILE(res); *SG(request_info).argv = PHPDBG_G(exec); - php_hash_environment(); + php_build_argv(NULL, &PG(http_globals)[TRACK_VARS_SERVER]); phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec)); if (PHPDBG_G(in_execution)) { phpdbg_clean(1); + return SUCCESS; } phpdbg_compile(); @@ -678,7 +679,7 @@ PHPDBG_COMMAND(run) /* {{{ */ SG(request_info).argv = erealloc(argv, ++argc * sizeof(char *)); SG(request_info).argc = argc; - php_hash_environment(); + php_build_argv(NULL, &PG(http_globals)[TRACK_VARS_SERVER]); } zend_try { @@ -689,13 +690,11 @@ PHPDBG_COMMAND(run) /* {{{ */ } zend_catch { PHPDBG_G(in_execution) = 0; - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - zend_bailout(); - } - if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { phpdbg_error("stop", "type=\"bailout\"", "Caught exit/error from VM"); restore = 0; + } else { + zend_bailout(); } } zend_end_try(); @@ -708,8 +707,9 @@ PHPDBG_COMMAND(run) /* {{{ */ if (EG(exception)) { phpdbg_handle_exception(); } - } + PHPDBG_G(in_execution) = 1; + } phpdbg_clean(1); PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; @@ -744,6 +744,7 @@ PHPDBG_COMMAND(ev) /* {{{ */ zend_execute_data *original_execute_data = EG(current_execute_data); zend_class_entry *original_scope = EG(scope); zend_vm_stack original_stack = EG(vm_stack); + zend_object *ex = NULL; PHPDBG_OUTPUT_BACKUP(); @@ -769,6 +770,7 @@ PHPDBG_COMMAND(ev) /* {{{ */ zend_try { if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code") == SUCCESS) { if (EG(exception)) { + ex = EG(exception); zend_exception_error(EG(exception), E_ERROR); } else { phpdbg_xml(""); @@ -783,6 +785,10 @@ PHPDBG_COMMAND(ev) /* {{{ */ } } } zend_catch { + PHPDBG_G(unclean_eval) = 1; + if (ex) { + OBJ_RELEASE(ex); + } EG(current_execute_data) = original_execute_data; EG(scope) = original_scope; EG(vm_stack_top) = original_stack->top; @@ -1185,14 +1191,10 @@ PHPDBG_COMMAND(register) /* {{{ */ PHPDBG_COMMAND(quit) /* {{{ */ { - /* don't allow this to loop, ever ... */ - if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { - PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; - PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); - zend_bailout(); - } + PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; + PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING; - return PHPDBG_NEXT; + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(clean) /* {{{ */ @@ -1211,8 +1213,6 @@ PHPDBG_COMMAND(clean) /* {{{ */ phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files))); - PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; - phpdbg_clean(1); phpdbg_xml(""); @@ -1291,7 +1291,7 @@ int phpdbg_interactive(zend_bool allow_async_unsafe) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; while (ret == SUCCESS || ret == FAILURE) { - if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_STOPPING) { + if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { zend_bailout(); } @@ -1370,15 +1370,14 @@ void phpdbg_clean(zend_bool full) /* {{{ */ { /* this is implicitly required */ if (PHPDBG_G(ops)) { - destroy_op_array(PHPDBG_G(ops)); - efree(PHPDBG_G(ops)); + if (destroy_op_array(PHPDBG_G(ops))) { + efree(PHPDBG_G(ops)); + } PHPDBG_G(ops) = NULL; } if (full) { PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; - - zend_bailout(); } } /* }}} */ -- cgit v1.2.1 From 9e8fec1ef70bc5ad79b9c471cf1c6a0845a25785 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Jul 2015 18:11:45 +0200 Subject: Fix leaks from bug #70138 --- sapi/phpdbg/phpdbg_prompt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 5b5ac2a075..9d40d000c2 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -691,7 +691,6 @@ PHPDBG_COMMAND(run) /* {{{ */ PHPDBG_G(in_execution) = 0; if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { - phpdbg_error("stop", "type=\"bailout\"", "Caught exit/error from VM"); restore = 0; } else { zend_bailout(); @@ -710,9 +709,10 @@ PHPDBG_COMMAND(run) /* {{{ */ PHPDBG_G(in_execution) = 1; } - phpdbg_clean(1); PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; + + phpdbg_clean(1); } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); } @@ -794,6 +794,7 @@ PHPDBG_COMMAND(ev) /* {{{ */ EG(vm_stack_top) = original_stack->top; EG(vm_stack_end) = original_stack->end; EG(vm_stack) = original_stack; + EG(exit_status) = 0; } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL; -- cgit v1.2.1 From 64f25adb6bbb6002dce837243e3915e45af385cf Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 27 Jul 2015 15:02:01 +0200 Subject: Remove -Wunused-result warnings --- sapi/phpdbg/phpdbg_prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 9d40d000c2..9253576f01 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -350,7 +350,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) / char *sys_ini; int i; - asprintf(&sys_ini, "%s/" PHPDBG_INIT_FILENAME, PHP_CONFIG_FILE_PATH); + ZEND_IGNORE_VALUE(asprintf(&sys_ini, "%s/" PHPDBG_INIT_FILENAME, PHP_CONFIG_FILE_PATH)); phpdbg_try_file_init(sys_ini, strlen(sys_ini), 0); free(sys_ini); @@ -369,7 +369,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) / scan_dir[i] = 0; } - asprintf(&init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME); + ZEND_IGNORE_VALUE(asprintf(&init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME)); phpdbg_try_file_init(init_file, strlen(init_file), 1); if (i == -1) { break; -- cgit v1.2.1 From c0e0f1414e68fd83f3254e59687da7dccbc5bf52 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 28 Jul 2015 00:10:08 +0200 Subject: Fix phpdbg stepping on CATCH with exception --- sapi/phpdbg/phpdbg_prompt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 9253576f01..89e8d027f6 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1384,7 +1384,11 @@ void phpdbg_clean(zend_bool full) /* {{{ */ /* code may behave weirdly if EG(exception) is set */ #define DO_INTERACTIVE(allow_async_unsafe) do { \ + const zend_op *backup_opline; \ if (exception) { \ + if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { \ + backup_opline = EG(current_execute_data)->opline; \ + } \ ++GC_REFCOUNT(exception); \ zend_clear_exception(); \ } \ @@ -1402,8 +1406,14 @@ void phpdbg_clean(zend_bool full) /* {{{ */ case PHPDBG_UNTIL: \ case PHPDBG_NEXT: \ if (exception) { \ - Z_OBJ(zv) = exception; \ - zend_throw_exception_internal(&zv); \ + if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) \ + && (backup_opline->opcode == ZEND_HANDLE_EXCEPTION || backup_opline->opcode == ZEND_CATCH)) { \ + EG(current_execute_data)->opline = backup_opline; \ + EG(exception) = exception; \ + } else { \ + Z_OBJ(zv) = exception; \ + zend_throw_exception_internal(&zv); \ + } \ } \ /* fallthrough */ \ default: \ -- cgit v1.2.1 From 06ef2aeca9705322c52230aba2fd633ae7aa2737 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 1 Aug 2015 21:33:23 +0200 Subject: Skip shebang line if present --- sapi/phpdbg/phpdbg_prompt.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') 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); -- cgit v1.2.1 From 34596a3dddb407fc36af7cdf9da55253210da5e1 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 3 Aug 2015 17:15:26 +0200 Subject: Fix breaking on HANDLE_EXCEPTION (opline_before_exception) --- sapi/phpdbg/phpdbg_prompt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index e920f30cdf..4d9bc00779 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1404,13 +1404,15 @@ void phpdbg_clean(zend_bool full) /* {{{ */ } } /* }}} */ -/* code may behave weirdly if EG(exception) is set */ +/* code may behave weirdly if EG(exception) is set; thus backup it */ #define DO_INTERACTIVE(allow_async_unsafe) do { \ const zend_op *backup_opline; \ + const zend_op *before_ex; \ if (exception) { \ if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { \ backup_opline = EG(current_execute_data)->opline; \ } \ + before_ex = EG(opline_before_exception); \ ++GC_REFCOUNT(exception); \ zend_clear_exception(); \ } \ @@ -1436,6 +1438,7 @@ void phpdbg_clean(zend_bool full) /* {{{ */ Z_OBJ(zv) = exception; \ zend_throw_exception_internal(&zv); \ } \ + EG(opline_before_exception) = before_ex; \ } \ /* fallthrough */ \ default: \ -- cgit v1.2.1 From d8fe645db444e54fcc8b2555c08a5021c17ca2d3 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 4 Aug 2015 00:00:10 +0200 Subject: Fix valgrind errors in phpdbg Revert "We cannot safely assume that all op array will be refcount 0 after execution" This reverts commit b6936adb58288a0606ed847802d9226cddb41e2b. This change turns out to not have been a clever idea and was causing more weirdness than it helped... --- sapi/phpdbg/phpdbg_prompt.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 4d9bc00779..e2e3250038 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -409,7 +409,7 @@ PHPDBG_COMMAND(exec) /* {{{ */ if (PHPDBG_G(ops)) { phpdbg_notice("exec", "type=\"unsetops\"", "Destroying compiled opcodes"); - phpdbg_clean(0); + zend_hash_clean(&PHPDBG_G(file_sources)); } PHPDBG_G(exec) = res; @@ -423,7 +423,7 @@ PHPDBG_COMMAND(exec) /* {{{ */ phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec)); if (PHPDBG_G(in_execution)) { - phpdbg_clean(1); + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; return SUCCESS; } @@ -651,7 +651,7 @@ PHPDBG_COMMAND(run) /* {{{ */ if (PHPDBG_G(in_execution)) { if (phpdbg_ask_user_permission("Do you really want to restart execution?") == SUCCESS) { phpdbg_startup_run++; - phpdbg_clean(1); + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; } return SUCCESS; } @@ -733,8 +733,7 @@ PHPDBG_COMMAND(run) /* {{{ */ } PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; - - phpdbg_clean(1); + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); } @@ -1236,10 +1235,9 @@ PHPDBG_COMMAND(clean) /* {{{ */ phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files))); - phpdbg_clean(1); - phpdbg_xml(""); + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; return SUCCESS; } /* }}} */ @@ -1389,21 +1387,6 @@ int phpdbg_interactive(zend_bool allow_async_unsafe) /* {{{ */ return ret; } /* }}} */ -void phpdbg_clean(zend_bool full) /* {{{ */ -{ - /* this is implicitly required */ - if (PHPDBG_G(ops)) { - if (destroy_op_array(PHPDBG_G(ops))) { - efree(PHPDBG_G(ops)); - } - PHPDBG_G(ops) = NULL; - } - - if (full) { - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; - } -} /* }}} */ - /* code may behave weirdly if EG(exception) is set; thus backup it */ #define DO_INTERACTIVE(allow_async_unsafe) do { \ const zend_op *backup_opline; \ -- cgit v1.2.1 From d0ad621906dcf2137119c85f2cfb5361c245a06f Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 4 Aug 2015 01:22:04 +0200 Subject: Fix further leaks --- sapi/phpdbg/phpdbg_prompt.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index e2e3250038..2001129ec8 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -384,6 +384,20 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) / } /* }}} */ +void phpdbg_clean(zend_bool full) /* {{{ */ +{ + /* this is implicitly required */ + if (PHPDBG_G(ops)) { + destroy_op_array(PHPDBG_G(ops)); + efree(PHPDBG_G(ops)); + PHPDBG_G(ops) = NULL; + } + + if (full) { + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; + } +} /* }}} */ + PHPDBG_COMMAND(exec) /* {{{ */ { zend_stat_t sb; @@ -409,7 +423,7 @@ PHPDBG_COMMAND(exec) /* {{{ */ if (PHPDBG_G(ops)) { phpdbg_notice("exec", "type=\"unsetops\"", "Destroying compiled opcodes"); - zend_hash_clean(&PHPDBG_G(file_sources)); + phpdbg_clean(0); } PHPDBG_G(exec) = res; @@ -423,7 +437,7 @@ PHPDBG_COMMAND(exec) /* {{{ */ phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec)); if (PHPDBG_G(in_execution)) { - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; + phpdbg_clean(1); return SUCCESS; } @@ -651,7 +665,7 @@ PHPDBG_COMMAND(run) /* {{{ */ if (PHPDBG_G(in_execution)) { if (phpdbg_ask_user_permission("Do you really want to restart execution?") == SUCCESS) { phpdbg_startup_run++; - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; + phpdbg_clean(1); } return SUCCESS; } @@ -733,7 +747,8 @@ PHPDBG_COMMAND(run) /* {{{ */ } PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; + + phpdbg_clean(1); } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); } @@ -1235,9 +1250,10 @@ PHPDBG_COMMAND(clean) /* {{{ */ phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files))); + phpdbg_clean(1); + phpdbg_xml(""); - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; return SUCCESS; } /* }}} */ -- cgit v1.2.1 From 76e3e99dd674fe98130ba110564c607b12a7772c Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 21 Aug 2015 23:36:31 +0100 Subject: Fix issues with phpdbg SIGINT handler Also fix valgrind warnings in allocator when not using mmap()ed memory --- sapi/phpdbg/phpdbg_prompt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 2001129ec8..5d5ed2822a 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1628,7 +1628,13 @@ void phpdbg_force_interruption(void) /* {{{ */ { if (data) { if (data->func) { - phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno); + if (ZEND_USER_CODE(data->func->type)) { + phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno); + } else if (data->func->internal_function.function_name) { + phpdbg_notice("hardinterrupt", "func=\"%s\"", "Current opline: in internal function %s", data->func->internal_function.function_name->val); + } else { + phpdbg_notice("hardinterrupt", "", "Current opline: executing internal code"); + } } else { phpdbg_notice("hardinterrupt", "opline=\"%p\"", "Current opline: %p (op_array information unavailable)", data->opline); } -- cgit v1.2.1 From c359ca8c3dea661cc2faa95270f59469ee8ee9d0 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Thu, 27 Aug 2015 11:34:52 +0800 Subject: Fixed printing --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 5d5ed2822a..41d221f527 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1629,7 +1629,7 @@ void phpdbg_force_interruption(void) /* {{{ */ { if (data) { if (data->func) { if (ZEND_USER_CODE(data->func->type)) { - phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno); + phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename->val, data->opline->lineno); } else if (data->func->internal_function.function_name) { phpdbg_notice("hardinterrupt", "func=\"%s\"", "Current opline: in internal function %s", data->func->internal_function.function_name->val); } else { -- cgit v1.2.1 From 8eadde40cdb1817d23c6aca01df69596877f69a3 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 19 Sep 2015 14:57:21 +0200 Subject: Fix leave and finish --- sapi/phpdbg/phpdbg_prompt.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 41d221f527..2e0f4903f8 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -565,11 +565,11 @@ PHPDBG_COMMAND(next) /* {{{ */ } /* }}} */ static void phpdbg_seek_to_end(void) /* {{{ */ { - const zend_op *opline = EG(current_execute_data)->opline; - const zend_op_array *op_array = &EG(current_execute_data)->func->op_array - 1; + const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; + const zend_op *opline = op_array->opcodes; PHPDBG_G(seek_ex) = EG(current_execute_data); - while (++opline < op_array->opcodes + op_array->last) { + do { switch (opline->opcode) { case ZEND_RETURN: case ZEND_FAST_RET: @@ -580,7 +580,7 @@ static void phpdbg_seek_to_end(void) /* {{{ */ { zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); return; } - } + } while (++opline < op_array->opcodes + op_array->last); } /* }}} */ @@ -591,8 +591,12 @@ PHPDBG_COMMAND(finish) /* {{{ */ return SUCCESS; } - PHPDBG_G(flags) |= PHPDBG_IN_FINISH; phpdbg_seek_to_end(); + if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) { + zend_hash_clean(&PHPDBG_G(seek)); + } else { + PHPDBG_G(flags) |= PHPDBG_IN_FINISH; + } return PHPDBG_FINISH; } /* }}} */ @@ -604,10 +608,15 @@ PHPDBG_COMMAND(leave) /* {{{ */ return SUCCESS; } - PHPDBG_G(flags) |= PHPDBG_IN_LEAVE; phpdbg_seek_to_end(); - - return PHPDBG_LEAVE; + if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) { + zend_hash_clean(&PHPDBG_G(seek)); + phpdbg_notice("leave", "type=\"end\"", "Already at the end of the function"); + return SUCCESS; + } else { + PHPDBG_G(flags) |= PHPDBG_IN_LEAVE; + return PHPDBG_LEAVE; + } } /* }}} */ PHPDBG_COMMAND(frame) /* {{{ */ -- cgit v1.2.1 From 491c62e2aa34dfbf8ad8d60523205ba2afba332a Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 19 Sep 2015 15:19:26 +0200 Subject: Apply same fixes for until --- sapi/phpdbg/phpdbg_prompt.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 2e0f4903f8..cacfe932aa 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -518,26 +518,23 @@ PHPDBG_COMMAND(continue) /* {{{ */ } /* }}} */ int phpdbg_skip_line_helper() /* {{{ */ { + const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; + const zend_op *opline = op_array->opcodes; + PHPDBG_G(flags) |= PHPDBG_IN_UNTIL; PHPDBG_G(seek_ex) = EG(current_execute_data); - { - const zend_op *opline = EG(current_execute_data)->opline; - const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; - - while (++opline < op_array->opcodes + op_array->last) { - if (opline->lineno != EG(current_execute_data)->opline->lineno - || opline->opcode == ZEND_RETURN - || opline->opcode == ZEND_FAST_RET - || opline->opcode == ZEND_GENERATOR_RETURN - || opline->opcode == ZEND_EXIT - || opline->opcode == ZEND_YIELD - || opline->opcode == ZEND_YIELD_FROM - ) { - zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); - break; - } + do { + if (opline->lineno != EG(current_execute_data)->opline->lineno + || opline->opcode == ZEND_RETURN + || opline->opcode == ZEND_FAST_RET + || opline->opcode == ZEND_GENERATOR_RETURN + || opline->opcode == ZEND_EXIT + || opline->opcode == ZEND_YIELD + || opline->opcode == ZEND_YIELD_FROM + ) { + zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); } - } + } while (++opline < op_array->opcodes + op_array->last); return PHPDBG_UNTIL; } @@ -578,7 +575,6 @@ static void phpdbg_seek_to_end(void) /* {{{ */ { case ZEND_YIELD: case ZEND_YIELD_FROM: zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); - return; } } while (++opline < op_array->opcodes + op_array->last); } -- cgit v1.2.1 From 4a174ca7e602fb20d12b8b665eaf3ce5d4d46bd3 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 23 Sep 2015 17:53:22 +0200 Subject: Fixed bug #70532 (respect set_exception_handler in phpdbg) --- sapi/phpdbg/phpdbg_prompt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index cacfe932aa..0314d39f24 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -744,6 +744,8 @@ PHPDBG_COMMAND(run) /* {{{ */ } if (restore) { + zend_exception_restore(); + zend_try_exception_handler(); if (EG(exception)) { phpdbg_handle_exception(); } -- cgit v1.2.1 From bccac3774bade617d88da45e7f1781151bb16160 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 23 Sep 2015 18:30:13 +0200 Subject: Fixed bug #70531 (-rr should not fallback to interactive mode in phpdbg) --- sapi/phpdbg/phpdbg_prompt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 0314d39f24..f5341075d0 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1476,6 +1476,11 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ } #endif + if (PHPDBG_G(flags) & PHPDBG_PREVENT_INTERACTIVE) { + phpdbg_print_opline_ex(execute_data, 0); + goto next; + } + /* check for uncaught exceptions */ if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { zend_execute_data *prev_ex = execute_data; -- cgit v1.2.1 From 0c03ba0ad0dfb4c5a7d3a1de19545a785be90ed6 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 2 Oct 2015 12:18:26 +0200 Subject: Fixed bug #70614 (incorrect exit code in -rr mode with Exceptions) --- sapi/phpdbg/phpdbg_prompt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index f5341075d0..c16836c872 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -649,9 +649,10 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), 1, &rv)); } - phpdbg_writeln("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT "\n%s", ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line, ZSTR_VAL(msg)); - zend_string_release(msg); + phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT, ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line); zend_string_release(file); + phpdbg_writeln("exceptionmsg", "msg=\"%s\"", ZSTR_VAL(msg)); + zend_string_release(msg); if (EG(prev_exception)) { OBJ_RELEASE(EG(prev_exception)); @@ -659,6 +660,8 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ } OBJ_RELEASE(ex); EG(opline_before_exception) = NULL; + + EG(exit_status) = 255; } /* }}} */ PHPDBG_COMMAND(run) /* {{{ */ -- cgit v1.2.1 From 4f90e2ec9d1d93652cef813789fa3aa3545e007f Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 2 Oct 2015 12:37:17 +0200 Subject: Ensure proper set_exception_handler() handling with exit() inside it --- sapi/phpdbg/phpdbg_prompt.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index c16836c872..50971b25ec 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -748,12 +748,20 @@ PHPDBG_COMMAND(run) /* {{{ */ if (restore) { zend_exception_restore(); - zend_try_exception_handler(); + zend_try { + zend_try_exception_handler(); + PHPDBG_G(in_execution) = 1; + } zend_catch { + PHPDBG_G(in_execution) = 0; + + if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { + zend_bailout(); + } + } zend_end_try(); + if (EG(exception)) { phpdbg_handle_exception(); } - - PHPDBG_G(in_execution) = 1; } PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; -- cgit v1.2.1 From 49493a2dcfb2cd1758b69b13d9006ead3be0e066 Mon Sep 17 00:00:00 2001 From: Lior Kaplan Date: Fri, 1 Jan 2016 19:19:27 +0200 Subject: Happy new year (Update copyright to 2016) --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 48fabca3f9..b63018b1ee 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From 35d5cd5c6e2d160952274b67d4c20e59f351dd0b Mon Sep 17 00:00:00 2001 From: Insu Yun Date: Tue, 12 Jan 2016 04:21:57 +0000 Subject: phpdbg: fix potential format string bug --- sapi/phpdbg/phpdbg_prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 97249765f8..796519ffdf 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -651,7 +651,7 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT, ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line); zend_string_release(file); - phpdbg_writeln("exceptionmsg", "msg=\"%s\"", ZSTR_VAL(msg)); + phpdbg_writeln("exceptionmsg", "msg=\"%s\"", "%s", ZSTR_VAL(msg)); zend_string_release(msg); if (EG(prev_exception)) { @@ -1627,7 +1627,7 @@ next: execute_data->call->func->type == ZEND_USER_FUNCTION) { zend_execute_ex = execute_ex; } - PHPDBG_G(vmret) = zend_vm_call_opcode_handler(execute_data); + PHPDBG_G(vmret) = zend_vm_call_opcode_handler(execute_data); zend_execute_ex = phpdbg_execute_ex; if (PHPDBG_G(vmret) != 0) { -- cgit v1.2.1 From c9357f82d3882eb3c7cb9f63dbc98d354fb20739 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 14 Feb 2016 14:02:19 +0100 Subject: Format string fixes Conflicts: ext/pgsql/pgsql.c --- sapi/phpdbg/phpdbg_prompt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 97249765f8..0314442daa 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1518,7 +1518,11 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("message"), 1, &rv)); - phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT ": %.*s", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, ZSTR_LEN(msg) < 80 ? ZSTR_LEN(msg) : 80, ZSTR_VAL(msg)); + phpdbg_error("exception", + "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", + "Uncaught %s in %s on line " ZEND_LONG_FMT ": %.*s", + ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, + ZSTR_LEN(msg) < 80 ? (int) ZSTR_LEN(msg) : 80, ZSTR_VAL(msg)); zend_string_release(msg); zend_string_release(file); -- cgit v1.2.1 From 055b4112188cccdc250790ab063479d2922f5fda Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 17 Feb 2016 20:26:47 +0100 Subject: Fix crash when advancing inside an internal function This just happened in the "double ctrl+c" mode, when we halted inside an internal function; there was some code assuming a proper op_array --- sapi/phpdbg/phpdbg_prompt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 0314442daa..558ca469b5 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -518,13 +518,14 @@ PHPDBG_COMMAND(continue) /* {{{ */ } /* }}} */ int phpdbg_skip_line_helper() /* {{{ */ { - const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; + zend_execute_data *ex = phpdbg_user_execute_data(EG(current_execute_data)); + const zend_op_array *op_array = &ex->func->op_array; const zend_op *opline = op_array->opcodes; PHPDBG_G(flags) |= PHPDBG_IN_UNTIL; - PHPDBG_G(seek_ex) = EG(current_execute_data); + PHPDBG_G(seek_ex) = ex; do { - if (opline->lineno != EG(current_execute_data)->opline->lineno + if (opline->lineno != ex->opline->lineno || opline->opcode == ZEND_RETURN || opline->opcode == ZEND_FAST_RET || opline->opcode == ZEND_GENERATOR_RETURN @@ -562,10 +563,11 @@ PHPDBG_COMMAND(next) /* {{{ */ } /* }}} */ static void phpdbg_seek_to_end(void) /* {{{ */ { - const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; + zend_execute_data *ex = phpdbg_user_execute_data(EG(current_execute_data)); + const zend_op_array *op_array = &ex->func->op_array; const zend_op *opline = op_array->opcodes; - PHPDBG_G(seek_ex) = EG(current_execute_data); + PHPDBG_G(seek_ex) = ex; do { switch (opline->opcode) { case ZEND_RETURN: @@ -588,7 +590,7 @@ PHPDBG_COMMAND(finish) /* {{{ */ } phpdbg_seek_to_end(); - if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) { + if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) phpdbg_user_execute_data(EG(current_execute_data))->opline)) { zend_hash_clean(&PHPDBG_G(seek)); } else { PHPDBG_G(flags) |= PHPDBG_IN_FINISH; @@ -605,7 +607,7 @@ PHPDBG_COMMAND(leave) /* {{{ */ } phpdbg_seek_to_end(); - if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) { + if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) phpdbg_user_execute_data(EG(current_execute_data))->opline)) { zend_hash_clean(&PHPDBG_G(seek)); phpdbg_notice("leave", "type=\"end\"", "Already at the end of the function"); return SUCCESS; -- cgit v1.2.1 From 908b662f7fcfbc032f70ece82c25fdc8d21de4b3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Mar 2016 16:56:39 +0300 Subject: PHP-7 zend_call_function() doesn't support symbol_table substitution --- sapi/phpdbg/phpdbg_prompt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 558ca469b5..31d3c01e46 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -121,7 +121,8 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ ZVAL_STRINGL(&fci.function_name, lc_name, name->len); fci.size = sizeof(zend_fcall_info); fci.function_table = &PHPDBG_G(registered); - fci.symbol_table = zend_rebuild_symbol_table(); + //???fci.symbol_table = zend_rebuild_symbol_table(); + fci.symbol_table = NULL; fci.object = NULL; fci.retval = &fretval; fci.no_separation = 1; -- cgit v1.2.1 From c67c166f930b2f815a805a3376e9244794e20c31 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Mar 2016 17:50:55 +0300 Subject: Removed zend_fcall_info.symbol_table --- sapi/phpdbg/phpdbg_prompt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 5b3b546466..8a4bd3a3ac 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -122,7 +122,6 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ fci.size = sizeof(zend_fcall_info); fci.function_table = &PHPDBG_G(registered); //???fci.symbol_table = zend_rebuild_symbol_table(); - fci.symbol_table = NULL; fci.object = NULL; fci.retval = &fretval; fci.no_separation = 1; -- cgit v1.2.1 From c4b188871e7abb7c6cc20d05ceda4cea082efcd2 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 16 Feb 2016 22:47:37 +0000 Subject: Fix bug #71575 removing extra semicolons outside macros --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 31d3c01e46..a01c8a399f 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -48,7 +48,7 @@ #error "phpdbg can only be built with CALL zend vm kind" #endif -ZEND_EXTERN_MODULE_GLOBALS(phpdbg); +ZEND_EXTERN_MODULE_GLOBALS(phpdbg) extern int phpdbg_startup_run; #ifdef HAVE_LIBDL -- cgit v1.2.1 From f0a2e8eb13b3971ec11baa2a6029ed7c4cb0064b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 27 Apr 2016 13:46:38 +0300 Subject: Removed "zend_fcall_info.function_table". It was assigned in many places, but is never used. --- sapi/phpdbg/phpdbg_prompt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index ac86c15629..a9fd351ffd 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -120,7 +120,6 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ ZVAL_STRINGL(&fci.function_name, lc_name, name->len); fci.size = sizeof(zend_fcall_info); - fci.function_table = &PHPDBG_G(registered); //???fci.symbol_table = zend_rebuild_symbol_table(); fci.object = NULL; fci.retval = &fretval; -- cgit v1.2.1 From 6499162ff0d8aa6e862d3e3cdd2288b87636b8a1 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 28 Apr 2016 04:13:34 +0300 Subject: - get rid of EG(scope). zend_get_executed_scope() should be used instead. - ichanged zval_update_constant_ex(). Use IS_TYPE_IMMUTABLE flag on shared constants and AST, instead of "inline_change" parameter. --- sapi/phpdbg/phpdbg_prompt.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index a9fd351ffd..787517dd9d 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -797,7 +797,6 @@ PHPDBG_COMMAND(ev) /* {{{ */ zval retval; zend_execute_data *original_execute_data = EG(current_execute_data); - zend_class_entry *original_scope = EG(scope); zend_vm_stack original_stack = EG(vm_stack); zend_object *ex = NULL; @@ -845,7 +844,6 @@ PHPDBG_COMMAND(ev) /* {{{ */ OBJ_RELEASE(ex); } EG(current_execute_data) = original_execute_data; - EG(scope) = original_scope; EG(vm_stack_top) = original_stack->top; EG(vm_stack_end) = original_stack->end; EG(vm_stack) = original_stack; -- cgit v1.2.1 From 747a482b9c011b33d3e61823d3291c2258eaec9e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 28 Apr 2016 15:17:24 +0300 Subject: Don't initialize EX(call)->symbol_table on each function call. Keep it uninitialized, and check ZEND_CALL_HAS_SYMBOL_TABLE flag when necessary. --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 787517dd9d..3b7274a997 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -687,7 +687,7 @@ PHPDBG_COMMAND(run) /* {{{ */ } /* clean up from last execution */ - if (ex && ex->symbol_table) { + if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE)) { zend_hash_clean(ex->symbol_table); } else { zend_rebuild_symbol_table(); -- cgit v1.2.1 From 2524ab9e67554f1de3c343ed7eb11eee0c92a093 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 30 May 2016 18:32:39 +0200 Subject: fix condition --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index a01c8a399f..6f73d3087a 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1048,7 +1048,7 @@ PHPDBG_API const char *phpdbg_load_module_or_extension(char **path, char **name) if (!handle) { #if PHP_WIN32 char *err = GET_DL_ERROR(); - if (err && *err != "") { + if (err && err[0]) { phpdbg_error("dl", "type=\"unknown\"", "%s", err); LocalFree(err); } else { -- cgit v1.2.1