]> granicus.if.org Git - php/commitdiff
fix registered commands during init, add test
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 6 Dec 2013 20:18:44 +0000 (20:18 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 6 Dec 2013 20:18:44 +0000 (20:18 +0000)
phpdbg_prompt.c
tests/commands/0103_register.test [new file with mode: 0644]

index a77d27d83ebf53e9455b907909d706cd97218172..c44db469bc1a07076711fb1ec16944fa20856b30 100644 (file)
@@ -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(&params);
+
+                       for (param = 0; param < (input->argc-1); param++) {
+                               add_next_index_stringl(
+                                       &params,
+                                       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, &params 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(&params);
-
-                       for (param = 0; param < (input->argc-1); param++) {
-                               add_next_index_stringl(
-                                       &params,
-                                       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, &params 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 (file)
index 0000000..3884159
--- /dev/null
@@ -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