diff --git a/phpdbg.c b/phpdbg.c index d830092797e..37a938f5554 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -1119,8 +1119,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 @@ -1269,6 +1277,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)); diff --git a/phpdbg_bp.c b/phpdbg_bp.c index 111d5ca1c90..15b00c1d01a 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -361,7 +361,7 @@ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC) /* {{{ */ { phpdbg_breakline_t opline_break; - if (op_array->last < brake->opline_num) { + if (op_array->last <= brake->opline_num) { if (brake->class_name == NULL) { phpdbg_error("There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num); } else if (brake->func_name == NULL) { diff --git a/phpdbg_frame.c b/phpdbg_frame.c index de02addc1b9..a235fe8cb04 100644 --- a/phpdbg_frame.c +++ b/phpdbg_frame.c @@ -167,7 +167,7 @@ void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */ zval **tmp; zval **file, **line; HashPosition position; - int i = 1, limit = num; + int i = 0, limit = num; int user_defined; if (limit < 0) { @@ -186,7 +186,7 @@ void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */ if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == FAILURE) { - phpdbg_write("frame #0: {main} at %s:%ld", Z_STRVAL_PP(file), Z_LVAL_PP(line)); + phpdbg_write("frame #%d: {main} at %s:%ld", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); break; } diff --git a/phpdbg_help.c b/phpdbg_help.c index 941d58ce670..72038dc0fd7 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -378,7 +378,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 @@ -793,11 +795,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 diff --git a/phpdbg_opcode.c b/phpdbg_opcode.c index 50073eb22bb..6b13625fc14 100644 --- a/phpdbg_opcode.c +++ b/phpdbg_opcode.c @@ -183,6 +183,7 @@ void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ { +#if ZEND_EXTENSION_API_NO <= PHP_5_5_API_NO #define CASE(s) case s: return #s switch (opcode) { CASE(ZEND_NOP); @@ -360,4 +361,8 @@ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ default: return "UNKNOWN"; } +#else + const char *ret = zend_get_opcode_name(opcode); + return ret?ret:"UNKNOWN"; +#endif } /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 31c5d251222..3010c088a55 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -356,6 +356,7 @@ PHPDBG_COMMAND(exec) /* {{{ */ if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { +<<<<<<< HEAD if (PHPDBG_G(exec)) { phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec)); efree(PHPDBG_G(exec)); @@ -366,6 +367,17 @@ PHPDBG_COMMAND(exec) /* {{{ */ if (PHPDBG_G(ops)) { phpdbg_notice("Destroying compiled opcodes"); phpdbg_clean(0 TSRMLS_CC); +======= + *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"); + } + } else { + phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); +>>>>>>> 3db29ee43960a4e164244a55b0e2a4b23a112e49 } PHPDBG_G(exec) = res; @@ -641,6 +653,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;