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.c | 44 ++++++++++++++++++++---------- sapi/phpdbg/phpdbg.h | 4 ++- sapi/phpdbg/phpdbg_io.c | 4 +++ sapi/phpdbg/phpdbg_prompt.c | 11 ++++++-- sapi/phpdbg/tests/commands/0104_clean.test | 1 - 5 files changed, 46 insertions(+), 18 deletions(-) (limited to 'sapi/phpdbg') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 3e31f76898..b7fb5e5afc 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -544,7 +544,7 @@ static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */ static int php_sapi_phpdbg_deactivate(TSRMLS_D) /* {{{ */ { - if ((PHPDBG_G(flags) & (PHPDBG_IS_CLEANING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_CLEANING) { + if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) == PHPDBG_IS_CLEANING) { zend_phpdbg_globals *pg = PHPDBG_G(backup) = calloc(1, sizeof(zend_phpdbg_globals)); php_phpdbg_globals_ctor(pg); @@ -554,7 +554,7 @@ static int php_sapi_phpdbg_deactivate(TSRMLS_D) /* {{{ */ pg->oplog = PHPDBG_G(oplog); pg->prompt[0] = PHPDBG_G(prompt)[0]; pg->prompt[1] = PHPDBG_G(prompt)[1]; - memset(pg->colors, PHPDBG_G(colors), sizeof(pg->colors)); + memcpy(pg->colors, PHPDBG_G(colors), sizeof(pg->colors)); pg->eol = PHPDBG_G(eol); pg->flags = PHPDBG_G(flags) & PHPDBG_PRESERVE_FLAGS_MASK; } @@ -1035,7 +1035,7 @@ int main(int argc, char **argv) /* {{{ */ zend_ulong flags; char *php_optarg; int php_optind, opt, show_banner = 1; - long cleaning = 0; + long cleaning = -1; zend_bool remote = 0; int step = 0; zend_phpdbg_globals *settings = NULL; @@ -1491,21 +1491,20 @@ phpdbg_main: /* Make stdin, stdout and stderr accessible from PHP scripts */ phpdbg_register_file_handles(TSRMLS_C); - if (show_banner) { + if (show_banner && cleaning < 2) { /* print blurb */ - phpdbg_welcome((cleaning > 0) TSRMLS_CC); + phpdbg_welcome(cleaning == 1 TSRMLS_CC); } - /* auto compile */ - if (PHPDBG_G(exec)) { - phpdbg_compile(TSRMLS_C); - } + cleaning = -1; /* initialize from file */ PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC); + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC); + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; @@ -1514,14 +1513,24 @@ phpdbg_main: goto phpdbg_out; } + /* auto compile */ + if (PHPDBG_G(exec)) { + if (settings) { + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + } + phpdbg_compile(TSRMLS_C); + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + } + /* step from here, not through init */ if (step) { PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } if (phpdbg_startup_run) { - /* no need to try{}, run does it ... */ - PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); + zend_try { + PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); + } zend_end_try(); if (phpdbg_startup_run > 1) { /* if -r is on the command line more than once just quit */ goto phpdbg_out; @@ -1537,7 +1546,9 @@ phpdbg_interact: } zend_catch { if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) { FILE *bp_tmp_fp = fopen(bp_tmp_file, "w"); + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC); + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; fclose(bp_tmp_fp); cleaning = 1; } else { @@ -1589,9 +1600,13 @@ phpdbg_out: } __except(phpdbg_exception_handler_win32(xp = GetExceptionInformation())) { phpdbg_error("segfault", "", "Access violation (Segementation fault) encountered\ntrying to abort cleanly..."); } -/* phpdbg_out: */ #endif + if (cleaning <= 0) { + PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING; + cleaning = -1; + } + { int i; /* free argv */ @@ -1638,9 +1653,10 @@ phpdbg_out: if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING) { phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); + cleaning++; } - if ((PHPDBG_G(flags) & (PHPDBG_IS_CLEANING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_CLEANING) { + if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) == PHPDBG_IS_CLEANING) { settings = PHPDBG_G(backup); } @@ -1654,7 +1670,7 @@ phpdbg_out: } - if (cleaning || remote) { + if (cleaning > 0 || remote) { goto phpdbg_main; } diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index 57ea7ee570..65bdcd0d6f 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -177,12 +177,14 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC); #define PHPDBG_IN_SIGNAL_HANDLER (1ULL<<33) +#define PHPDBG_DISCARD_OUTPUT (1ULL<<34) + #define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL | PHPDBG_IN_FINISH | PHPDBG_IN_LEAVE) #define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP) #define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP | PHPDBG_HAS_SYM_BP | PHPDBG_HAS_METHOD_BP | PHPDBG_HAS_OPLINE_BP | PHPDBG_HAS_COND_BP | PHPDBG_HAS_OPCODE_BP | PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP) #define PHPDBG_IS_STOPPING (PHPDBG_IS_QUITTING | PHPDBG_IS_CLEANING) -#define PHPDBG_PRESERVE_FLAGS_MASK (PHPDBG_SHOW_REFCOUNTS | PHPDBG_IS_STEPONEVAL | PHPDBG_IS_BP_ENABLED | PHPDBG_STEP_OPCODE) +#define PHPDBG_PRESERVE_FLAGS_MASK (PHPDBG_SHOW_REFCOUNTS | PHPDBG_IS_STEPONEVAL | PHPDBG_IS_BP_ENABLED | PHPDBG_STEP_OPCODE | PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED) #ifndef _WIN32 # define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_BP_ENABLED) diff --git a/sapi/phpdbg/phpdbg_io.c b/sapi/phpdbg/phpdbg_io.c index a2a5c5969f..6908a687d7 100644 --- a/sapi/phpdbg/phpdbg_io.c +++ b/sapi/phpdbg/phpdbg_io.c @@ -187,6 +187,10 @@ PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC) { + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { return phpdbg_send_bytes(sock, ptr, len); } 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(""); diff --git a/sapi/phpdbg/tests/commands/0104_clean.test b/sapi/phpdbg/tests/commands/0104_clean.test index d50903c479..2c7660ad60 100644 --- a/sapi/phpdbg/tests/commands/0104_clean.test +++ b/sapi/phpdbg/tests/commands/0104_clean.test @@ -9,7 +9,6 @@ #Functions %d #Constants %d #Includes %d -#[Nothing to execute!] ################################################# clean quit -- cgit v1.2.1