From: Felipe Pena Date: Wed, 20 Nov 2013 18:52:34 +0000 (-0200) Subject: - Initial code for signal handling X-Git-Tag: php-5.6.0alpha1~110^2~159 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed16d3b60845f8c60b48ffd67cfd9f9f7ba0fdc0;p=php - Initial code for signal handling --- diff --git a/phpdbg.c b/phpdbg.c index 775e04e8f2..3213ea3dcc 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -431,6 +431,13 @@ static void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */ } } /* }}} */ +void phpdbg_sigint_handler(int signo) +{ + TSRMLS_FETCH(); + PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED; + phpdbg_notice("here"); +} + int main(int argc, char **argv) /* {{{ */ { sapi_module_struct *phpdbg = &phpdbg_sapi_module; @@ -449,7 +456,7 @@ int main(int argc, char **argv) /* {{{ */ long cleaning = 0; int run = 0; int step = 0; - + #ifdef ZTS void ***tsrm_ls; #endif @@ -483,7 +490,7 @@ phpdbg_main: opt = 0; run = 0; step = 0; - + while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (opt) { case 'r': @@ -565,7 +572,7 @@ phpdbg_main: case 's': /* set stepping on */ step = 1; break; - + case 'E': /* stepping through eval on */ flags |= PHPDBG_IS_STEPONEVAL; break; @@ -603,6 +610,12 @@ phpdbg_main: phpdbg->ini_entries = ini_entries; if (phpdbg->startup(phpdbg) == SUCCESS) { +#ifdef ZEND_SIGNALS + zend_signal(SIGINT, phpdbg_sigint_handler); +#else + signal(SIGINT, phpdbg_sigint_handler); +#endif + zend_activate(TSRMLS_C); #ifdef ZEND_SIGNALS @@ -651,7 +664,7 @@ phpdbg_main: zend_try { PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; phpdbg_init( - init_file, init_file_len, + init_file, init_file_len, init_file_default TSRMLS_CC); PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; } zend_catch { @@ -660,12 +673,12 @@ phpdbg_main: goto phpdbg_out; } } zend_end_try(); - + /* step from here, not through init */ if (step) { PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } - + if (run) { /* no need to try{}, run does it ... */ PHPDBG_COMMAND_HANDLER(run)(NULL, NULL TSRMLS_CC); diff --git a/phpdbg.h b/phpdbg.h index 108db3759d..967cd8fb0b 100644 --- a/phpdbg.h +++ b/phpdbg.h @@ -99,6 +99,7 @@ #define PHPDBG_IS_REGISTERED (1<<16) #define PHPDBG_IS_STEPONEVAL (1<<17) #define PHPDBG_IS_INITIALIZING (1<<18) +#define PHPDBG_IS_SIGNALED (1<<19) #ifndef _WIN32 # define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED) diff --git a/phpdbg_info.c b/phpdbg_info.c index 246a3f5bec..09c91d5af6 100644 --- a/phpdbg_info.c +++ b/phpdbg_info.c @@ -81,7 +81,7 @@ PHPDBG_INFO(vars) /* {{{ */ phpdbg_notice("Variables: %d", zend_hash_num_elements(&vars)); - + if (zend_hash_num_elements(&vars)) { phpdbg_writeln("Address\t\tRefs\tType\t\tVariable"); for (zend_hash_internal_pointer_reset_ex(&vars, &pos); @@ -106,10 +106,10 @@ PHPDBG_INFO(vars) /* {{{ */ case IS_OBJECT: phpdbg_write("(object)\t"); break; case IS_NULL: phpdbg_write("(null)\t"); break; } - + if (Z_TYPE_PP(data) == IS_RESOURCE) { int type; - + phpdbg_writeln( "%s$%s", Z_ISREF_PP(data) ? "&": "", var); if (zend_list_find(Z_RESVAL_PP(data), &type)) { @@ -144,7 +144,8 @@ PHPDBG_INFO(vars) /* {{{ */ return SUCCESS; } /* }}} */ -static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) { /* {{{ */ +static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) /* {{{ */ +{ phpdbg_write( "%s %s %s (%d)", ((*ce)->type == ZEND_USER_CLASS) ? diff --git a/phpdbg_list.c b/phpdbg_list.c index 241983d742..026f4b9e45 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -239,7 +239,7 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ ops->line_end - ops->line_start + 1, ops->line_start, 0 TSRMLS_CC); } /* }}} */ -void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) +void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ */ { HashTable *func_table = EG(function_table); zend_function* fbc; @@ -275,5 +275,5 @@ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) } efree(func_name); -} +} /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 48ccc19753..37cdfe9df7 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -488,24 +488,24 @@ PHPDBG_COMMAND(eval) /* {{{ */ zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING); zval retval; char *code = NULL; - + if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) { PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING; } if (input && input->start) { code = (char*) input->start; - + if (memcmp( code, "eval", sizeof("eval")-1) == SUCCESS) { code += sizeof("eval")-1; } else code += sizeof("E")-1; - + while (code && isspace(*code)) { code++; } } else phpdbg_error("Nothing to execute"); - + /* disable stepping while eval() in progress */ PHPDBG_G(flags) |= PHPDBG_IN_EVAL; if (zend_eval_stringl(code, strlen(code), @@ -653,21 +653,21 @@ PHPDBG_COMMAND(shell) /* {{{ */ case STR_PARAM: { FILE *fd = NULL; char * program = NULL; - + /* we expect an input, I hope we get one ! */ if (input && input->start) { program = (char*) input->start; - + if (memcmp( program, "shell", sizeof("shell")-1) == SUCCESS) { program += sizeof("shell")-1; } else program += sizeof("-")-1; - + while (program && isspace(*program)) { program++; } } else program = param->str; - + if ((fd=VCWD_POPEN((char*)program, "w"))) { /* do something perhaps ?? do we want input ?? */ fclose(fd); @@ -1210,7 +1210,7 @@ zend_vm_enter: } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));\ } while(0) - /* allow conditional breakpoints and + /* allow conditional breakpoints and initialization to access the vm uninterrupted */ if (PHPDBG_G(flags) & PHPDBG_IN_COND_BP|PHPDBG_IS_INITIALIZING) { /* skip possible breakpoints */ diff --git a/test.php b/test.php index cafbcec3e5..f836ce3939 100644 --- a/test.php +++ b/test.php @@ -26,7 +26,6 @@ function test() { $dbg = new phpdbg(); -$test = 1; var_dump( $dbg->isGreat("PHP Rocks !!")); @@ -34,12 +33,18 @@ var_dump( foreach (test() as $gen) continue; + +$n = 10; +while ($n--) { + sleep(1); +} + echo "it works!\n"; if (isset($dump)) var_dump($_SERVER); -function phpdbg_test_ob() +function phpdbg_test_ob() { echo 'Start'; ob_start(); @@ -48,4 +53,6 @@ function phpdbg_test_ob() echo 'End'; echo $b; } + + ?>