From 3f10eddd1d069acf30425bcd0ded0c7cd1addab4 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 13 Jul 2015 14:11:39 +0200 Subject: Fix weird asm instruction order with gcc by marking as volatile in phpdbg --- sapi/phpdbg/phpdbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 31dab3f274..85a085b26e 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1169,7 +1169,7 @@ int main(int argc, char **argv) /* {{{ */ char *php_optarg; int php_optind, opt, show_banner = 1; long cleaning = -1; - zend_bool quit_immediately = 0; + volatile zend_bool quit_immediately = 0; /* somehow some gcc release builds will play a bit around with order in combination with setjmp..., hence volatile */ zend_bool remote = 0; zend_phpdbg_globals *settings = NULL; char *bp_tmp = NULL; -- cgit v1.2.1 From 07c425cc290ccea8cf4ae49148b8e26e9024692f Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 14 Jul 2015 01:55:32 +0200 Subject: Init variable to NULL before passing to zpp --- sapi/phpdbg/phpdbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 85a085b26e..3ee0bde97f 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -447,7 +447,7 @@ static PHP_FUNCTION(phpdbg_end_oplog) phpdbg_oplog_entry *cur = PHPDBG_G(oplog_list)->start; phpdbg_oplog_list *prev = PHPDBG_G(oplog_list)->prev; - HashTable *options; + HashTable *options = NULL; zval *option_buffer; zend_bool by_function = 0; zend_bool by_opcode = 0; -- cgit v1.2.1 From d25f3819c70888d791eb8031e5049d0791c1b040 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 15 Jul 2015 22:30:12 +0200 Subject: Fix crash on non-debug for phpdbg_end_oplog() --- sapi/phpdbg/phpdbg.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 3ee0bde97f..48ac68c7f4 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -111,6 +111,8 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */ pg->sigsafe_mem.mem = NULL; pg->sigsegv_bailout = NULL; + pg->oplog_list = NULL; + #ifdef PHP_WIN32 pg->sigio_watcher_thread = INVALID_HANDLE_VALUE; memset(&pg->swd, 0, sizeof(struct win32_sigio_watcher_data)); -- cgit v1.2.1 From 6435eb80190ebfee00b8731ae369dba6d14a15f2 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 18 Jul 2015 20:37:44 +0200 Subject: Do not display compilation success / normal script end in -rr mode --- sapi/phpdbg/phpdbg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 48ac68c7f4..3fa69cfe62 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1475,7 +1475,7 @@ phpdbg_main: /* setup remote server if necessary */ if (cleaning <= 0 && listen > 0) { server = phpdbg_open_socket(address, listen); - if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) { + if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) { exit(0); } @@ -1656,7 +1656,7 @@ phpdbg_main: /* auto compile */ if (PHPDBG_G(exec)) { - if (settings) { + if (settings || phpdbg_startup_run > 0) { PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; } @@ -1814,7 +1814,7 @@ phpdbg_out: php_request_shutdown(NULL); } zend_end_try(); - if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING) { + if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING && !quit_immediately) { phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); cleaning++; } -- cgit v1.2.1 From 699e641e93e2a697e8418b4f59d84227324631d2 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 18 Jul 2015 20:51:25 +0200 Subject: Do not show "Script ended normally" upon forced rerun --- sapi/phpdbg/phpdbg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 3fa69cfe62..ffd0fa5bd1 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1814,8 +1814,10 @@ phpdbg_out: php_request_shutdown(NULL); } zend_end_try(); - if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING && !quit_immediately) { - phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); + if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING) { + if (!quit_immediately && !phpdbg_startup_run) { + phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); + } cleaning++; } -- cgit v1.2.1 From e3cd0709dbc7aecdc9dbc2747942f76df4ca76b5 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 18 Jul 2015 23:36:37 +0200 Subject: Do never clean stdin buffer away --- sapi/phpdbg/phpdbg.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index ffd0fa5bd1..c0f5253c00 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -711,6 +711,8 @@ static int php_sapi_phpdbg_deactivate(void) /* {{{ */ pg->prompt[1] = PHPDBG_G(prompt)[1]; memcpy(pg->colors, PHPDBG_G(colors), sizeof(pg->colors)); pg->eol = PHPDBG_G(eol); + pg->input_buflen = PHPDBG_G(input_buflen); + memcpy(pg->input_buffer, PHPDBG_G(input_buffer), pg->input_buflen); pg->flags = PHPDBG_G(flags) & PHPDBG_PRESERVE_FLAGS_MASK; } -- cgit v1.2.1 From 4dc0546a59eb04f32b28f95bab2f02b849217955 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 20 Jul 2015 16:18:30 +0200 Subject: Preserve argv consistency over multiple runs --- sapi/phpdbg/phpdbg.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index c0f5253c00..db830f2d28 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1394,11 +1394,8 @@ phpdbg_main: } /* set exec if present on command line */ - if (!exec && (argc > php_optind) && (strcmp(argv[php_optind-1], "--") != SUCCESS)) { - if (strlen(argv[php_optind])) { - if (exec) { - free(exec); - } + if (argc > php_optind && (strcmp(argv[php_optind-1], "--") != SUCCESS)) { + if (!exec && strlen(argv[php_optind])) { exec = strdup(argv[php_optind]); } php_optind++; @@ -1529,6 +1526,14 @@ phpdbg_main: PHPDBG_G(sapi_name_ptr) = sapi_name; + if (exec) { /* set execution context */ + PHPDBG_G(exec) = phpdbg_resolve_path(exec); + PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0; + + free(exec); + exec = NULL; + } + php_output_activate(); php_output_deactivate(); @@ -1542,7 +1547,7 @@ phpdbg_main: for (i = SG(request_info).argc; --i;) { SG(request_info).argv[i] = estrdup(argv[php_optind - 1 + i]); } - SG(request_info).argv[i] = exec ? estrdup(exec) : estrdup(""); + SG(request_info).argv[0] = PHPDBG_G(exec) ? estrdup(PHPDBG_G(exec)) : estrdup(""); php_hash_environment(); } @@ -1603,14 +1608,6 @@ phpdbg_main: php_stream_stdio_ops.write = phpdbg_stdiop_write; #endif - if (exec) { /* set execution context */ - PHPDBG_G(exec) = phpdbg_resolve_path(exec); - PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0; - - free(exec); - exec = NULL; - } - if (oplog_file) { /* open oplog */ PHPDBG_G(oplog) = fopen(oplog_file, "w+"); if (!PHPDBG_G(oplog)) { @@ -1775,7 +1772,7 @@ phpdbg_out: { int i; /* free argv */ - for (i = SG(request_info).argc; --i;) { + for (i = SG(request_info).argc; i--;) { efree(SG(request_info).argv[i]); } efree(SG(request_info).argv); @@ -1838,6 +1835,9 @@ phpdbg_out: } if ((cleaning > 0 || remote) && !quit_immediately) { + /* reset internal php_getopt state */ + php_getopt(-1, argv, OPTIONS, NULL, &php_optind, 0, 0); + goto phpdbg_main; } -- cgit v1.2.1 From 6aadeba213305a0b8818c347bea956cb7e258c3a Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 20 Jul 2015 20:41:07 +0200 Subject: Add show_unexecuted option to phpdbg_end_oplog() --- sapi/phpdbg/phpdbg.c | 81 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 10 deletions(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index db830f2d28..3fdc7cbe30 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -443,16 +443,54 @@ static PHP_FUNCTION(phpdbg_start_oplog) PHPDBG_G(oplog_list)->start = PHPDBG_G(oplog_cur); } +static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *insert_ht, zend_bool by_opcode) { + /* ignore RECV_* opcodes */ + zend_op *cur = op_array->opcodes + op_array->num_args + !!(op_array->fn_flags & ZEND_ACC_VARIADIC); + zend_op *end = op_array->opcodes + op_array->last; + + zend_long insert_idx; + zval zero; + 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)) { + end--; + } + + for (; cur < end; cur++) { + if (cur->opcode == ZEND_NOP || cur->opcode == ZEND_OP_DATA || cur->opcode == ZEND_FE_FREE || cur->opcode == ZEND_FREE || cur->opcode == ZEND_ASSERT_CHECK + || cur->opcode == ZEND_DECLARE_CONST || cur->opcode == ZEND_DECLARE_CLASS || cur->opcode == ZEND_DECLARE_INHERITED_CLASS || cur->opcode == ZEND_DECLARE_FUNCTION + || cur->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED || cur->opcode == ZEND_VERIFY_ABSTRACT_CLASS || cur->opcode == ZEND_ADD_TRAIT || cur->opcode == ZEND_BIND_TRAITS + || cur->opcode == ZEND_DECLARE_ANON_CLASS || cur->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS || cur->opcode == ZEND_FAST_RET || cur->opcode == ZEND_TICKS + || cur->opcode == ZEND_EXT_STMT || cur->opcode == ZEND_EXT_FCALL_BEGIN || cur->opcode == ZEND_EXT_FCALL_END || cur->opcode == ZEND_EXT_NOP || cur->opcode == ZEND_BIND_GLOBAL) { + continue; + } + + if (by_opcode) { + insert_idx = cur - op_array->opcodes; + } else { + insert_idx = cur->lineno; + } + + if (cur->opcode == ZEND_NEW && (cur + 1)->opcode == ZEND_DO_FCALL) { + cur++; + } + + zend_hash_index_update(insert_ht, insert_idx, &zero); + } +} + /* {{{ proto void phpdbg_end_oplog() */ static PHP_FUNCTION(phpdbg_end_oplog) { - phpdbg_oplog_entry *cur = PHPDBG_G(oplog_list)->start; - phpdbg_oplog_list *prev = PHPDBG_G(oplog_list)->prev; + phpdbg_oplog_entry *cur; + phpdbg_oplog_list *prev; HashTable *options = NULL; zval *option_buffer; zend_bool by_function = 0; zend_bool by_opcode = 0; + zend_bool show_unexecuted = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &options) == FAILURE) { return; @@ -463,6 +501,9 @@ static PHP_FUNCTION(phpdbg_end_oplog) return; } + cur = PHPDBG_G(oplog_list)->start; + prev = PHPDBG_G(oplog_list)->prev; + efree(PHPDBG_G(oplog_list)); PHPDBG_G(oplog_list) = prev; @@ -476,6 +517,10 @@ static PHP_FUNCTION(phpdbg_end_oplog) } } + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("show_unexecuted")))) { + show_unexecuted = zend_is_true(option_buffer); + } + array_init(return_value); { @@ -490,6 +535,9 @@ static PHP_FUNCTION(phpdbg_end_oplog) 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; file_buf = zend_hash_find(Z_ARR_P(return_value), last_file); @@ -497,28 +545,41 @@ static PHP_FUNCTION(phpdbg_end_oplog) zval ht; array_init(&ht); file_buf = zend_hash_add_new(Z_ARR_P(return_value), last_file, &ht); + + if (show_unexecuted) { + phpdbg_oplog_fill_executable(op_array, Z_ARR_P(file_buf), by_opcode); + } } + insert_ht = Z_ARR_P(file_buf); } - insert_ht = Z_ARR_P(file_buf); if (by_function) { - if (op_array->function_name != last_function || op_array->scope != last_scope) { + if (op_array->function_name == NULL) { + if (last_function != NULL) { + insert_ht = Z_ARR_P(file_buf); + } + last_function = NULL; + } else if (op_array->function_name != last_function || op_array->scope != last_scope) { zend_string *fn_name; last_function = op_array->function_name; last_scope = op_array->scope; if (last_scope == NULL) { - fn_name = zend_string_copy(last_function); + fn_name = zend_string_copy(last_function ? last_function : last_file); } else { - fn_name = strpprintf(ZSTR_LEN(last_function) + ZSTR_LEN(last_scope->name) + 2, "%.*s::%.*s", ZSTR_LEN(last_function), ZSTR_VAL(last_function), ZSTR_LEN(last_scope->name), ZSTR_VAL(last_scope->name)); + fn_name = strpprintf(ZSTR_LEN(last_function) + ZSTR_LEN(last_scope->name) + 2, "%.*s::%.*s", ZSTR_LEN(last_scope->name), ZSTR_VAL(last_scope->name), ZSTR_LEN(last_function), ZSTR_VAL(last_function)); } fn_buf = zend_hash_find(Z_ARR_P(return_value), fn_name); if (!fn_buf) { zval ht; array_init(&ht); fn_buf = zend_hash_add_new(Z_ARR_P(return_value), fn_name, &ht); + + if (show_unexecuted) { + phpdbg_oplog_fill_executable(op_array, Z_ARR_P(fn_buf), by_opcode); + } } + insert_ht = Z_ARR_P(fn_buf); } - insert_ht = Z_ARR_P(fn_buf); } if (by_opcode) { @@ -530,9 +591,7 @@ static PHP_FUNCTION(phpdbg_end_oplog) { zval *num = zend_hash_index_find(insert_ht, insert_idx); if (!num) { - zval zv; - ZVAL_LONG(&zv, 0); - num = zend_hash_index_add_new(insert_ht, insert_idx, &zv); + num = zend_hash_index_add_new(insert_ht, insert_idx, &zero); } Z_LVAL_P(num)++; } @@ -1675,6 +1734,8 @@ phpdbg_main: goto phpdbg_out; } + PG(during_request_startup) = 0; + phpdbg_fully_started = 1; /* #ifndef for making compiler shutting up */ -- cgit v1.2.1 From f0b50963e5e526e81bd488d94152c81a6033dfaa Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 20 Jul 2015 21:57:00 +0200 Subject: Do not use readline when not having a tty This is important for e.g. run-tests.php --- sapi/phpdbg/phpdbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 3fdc7cbe30..d594601f29 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -564,7 +564,7 @@ static PHP_FUNCTION(phpdbg_end_oplog) last_function = op_array->function_name; last_scope = op_array->scope; if (last_scope == NULL) { - fn_name = zend_string_copy(last_function ? last_function : last_file); + fn_name = zend_string_copy(last_function); } else { fn_name = strpprintf(ZSTR_LEN(last_function) + ZSTR_LEN(last_scope->name) + 2, "%.*s::%.*s", ZSTR_LEN(last_scope->name), ZSTR_VAL(last_scope->name), ZSTR_LEN(last_function), ZSTR_VAL(last_function)); } -- cgit v1.2.1