mirror of
https://github.com/php/php-src.git
synced 2026-03-30 20:22:36 +02:00
Added support for command line arg passing
"phpdbg -- arg" in shell "run arg" in phpdbg prompt
This commit is contained in:
16
phpdbg.c
16
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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user