]> granicus.if.org Git - php/commitdiff
condense globals
authorkrakjoe <joe.watkins@live.co.uk>
Tue, 12 Nov 2013 01:24:53 +0000 (01:24 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Tue, 12 Nov 2013 01:24:53 +0000 (01:24 +0000)
introduce flags
sensible silence and stepping

phpdbg.c
phpdbg.h
phpdbg_bp.c
phpdbg_prompt.c

index a37781b245367c94a25c1661398a00bf6b84d99d..794f6479c195caf9b094c9461f5f6c2f30a672ab 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -30,18 +30,12 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
     pg->exec = NULL;
     pg->exec_len = 0;
     pg->ops = NULL;
-    pg->stepping = 0;
     pg->vmret = 0;
-    pg->quitting = 0;
     pg->bp_count = 0;
-    pg->quiet = 0;
     pg->last = NULL;
     pg->last_params = NULL;
     pg->last_params_len = 0;
-    pg->has_file_bp = 0;
-    pg->has_sym_bp = 0;
-    pg->has_opline_bp = 0;
-    pg->has_method_bp = 0;
+    pg->flags = PHPDBG_IS_QUIET;
 } /* }}} */
 
 static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
@@ -407,7 +401,7 @@ int main(int argc, char *argv[]) /* {{{ */
                    } zend_catch {
                 
                    } zend_end_try();
