From cc70ec1e6735bb60606673c72c5ce9d9cb076e29 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Oct 2014 03:50:28 +0100 Subject: Add question to reset execution in run/exec/clean --- sapi/phpdbg/phpdbg_prompt.c | 123 ++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 55 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 2e0c698f05..29c75c583c 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -43,6 +43,8 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); ZEND_EXTERN_MODULE_GLOBALS(output); +extern int phpdbg_startup_run; +extern char *phpdbg_exec; #ifdef HAVE_LIBDL #ifdef PHP_WIN32 @@ -355,6 +357,11 @@ PHPDBG_COMMAND(exec) /* {{{ */ size_t res_len = strlen(res); if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { + if (EG(in_execution)) { + if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?" TSRMLS_CC) == FAILURE) { + return FAILURE; + } + } if (PHPDBG_G(exec)) { phpdbg_notice("exec", "type=\"unset\" context=\"%s\"", "Unsetting old execution context: %s", PHPDBG_G(exec)); @@ -378,9 +385,11 @@ PHPDBG_COMMAND(exec) /* {{{ */ phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec)); - if (phpdbg_compile(TSRMLS_C) == FAILURE) { - phpdbg_error("compile", "type=\"compilefailure\" context=\"%s\"", "Failed to compile %s", PHPDBG_G(exec)); + if (EG(in_execution)) { + phpdbg_clean(1 TSRMLS_CC); } + + phpdbg_compile(TSRMLS_C); } else { phpdbg_notice("exec", "type=\"unchanged\"", "Execution context not changed"); } @@ -399,20 +408,15 @@ int phpdbg_compile(TSRMLS_D) /* {{{ */ if (!PHPDBG_G(exec)) { phpdbg_error("inactive", "type=\"nocontext\"", "No execution context"); - return SUCCESS; - } - - if (EG(in_execution)) { - phpdbg_error("inactive", "type=\"isrunning\"", "Cannot compile while in execution"); return FAILURE; } if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC) == SUCCESS) { - PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE TSRMLS_CC); zend_destroy_file_handle(&fh TSRMLS_CC); phpdbg_notice("compile", "context=\"%s\"", "Successful compilation of %s", PHPDBG_G(exec)); + return SUCCESS; } else { phpdbg_error("compile", "type=\"openfailure\" context=\"%s\"", "Could not open file %s", PHPDBG_G(exec)); @@ -570,11 +574,6 @@ static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */ PHPDBG_COMMAND(run) /* {{{ */ { - if (EG(in_execution)) { - phpdbg_error("inactive", "type=\"isrunning\"", "Cannot start another execution while one is in progress"); - return SUCCESS; - } - if (PHPDBG_G(ops) || PHPDBG_G(exec)) { zend_op **orig_opline = EG(opline_ptr); zend_op_array *orig_op_array = EG(active_op_array); @@ -582,6 +581,14 @@ PHPDBG_COMMAND(run) /* {{{ */ zend_bool restore = 1; zend_execute_data *ex = EG(current_execute_data); + if (EG(in_execution)) { + if (phpdbg_ask_user_permission("Do you really want to restart execution?" TSRMLS_CC) == SUCCESS) { + phpdbg_startup_run++; + phpdbg_clean(1 TSRMLS_CC); + } + return SUCCESS; + } + if (!PHPDBG_G(ops)) { if (phpdbg_compile(TSRMLS_C) == FAILURE) { phpdbg_error("compile", "type=\"compilefailure\" context=\"%s\"", "Failed to compile %s, cannot run", PHPDBG_G(exec)); @@ -643,7 +650,7 @@ PHPDBG_COMMAND(run) /* {{{ */ EG(opline_ptr) = orig_opline; EG(return_value_ptr_ptr) = orig_retval_ptr; - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { phpdbg_error("stop", "type=\"bailout\"", "Caught exit/error from VM"); restore = 0; } @@ -1127,7 +1134,7 @@ PHPDBG_COMMAND(register) /* {{{ */ PHPDBG_COMMAND(quit) /* {{{ */ { /* don't allow this to loop, ever ... */ - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; zend_bailout(); } @@ -1138,8 +1145,9 @@ PHPDBG_COMMAND(quit) /* {{{ */ PHPDBG_COMMAND(clean) /* {{{ */ { if (EG(in_execution)) { - phpdbg_error("inactive", "type=\"isrunning\"", "Cannot clean environment while executing"); - return SUCCESS; + if (phpdbg_ask_user_permission("Do you really want to clean your current environment?" TSRMLS_CC) == FAILURE) { + return SUCCESS; + } } phpdbg_out("Cleaning Execution Environment\n"); @@ -1227,60 +1235,64 @@ int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; - input = phpdbg_read_input(NULL TSRMLS_CC); + while (1) { + if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { + zend_bailout(); + } - if (input) { - do { - phpdbg_init_param(&stack, STACK_PARAM); + if (!(input = phpdbg_read_input(NULL TSRMLS_CC))) { + break; + } - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - phpdbg_activate_err_buf(1 TSRMLS_CC); + + phpdbg_init_param(&stack, STACK_PARAM); + + if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { + phpdbg_activate_err_buf(1 TSRMLS_CC); #ifdef PHP_WIN32 #define PARA ((phpdbg_param_t *)stack.next)->type - if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { - sigio_watcher_start(); - } + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { + sigio_watcher_start(); + } #endif - switch (ret = phpdbg_stack_execute(&stack, allow_async_unsafe TSRMLS_CC)) { - case FAILURE: - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - if (!allow_async_unsafe || phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_output_err_buf(NULL, "%b", "%b" TSRMLS_CC); - } + switch (ret = phpdbg_stack_execute(&stack, allow_async_unsafe TSRMLS_CC)) { + case FAILURE: + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { + if (!allow_async_unsafe || phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { + phpdbg_output_err_buf(NULL, "%b", "%b" TSRMLS_CC); } - break; + } + break; - case PHPDBG_LEAVE: - case PHPDBG_FINISH: - case PHPDBG_UNTIL: - case PHPDBG_NEXT: { - phpdbg_activate_err_buf(0 TSRMLS_CC); - phpdbg_free_err_buf(TSRMLS_C); - if (!EG(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - phpdbg_error("command", "type=\"noexec\"", "Not running"); - } - goto out; + case PHPDBG_LEAVE: + case PHPDBG_FINISH: + case PHPDBG_UNTIL: + case PHPDBG_NEXT: { + phpdbg_activate_err_buf(0 TSRMLS_CC); + phpdbg_free_err_buf(TSRMLS_C); + if (!EG(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { + phpdbg_error("command", "type=\"noexec\"", "Not running"); } + break; } + } - phpdbg_activate_err_buf(0 TSRMLS_CC); - phpdbg_free_err_buf(TSRMLS_C); + phpdbg_activate_err_buf(0 TSRMLS_CC); + phpdbg_free_err_buf(TSRMLS_C); #ifdef PHP_WIN32 - if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { - sigio_watcher_stop(); - } + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { + sigio_watcher_stop(); + } #undef PARA #endif - } + } - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - PHPDBG_G(req_id) = 0; - } while ((input = phpdbg_read_input(NULL TSRMLS_CC))); + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input TSRMLS_CC); + PHPDBG_G(req_id) = 0; } -out: if (input) { phpdbg_stack_free(&stack); phpdbg_destroy_input(&input TSRMLS_CC); @@ -1308,6 +1320,7 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ } if (full) { + phpdbg_exec = strdup(PHPDBG_G(exec)); /* preserve exec, don't reparse that from cmd */ PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; zend_bailout(); @@ -1593,7 +1606,7 @@ void phpdbg_force_interruption(TSRMLS_D) { next: PHPDBG_G(flags) &= ~PHPDBG_IN_SIGNAL_HANDLER; - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { zend_bailout(); } } -- cgit v1.2.1 From 69bc61de419ccd92bfa308f356b56591f7696413 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Oct 2014 10:48:45 +0100 Subject: Fix nullptr dereference in clean without exec context --- sapi/phpdbg/phpdbg_prompt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 29c75c583c..eca4c6ac2b 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1320,7 +1320,10 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ } if (full) { - phpdbg_exec = strdup(PHPDBG_G(exec)); /* preserve exec, don't reparse that from cmd */ + if (PHPDBG_G(exec)) { + phpdbg_exec = strdup(PHPDBG_G(exec)); /* preserve exec, don't reparse that from cmd */ + } + PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; zend_bailout(); -- cgit v1.2.1 From 3ab7734b88f1842b818526e2e3f34022c3270057 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Oct 2014 20:43:49 +0100 Subject: Stabilize execution, always run destructors and extended file breakpoints --- sapi/phpdbg/phpdbg_prompt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index eca4c6ac2b..a2e4d41042 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -28,7 +28,6 @@ #include "phpdbg_print.h" #include "phpdbg_info.h" #include "phpdbg_break.h" -#include "phpdbg_bp.h" #include "phpdbg_opcode.h" #include "phpdbg_list.h" #include "phpdbg_utils.h" @@ -44,7 +43,6 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); ZEND_EXTERN_MODULE_GLOBALS(output); extern int phpdbg_startup_run; -extern char *phpdbg_exec; #ifdef HAVE_LIBDL #ifdef PHP_WIN32 @@ -641,10 +639,10 @@ PHPDBG_COMMAND(run) /* {{{ */ } zend_try { - PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; + PHPDBG_G(flags) &= ~PHPDBG_IS_INTERACTIVE; + PHPDBG_G(flags) |= PHPDBG_IS_RUNNING; zend_execute(EG(active_op_array) TSRMLS_CC); - PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; - phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); + PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; } zend_catch { EG(active_op_array) = orig_op_array; EG(opline_ptr) = orig_opline; @@ -669,7 +667,11 @@ PHPDBG_COMMAND(run) /* {{{ */ EG(active_op_array) = orig_op_array; EG(opline_ptr) = orig_opline; EG(return_value_ptr_ptr) = orig_retval_ptr; + + phpdbg_clean(1 TSRMLS_CC); } + + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); } @@ -1235,8 +1237,8 @@ int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; - while (1) { - if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { + while (ret == SUCCESS || ret == FAILURE) { + if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_STOPPING) { zend_bailout(); } @@ -1291,6 +1293,7 @@ int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC) /* {{{ */ phpdbg_stack_free(&stack); phpdbg_destroy_input(&input TSRMLS_CC); PHPDBG_G(req_id) = 0; + input = NULL; } if (input) { @@ -1320,10 +1323,6 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ } if (full) { - if (PHPDBG_G(exec)) { - phpdbg_exec = strdup(PHPDBG_G(exec)); /* preserve exec, don't reparse that from cmd */ - } - PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; zend_bailout(); -- cgit v1.2.1 From 190f4f9f18643a306fab7a71b625bf01168b0093 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Oct 2014 22:21:18 +0100 Subject: Fix last commit, and do not output unnecessary information --- sapi/phpdbg/phpdbg_prompt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index a2e4d41042..fd4af2c3cd 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -263,7 +263,7 @@ void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_ goto next_line; } - { + zend_try { char *input = phpdbg_read_input(cmd TSRMLS_CC); phpdbg_param_t stack; @@ -287,7 +287,12 @@ void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_ phpdbg_stack_free(&stack); phpdbg_destroy_input(&input TSRMLS_CC); - } + } zend_catch { + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } + } zend_end_try(); } next_line: line++; @@ -1160,6 +1165,8 @@ PHPDBG_COMMAND(clean) /* {{{ */ phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files))); + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; + phpdbg_clean(1 TSRMLS_CC); phpdbg_xml(""); -- cgit v1.2.1 From 50756b515c76bb9c43a01bfce03207906f596005 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 26 Oct 2014 23:33:54 +0100 Subject: Do not execute anything after quit or clean command --- sapi/phpdbg/phpdbg_prompt.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index fd4af2c3cd..5e2cc03d50 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1438,6 +1438,10 @@ void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */ } #endif + if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_STOPPING) { + zend_bailout(); + } + EG(in_execution) = 1; #if PHP_VERSION_ID >= 50500 -- cgit v1.2.1 From fe5f5d40f29387bb6cae79dfbab50463a66b53ba Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 28 Oct 2014 12:27:19 +0100 Subject: *Always* clean up and run destructors --- sapi/phpdbg/phpdbg_prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 73ecbcb892..262b265a2e 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -676,10 +676,10 @@ PHPDBG_COMMAND(run) /* {{{ */ EG(active_op_array) = orig_op_array; EG(opline_ptr) = orig_opline; EG(return_value_ptr_ptr) = orig_retval_ptr; - - phpdbg_clean(1 TSRMLS_CC); } + phpdbg_clean(1 TSRMLS_CC); + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); -- cgit v1.2.1 From fd8a70b1ee8889234be5e9dded768852f26c9c5e Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 28 Oct 2014 13:55:56 +0100 Subject: Typo (notfoundc => notfound) --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 262b265a2e..733d3cbe48 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1132,7 +1132,7 @@ PHPDBG_COMMAND(register) /* {{{ */ phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname); } else { - phpdbg_error("register", "type=\"notfoundc\" function=\"%s\"", "The requested function (%s) could not be found", param->str); + phpdbg_error("register", "type=\"notfound\" function=\"%s\"", "The requested function (%s) could not be found", param->str); } } else { phpdbg_error("register", "type=\"inuse\" function=\"%s\"", "The requested name (%s) is already in use", lcname); -- cgit v1.2.1 From 297baa0c18d8d04de7a683a51b9f069c84a855f3 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 28 Oct 2014 17:20:21 +0100 Subject: Remove the ugly hack via a temp file to store breakpoints --- sapi/phpdbg/phpdbg_prompt.c | 184 ++++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 77 deletions(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 733d3cbe48..c1fcb59a08 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -208,98 +208,128 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ * return FAILURE; } /* }}} */ -void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ -{ - struct stat sb; +struct phpdbg_init_state { + int line; + zend_bool in_code; + char *code; + size_t code_len; + const char *init_file; +}; - if (init_file && VCWD_STAT(init_file, &sb) != -1) { - FILE *fp = fopen(init_file, "r"); - if (fp) { - int line = 1; +static void phpdbg_line_init(char *cmd, struct phpdbg_init_state *state TSRMLS_DC) { + size_t cmd_len = strlen(cmd); - char cmd[PHPDBG_MAX_CMD]; - size_t cmd_len = 0L; - char *code = NULL; - size_t code_len = 0L; - zend_bool in_code = 0; + state->line++; - while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { - cmd_len = strlen(cmd)-1; - - while (cmd_len > 0L && isspace(cmd[cmd_len-1])) - cmd_len--; - - cmd[cmd_len] = '\0'; - - if (*cmd && cmd_len > 0L && cmd[0] != '#') { - if (cmd_len == 2) { - if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { - in_code = 1; - goto next_line; - } else { - if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { - in_code = 0; - code[code_len] = '\0'; - { - zend_eval_stringl(code, code_len, NULL, "phpdbginit code" TSRMLS_CC); - } - free(code); - code = NULL; - goto next_line; - } - } - } + while (cmd_len > 0L && isspace(cmd[cmd_len-1])) { + cmd_len--; + } - if (in_code) { - if (code == NULL) { - code = malloc(cmd_len + 1); - } else code = realloc(code, code_len + cmd_len + 1); + cmd[cmd_len] = '\0'; - if (code) { - memcpy( - &code[code_len], cmd, cmd_len); - code_len += cmd_len; - } - goto next_line; - } + if (*cmd && cmd_len > 0L && cmd[0] != '#') { + if (cmd_len == 2) { + if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { + state->in_code = 1; + return; + } else { + if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { + state->in_code = 0; + state->code[state->code_len] = '\0'; + zend_eval_stringl(state->code, state->code_len, NULL, "phpdbginit code" TSRMLS_CC); + free(state->code); + state->code = NULL; + return; + } + } + } - zend_try { - char *input = phpdbg_read_input(cmd TSRMLS_CC); - phpdbg_param_t stack; + if (state->in_code) { + if (state->code == NULL) { + state->code = malloc(cmd_len + 1); + } else { + state->code = realloc(state->code, state->code_len + cmd_len + 1); + } - phpdbg_init_param(&stack, STACK_PARAM); + if (state->code) { + memcpy(&state->code[state->code_len], cmd, cmd_len); + state->code_len += cmd_len; + } - phpdbg_activate_err_buf(1 TSRMLS_CC); + return; + } - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { - case FAILURE: - phpdbg_activate_err_buf(0 TSRMLS_CC); - if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, init_file, line, input); - } - break; - } - } + zend_try { + char *input = phpdbg_read_input(cmd TSRMLS_CC); + phpdbg_param_t stack; + + phpdbg_init_param(&stack, STACK_PARAM); + + phpdbg_activate_err_buf(1 TSRMLS_CC); + if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { + switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { + case FAILURE: phpdbg_activate_err_buf(0 TSRMLS_CC); - phpdbg_free_err_buf(TSRMLS_C); - - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - } zend_catch { - PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - zend_bailout(); + if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { + if (state->init_file) { + phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, state->init_file, state->line, input); + } else { + phpdbg_output_err_buf("initfailure", "%b line=\"%d\" input=\"%s\"", "Unrecognized command on line %d: %s, %b!" TSRMLS_CC, state->line, input); + } } - } zend_end_try(); + break; } -next_line: - line++; } - if (code) { - free(code); + phpdbg_activate_err_buf(0 TSRMLS_CC); + phpdbg_free_err_buf(TSRMLS_C); + + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input TSRMLS_CC); + } zend_catch { + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } + } zend_end_try(); + } + +} + +void phpdbg_string_init(char *buffer TSRMLS_DC) { + struct phpdbg_init_state state = {0}; + char *str = strtok(buffer, "\n"); + + while (str) { + phpdbg_line_init(str, &state TSRMLS_CC); + + str = strtok(NULL, "\n"); + } + + if (state.code) { + free(state.code); + } +} + +void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ +{ + struct stat sb; + + if (init_file && VCWD_STAT(init_file, &sb) != -1) { + FILE *fp = fopen(init_file, "r"); + if (fp) { + char cmd[PHPDBG_MAX_CMD]; + struct phpdbg_init_state state = {0}; + + state.init_file = init_file; + + while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { + phpdbg_line_init(cmd, &state TSRMLS_CC); + } + + if (state.code) { + free(state.code); } fclose(fp); -- cgit v1.2.1 From fc904569ea5c5513925a69bf43820845eb3db104 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 29 Oct 2014 20:03:28 +0100 Subject: fix output globals importing --- sapi/phpdbg/phpdbg_prompt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_prompt.c') diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index c1fcb59a08..915bccfa69 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -41,7 +41,6 @@ #include "phpdbg_eol.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -ZEND_EXTERN_MODULE_GLOBALS(output); extern int phpdbg_startup_run; #ifdef HAVE_LIBDL -- cgit v1.2.1