]> granicus.if.org Git - php/commitdiff
Added support for command line arg passing
authorBob Weinand <bobwei9@hotmail.com>
Sat, 12 Apr 2014 22:27:46 +0000 (00:27 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Sat, 12 Apr 2014 22:27:46 +0000 (00:27 +0200)
"phpdbg -- arg" in shell
"run arg" in phpdbg prompt

phpdbg.c
phpdbg_help.c
phpdbg_prompt.c

index 7676687e7124fb7f225b8ddf1da8c9a3153cd3f8..ba12d94515d741db597a8d4b46a418df2d63f5b0 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -1139,8 +1139,16 @@ phpdbg_main:
        phpdbg->ini_entries = ini_entries;
                
        if (phpdbg->startup(phpdbg) == SUCCESS) {
-               php_request_startup(TSRMLS_C);
+               int i;
+               SG(request_info).argc = argc - php_optind + 1;          
+               SG(request_info).argv = emalloc(SG(request_info).argc * sizeof(char *));
+               for (i = SG(request_info).argc; --i;) {
+                       SG(request_info).argv[i] = estrdup(argv[php_optind - 1 + i]);
+               }
+               SG(request_info).argv[php_optind - 1] = exec?exec:"";
                
+               php_request_startup(TSRMLS_C);
+
                /* do not install sigint handlers for remote consoles */
                /* sending SIGINT then provides a decent way of shutting down the server */
 #ifdef ZEND_SIGNALS
@@ -1289,6 +1297,12 @@ phpdbg_out:
                }
 #endif
 
+               /* free argv */
+               for (i = SG(request_info).argc; --i;) {
+                       efree(SG(request_info).argv[i]);
+               }
+               efree(SG(request_info).argv);
+
 #ifndef ZTS
                /* force cleanup of auto and core globals */
                zend_hash_clean(CG(auto_globals));
index 3aa82848e00993178b5341dd2bdfb2124ceb11c8..dd8e53052262a4c5062a5adec374a568302f5a88 100644 (file)
@@ -379,7 +379,9 @@ phpdbg_help_text_t phpdbg_help_text[] = {
 "  **-S**      **-S**cli               Override SAPI name, careful!" CR
 "  **-l**      **-l**4000              Setup remote console ports" CR
 "  **-a**      **-a**192.168.0.3       Setup remote console bind address" CR
-"  **-V**                          Print version number" CR CR
+"  **-V**                          Print version number" CR
+"  **--**      **--** arg1 arg2        Use to delimit phpdbg arguments and php $argv; append any $argv "
+"argument after it" CR CR
 
 "**Remote Console Mode**" CR CR
 
@@ -838,11 +840,13 @@ phpdbg_help_text_t phpdbg_help_text[] = {
 
 {"run",
 "Enter the vm, startinging execution. Execution will then continue until the next breakpoint "
-"or completion of the script"
+"or completion of the script. Add parameters you want to use as $argv"
 "**Examples**" CR CR
 "    $P run" CR
 "    $P r" CR
-"    Will cause execution of the context, if it is set." CR CR
+"    Will cause execution of the context, if it is set" CR CR
+"    $P r test" CR
+"    Will execute with $argv[1] == \"test\"" CR CR
 
 "Note that the execution context must be set. If not previously compiled, then the script will "
 "be compiled before execution." CR CR
index e53a5e68b1947ac2006b65e244dca3d84736a1d8..c088535eb42a453f85d85f975171de1219837441 100644 (file)
@@ -289,6 +289,9 @@ PHPDBG_COMMAND(exec) /* {{{ */
                                                PHPDBG_G(exec) = res;
                                                PHPDBG_G(exec_len) = res_len;
 
+                                               *SG(request_info).argv = PHPDBG_G(exec);
+                                               php_hash_environment(TSRMLS_C);
+
                                                phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
                                        } else {
                                                phpdbg_notice("Execution context not changed");
@@ -579,6 +582,29 @@ PHPDBG_COMMAND(run) /* {{{ */
                /* reset hit counters */
                phpdbg_reset_breakpoints(TSRMLS_C);
 
+               if (param->type != EMPTY_PARAM) {
+                       char **argv = emalloc(5 * sizeof(char *));
+                       int argc = 0;
+                       int i;
+                       char *argv_str = strtok(input->string, " ");
+                       while (argv_str) {
+                               if (argc >= 4 && argc == (argc & -argc)) {
+                                       argv = erealloc(argv, (argc * 2 + 1) * sizeof(char *));
+                               }
+                               argv[++argc] = argv_str;
+                               argv_str = strtok(0, " ");
+                               argv[argc] = estrdup(argv[argc]);
+                       }
+                       argv[0] = SG(request_info).argv[0];
+                       for (i = SG(request_info).argc; --i;) {
+                               efree(SG(request_info).argv[i]);
+                       }
+                       efree(SG(request_info).argv);
+                       SG(request_info).argv = erealloc(argv, ++argc * sizeof(char *));
+                       SG(request_info).argc = argc;
+                       php_hash_environment(TSRMLS_C);
+               }
+
                zend_try {
                        php_output_activate(TSRMLS_C);
                        PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;