-               } while(!PHPDBG_G(quitting));
+               } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
                
                if (ini_entries) {
                    free(ini_entries);
index 7477c401116510a4e9590a0397a7bcefdda4e6e3..457d682ce67455191a5baecc73ce64b22555b11a 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
 
 #define PHPDBG_NEXT 2
 
+/* {{{ flags */
+#define PHPDBG_HAS_FILE_BP      0x00000001
+#define PHPDBG_HAS_SYM_BP       0x00000010
+#define PHPDBG_HAS_OPLINE_BP    0x00000100
+#define PHPDBG_HAS_METHOD_BP    0x00001000
+
+#define PHPDBG_IS_STEPPING      0x00010000
+#define PHPDBG_IS_QUIET         0x00100000
+#define PHPDBG_IS_QUITTING      0x01000000 /* }}} */
+
 typedef struct _phpdbg_command_t phpdbg_command_t;
 
 ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
@@ -57,17 +67,11 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
        zend_op_array *ops;         /* op_array */
        zval *retval;               /* return value */
        int bp_count;               /* breakpoint count */
-       int stepping;               /* stepping */
        int vmret;                  /* return from last opcode handler execution */
-       zend_bool has_file_bp;      /* file-based breakpoint has been set */
-       zend_bool has_sym_bp;       /* symbol-based breakpoint has been set */
-       zend_bool has_opline_bp;    /* opline-based breakpoint has been set */
-       zend_bool has_method_bp;    /* method-based breakpoint has been set */
-       zend_bool quitting;         /* quitting flag */
-       int quiet;                  /* quiet */
        phpdbg_command_t *last;     /* last command */
        const char *last_params;    /* last expression */
        size_t last_params_len;     /* last expression length */
+       zend_ulong flags;           /* phpdbg flags */
 ZEND_END_MODULE_GLOBALS(phpdbg)
 
 #endif /* PHPDBG_H */
index ab4bf55a0b75c3b5fa96c7a04034395f9ddde760..e1138193d302ba391962359f63c7e12c885418f4 100644 (file)
@@ -50,7 +50,7 @@ void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{
        new_break.filename = estrndup(path, path_len);
        new_break.line = line_num;
 
-       PHPDBG_G(has_file_bp) = 1;
+       PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
 
        if (zend_hash_find(&PHPDBG_G(bp_files),
                new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) {
@@ -78,7 +78,7 @@ void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */
        if (!zend_hash_exists(&PHPDBG_G(bp_symbols), name, name_len)) {
                phpdbg_breaksymbol_t new_break;
 
-               PHPDBG_G(has_sym_bp) = 1;
+               PHPDBG_G(flags) |= PHPDBG_HAS_SYM_BP;
 
                new_break.symbol = estrndup(name, name_len + 1);
                new_break.id = PHPDBG_G(bp_count)++;
@@ -111,7 +111,7 @@ void phpdbg_set_breakpoint_method(const char* class_name,
     if (!zend_hash_exists(class_table, func_name, func_len)) {
         phpdbg_breakmethod_t new_break;
         
-        PHPDBG_G(has_method_bp) = 1;
+        PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP;
         
         new_break.class_name = class_name;
         new_break.class_len = class_len;
@@ -135,7 +135,7 @@ void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */
        if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), opline)) {
                phpdbg_breakline_t new_break;
 
-               PHPDBG_G(has_opline_bp) = 1;
+               PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
 
         new_break.name = strdup(name);
                new_break.opline = opline;
@@ -154,7 +154,7 @@ void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{
        if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), (zend_ulong) opline)) {
                phpdbg_breakline_t new_break;
 
-               PHPDBG_G(has_opline_bp) = 1;
+               PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
 
         asprintf(
             (char**)&new_break.name, "%p", (zend_op*) opline);
@@ -272,10 +272,7 @@ void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
     zend_hash_clean(&PHPDBG_G(bp_oplines));
     zend_hash_clean(&PHPDBG_G(bp_methods));
     
-    PHPDBG_G(has_file_bp) = 0;
-    PHPDBG_G(has_sym_bp) = 0;
-    PHPDBG_G(has_opline_bp) = 0;
-    PHPDBG_G(has_method_bp) = 0;
+    PHPDBG_G(flags) &= ~(PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP);
     PHPDBG_G(bp_count) = 0;
 } /* }}} */
 
index 27caeddcbc3883fb29d1c11199306022f1702900..eb087e00b7bc3fa723a9076298d21b610fc75b56 100644 (file)
@@ -98,9 +98,14 @@ static PHPDBG_COMMAND(compile) /* {{{ */
 
 static PHPDBG_COMMAND(step) /* {{{ */
 {
-       PHPDBG_G(stepping) = atoi(expr);
+       if (atoi(expr)) {
+           PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+       } else {
+           PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
+       }
+       
        printf(
-           "[Stepping %s]\n", PHPDBG_G(stepping) ? "on" : "off");
+           "[Stepping %s]\n", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
        return SUCCESS;
 } /* }}} */
 
@@ -130,7 +135,7 @@ static PHPDBG_COMMAND(run) /* {{{ */
                zend_try {
                        zend_execute(EG(active_op_array) TSRMLS_CC);
                } zend_catch {
-                       if (!PHPDBG_G(quitting)) {
+                       if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                                printf("[Caught excetion in VM]\n");
                                return FAILURE;
                        } else return SUCCESS;
@@ -146,14 +151,24 @@ static PHPDBG_COMMAND(run) /* {{{ */
 static PHPDBG_COMMAND(eval) /* {{{ */
 {
        zval retval;
-
+    
        if (expr_len) {
+           zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
+           
+           /* disable stepping while eval() in progress */
+           PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+           
                if (zend_eval_stringl((char*)expr, expr_len-1,
                        &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
                        zend_print_zval_r(
                            &retval, 0 TSRMLS_CC);
                        printf("\n");
                }
+               
+               /* switch stepping back on */
+               if (stepping) {
+                   PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+               }
        } else {
                printf("[No expression provided !]\n");
                return FAILURE;
@@ -204,7 +219,7 @@ static PHPDBG_COMMAND(print) /* {{{ */
        printf("Execution Context Information:\n");
        printf("Exec\t\t%s\n", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
        printf("Compiled\t%s\n", PHPDBG_G(ops) ? "yes" : "no");
-       printf("Stepping\t%s\n", PHPDBG_G(stepping) ? "on" : "off");
+       printf("Stepping\t%s\n", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
 
        if (PHPDBG_G(ops)) {
                printf("Opcodes\t\t%d\n", PHPDBG_G(ops)->last);
@@ -224,7 +239,7 @@ static PHPDBG_COMMAND(print) /* {{{ */
     printf("Constants\t%d\n", zend_hash_num_elements(EG(zend_constants)));
     printf("Included\t%d\n", zend_hash_num_elements(&EG(included_files)));
 
-    if (PHPDBG_G(has_file_bp)) {
+    if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) {
         HashPosition position;
         zend_llist *points;
 
@@ -268,7 +283,7 @@ static PHPDBG_COMMAND(print) /* {{{ */
     }
 #endif
 
-    if (PHPDBG_G(has_opline_bp)) {
+    if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) {
         HashPosition position;
         phpdbg_breakline_t *brake;
 
@@ -364,7 +379,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
 
 static PHPDBG_COMMAND(quit) /* {{{ */
 {
-    PHPDBG_G(quitting)=1;
+    PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
 
        zend_bailout();
 
@@ -459,10 +474,14 @@ static PHPDBG_COMMAND(help) /* {{{ */
 } /* }}} */
 
 static PHPDBG_COMMAND(quiet) { /* {{{ */
-    PHPDBG_G(quiet) = atoi(expr);
+    if (atoi(expr)) {
+        PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
+    } else {
+        PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
+    }
 
     printf(
-        "[Quietness %s]\n", PHPDBG_G(quiet) ? "enabled" : "disabled");
+        "[Quietness %s]\n", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "enabled" : "disabled");
 
     return SUCCESS;
 } /* }}} */
@@ -530,7 +549,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
 
        printf("phpdbg> ");
 
-       while (!PHPDBG_G(quitting) &&
+       while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING) &&
               fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
                size_t cmd_len = strlen(cmd) - 1;
 
@@ -541,7 +560,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
                if (cmd_len) {
                    switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
                        case FAILURE:
-                           if (!PHPDBG_G(quitting)) {
+                           if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                                printf(
                                    "[Failed to execute %s !]\n", cmd);
                            }
@@ -556,7 +575,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
                        PHPDBG_G(last_params), PHPDBG_G(last_params_len) TSRMLS_CC);
                }
 
-               if (!PHPDBG_G(quitting)) {
+               if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                    printf("phpdbg> ");
                }
 
@@ -567,10 +586,12 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
 
 static void phpdbg_print_opline(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
 {
-    if (!PHPDBG_G(quiet)) {
+    /* force out a line while stepping so the user knows what is happening */
+    if (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING)) {
         zend_op *opline = execute_data->opline;
 
-        printf("[OPLINE: %p:%s]\n", opline, phpdbg_decode_opcode(opline->opcode));
+        printf(
+            "[OPLINE: %p:%s]\n", opline, phpdbg_decode_opcode(opline->opcode));
     }
 } /* }}} */
 
@@ -595,16 +616,16 @@ zend_vm_enter:
         phpdbg_print_opline(
                    execute_data TSRMLS_CC);
 
-        if (PHPDBG_G(has_file_bp)
+        if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)
             && phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC) == SUCCESS) {
             while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
-                if (!PHPDBG_G(quitting)) {
+                if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                     continue;
                 }
             }
         }
 
-        if ((PHPDBG_G(has_sym_bp)||PHPDBG_G(has_method_bp))) {
+        if ((PHPDBG_G(flags) & (PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_SYM_BP))) {
             zend_execute_data *previous = execute_data->prev_execute_data;
             if (previous && previous != execute_data && previous->opline) {
                 /* check we are the beginning of a function entry */
@@ -615,7 +636,7 @@ zend_vm_enter:
                         case ZEND_INIT_STATIC_METHOD_CALL: {
                             if (phpdbg_find_breakpoint_symbol(previous->function_state.function TSRMLS_CC) == SUCCESS) {
                                 while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
-                                    if (!PHPDBG_G(quitting)) {
+                                    if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                                         continue;
                                     }
                                 }
@@ -626,10 +647,10 @@ zend_vm_enter:
             }
         }
         
-        if (PHPDBG_G(has_opline_bp)
+        if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)
             && phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC) == SUCCESS) {
             while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
-                if (!PHPDBG_G(quitting)) {
+                if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                     continue;
                 }
             }
@@ -637,9 +658,9 @@ zend_vm_enter:
 
         PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
 
-        if (PHPDBG_G(stepping)) {
+        if ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)) {
             while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
-                if (!PHPDBG_G(quitting)) {
+                if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                     continue;
                 }
             }