From ad2ea99c3e13c96fe322ef8cdbbdb7f58c6aeea0 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Fri, 6 Dec 2013 20:18:44 +0000 Subject: [PATCH] fix registered commands during init, add test --- phpdbg_prompt.c | 139 +++++++++++++++--------------- tests/commands/0103_register.test | 28 ++++++ 2 files changed, 99 insertions(+), 68 deletions(-) create mode 100644 tests/commands/0103_register.test diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index a77d27d83e..c44db469bc 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -67,6 +67,71 @@ const phpdbg_command_t phpdbg_prompt_commands[] = { ZEND_EXTERN_MODULE_GLOBALS(phpdbg); +static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */ +{ + phpdbg_input_t *function = input->argv[0]; + + if (zend_hash_exists( + &PHPDBG_G(registered), function->string, function->length+1)) { + + zval fname, *fretval; + zend_fcall_info fci; + + ZVAL_STRINGL(&fname, function->string, function->length, 1); + + memset(&fci, 0, sizeof(zend_fcall_info)); + + fci.size = sizeof(zend_fcall_info); + fci.function_table = &PHPDBG_G(registered); + fci.function_name = &fname; + fci.symbol_table = EG(active_symbol_table); + fci.object_ptr = NULL; + fci.retval_ptr_ptr = &fretval; + fci.no_separation = 1; + + if (input->argc > 1) { + int param; + zval params; + + array_init(¶ms); + + for (param = 0; param < (input->argc-1); param++) { + add_next_index_stringl( + ¶ms, + input->argv[param+1]->string, + input->argv[param+1]->length, 1); + + phpdbg_debug( + "created param[%d] from argv[%d]: %s", + param, param+1, input->argv[param+1]->string); + } + + zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); + } else { + fci.params = NULL; + fci.param_count = 0; + } + + phpdbg_debug( + "created %d params from %d arguments", + fci.param_count, input->argc); + + zend_call_function(&fci, NULL TSRMLS_CC); + + if (fretval) { + zend_print_zval_r( + fretval, 0 TSRMLS_CC); + phpdbg_writeln(EMPTY); + } + + zval_dtor(&fname); + + return SUCCESS; + } + + return FAILURE; +} /* }}} */ + void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) { struct stat sb; @@ -125,9 +190,12 @@ void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_ { phpdbg_input_t *input = phpdbg_read_input(cmd TSRMLS_CC); switch (phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) { - case FAILURE: - phpdbg_error( - "Unrecognized command in %s:%d: %s!", init_file, line, cmd); + case FAILURE: + if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { + if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) { + phpdbg_error("Unrecognized command in %s:%d: %s!", init_file, line, input->string); + } + } break; } phpdbg_destroy_input(&input TSRMLS_CC); @@ -1070,71 +1138,6 @@ PHPDBG_COMMAND(list) /* {{{ */ return SUCCESS; } /* }}} */ -static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */ -{ - phpdbg_input_t *function = input->argv[0]; - - if (zend_hash_exists( - &PHPDBG_G(registered), function->string, function->length+1)) { - - zval fname, *fretval; - zend_fcall_info fci; - - ZVAL_STRINGL(&fname, function->string, function->length, 1); - - memset(&fci, 0, sizeof(zend_fcall_info)); - - fci.size = sizeof(zend_fcall_info); - fci.function_table = &PHPDBG_G(registered); - fci.function_name = &fname; - fci.symbol_table = EG(active_symbol_table); - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &fretval; - fci.no_separation = 1; - - if (input->argc > 1) { - int param; - zval params; - - array_init(¶ms); - - for (param = 0; param < (input->argc-1); param++) { - add_next_index_stringl( - ¶ms, - input->argv[param+1]->string, - input->argv[param+1]->length, 1); - - phpdbg_debug( - "created param[%d] from argv[%d]: %s", - param, param+1, input->argv[param+1]->string); - } - - zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); - } else { - fci.params = NULL; - fci.param_count = 0; - } - - phpdbg_debug( - "created %d params from %d arguments", - fci.param_count, input->argc); - - zend_call_function(&fci, NULL TSRMLS_CC); - - if (fretval) { - zend_print_zval_r( - fretval, 0 TSRMLS_CC); - phpdbg_writeln(EMPTY); - } - - zval_dtor(&fname); - - return SUCCESS; - } - - return FAILURE; -} /* }}} */ - int phpdbg_interactive(TSRMLS_D) /* {{{ */ { int ret = SUCCESS; diff --git a/tests/commands/0103_register.test b/tests/commands/0103_register.test new file mode 100644 index 0000000000..38841591ca --- /dev/null +++ b/tests/commands/0103_register.test @@ -0,0 +1,28 @@ +################################################# +# name: register +# purpose: test registration functions +# expect: TEST::FORMAT +# options: -rr +################################################# +#[Registered test_function] +#array(5) { +# [0]=> +# string(1) "1" +# [1]=> +# string(1) "2" +# [2]=> +# string(1) "3" +# [3]=> +# string(1) "4" +# [4]=> +# string(1) "5" +#} +################################################# +<: +function test_function() { + var_dump(func_get_args()); +} +:> +R test_function +test_function 1 2 3 4 5 +q -- 2.40.0