]> granicus.if.org Git - php/commitdiff
- Initial code for signal handling
authorFelipe Pena <felipensp@gmail.com>
Wed, 20 Nov 2013 18:52:34 +0000 (16:52 -0200)
committerFelipe Pena <felipensp@gmail.com>
Wed, 20 Nov 2013 18:52:34 +0000 (16:52 -0200)
phpdbg.c
phpdbg.h
phpdbg_info.c
phpdbg_list.c
phpdbg_prompt.c
test.php

index 775e04e8f23d159979a1f6f951187d449d25e72c..3213ea3dcc5ff779f7993900f2d062f091e55927 100644 (file)
--- 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);
index 108db3759dbdc6a0858a9fd741432fef35db7483..967cd8fb0beaa68842eda957069566a6c6d6fcf0 100644 (file)
--- 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)
index 246a3f5bec4844ddb9b22b26aec5cd5226ffbd1e..09c91d5af68e21d2e2618c76c165466ce95927f8 100644 (file)
@@ -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) ?
index 241983d742806dcce1c794e572bc8766b1abb8c9..026f4b9e452f2eccd65c57947229becdc598a44f 100644 (file)
@@ -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);
-}
+} /* }}} */
 
index 48ccc19753579beaaaea01ea62e18cc7bf7594d8..37cdfe9df77d7cc0147209d6cbdfbfa163ffae28 100644 (file)
@@ -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 */
index cafbcec3e5f6df005af27d356b5c46d86fe9f7f5..f836ce39393839719dc33b730ccc1af40d448dbe 100644 (file)
--- 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;
 }
+
+
 ?>