]> granicus.if.org Git - php/commitdiff
- Moved catch cmd to "break op" cmd
authorFelipe Pena <felipensp@gmail.com>
Sat, 23 Nov 2013 23:14:16 +0000 (21:14 -0200)
committerFelipe Pena <felipensp@gmail.com>
Sat, 23 Nov 2013 23:14:16 +0000 (21:14 -0200)
Changelog.md
phpdbg.c
phpdbg.h
phpdbg_bp.c
phpdbg_bp.h
phpdbg_break.c
phpdbg_break.h
phpdbg_help.c
phpdbg_help.h
phpdbg_prompt.c
phpdbg_prompt.h

index cb6c0e4e779685c9044f388a352a80f4e914b19c..32ecce879f53e3d5621a3f0691fc0e697edf62c8 100644 (file)
@@ -4,8 +4,7 @@ ChangeLog for phpdbg
 Version 0.1.1 2013-00-00
 ------------------------
 
-1. New commands:
-  - catch   (catch an opcode before its execution)
+
 
 Version 0.1.0 2013-11-23
 ------------------------
index 9bfa2834e2cf1a2fc565e9b1c5be9a31237b0ec0..a81edf556d13fc503431d998617a7e376b7ee639 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -116,10 +116,10 @@ static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],   8, NULL, php_phpdbg_destroy_bp_file, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], 8, NULL, php_phpdbg_destroy_bp_symbol, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, NULL, 0);
+       zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], 8, NULL, NULL, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], 8, NULL, php_phpdbg_destroy_bp_condition, 0);
        zend_hash_init(&PHPDBG_G(seek), 8, NULL, NULL, 0);
-       zend_hash_init(&PHPDBG_G(catch), 8, NULL, NULL, 0);
        zend_hash_init(&PHPDBG_G(registered), 8, NULL, php_phpdbg_destroy_registered, 0);
 
        return SUCCESS;
@@ -130,10 +130,10 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
        zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
        zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
        zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
+       zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]);
        zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
        zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]);
        zend_hash_destroy(&PHPDBG_G(seek));
-       zend_hash_destroy(&PHPDBG_G(catch));
        zend_hash_destroy(&PHPDBG_G(registered));
 
        if (PHPDBG_G(exec)) {
index fec57c96ed0112894c8494db138d3132e3af32fa..af13f6699648649ecedd821f322170cc30e4b930 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
@@ -80,7 +80,8 @@
 #define PHPDBG_BREAK_OPLINE     2
 #define PHPDBG_BREAK_METHOD     3
 #define PHPDBG_BREAK_COND       4
-#define PHPDBG_BREAK_TABLES     5 /* }}} */
+#define PHPDBG_BREAK_OPCODE     5
+#define PHPDBG_BREAK_TABLES     6 /* }}} */
 
 /* {{{ flags */
 #define PHPDBG_HAS_FILE_BP      (1<<1)
 #define PHPDBG_HAS_OPLINE_BP    (1<<3)
 #define PHPDBG_HAS_METHOD_BP    (1<<4)
 #define PHPDBG_HAS_COND_BP      (1<<5)
-#define PHPDBG_BP_MASK          (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP|PHPDBG_HAS_COND_BP)
+#define PHPDBG_HAS_OPCODE_BP    (1<<6)
+#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)
 
-#define PHPDBG_IN_COND_BP       (1<<6)
-#define PHPDBG_IN_EVAL          (1<<7)
+#define PHPDBG_IN_COND_BP       (1<<7)
+#define PHPDBG_IN_EVAL          (1<<8)
 
-#define PHPDBG_IS_STEPPING      (1<<8)
-#define PHPDBG_IS_QUIET         (1<<9)
-#define PHPDBG_IS_QUITTING      (1<<10)
-#define PHPDBG_IS_COLOURED      (1<<11)
-#define PHPDBG_IS_CLEANING      (1<<12)
+#define PHPDBG_IS_STEPPING      (1<<9)
+#define PHPDBG_IS_QUIET         (1<<10)
+#define PHPDBG_IS_QUITTING      (1<<11)
+#define PHPDBG_IS_COLOURED      (1<<12)
+#define PHPDBG_IS_CLEANING      (1<<13)
 
-#define PHPDBG_IN_UNTIL                        (1<<13)
-#define PHPDBG_IN_FINISH               (1<<14)
-#define PHPDBG_IN_LEAVE                        (1<<15)
+#define PHPDBG_IN_UNTIL                        (1<<14)
+#define PHPDBG_IN_FINISH               (1<<15)
+#define PHPDBG_IN_LEAVE                        (1<<16)
 #define PHPDBG_SEEK_MASK               (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE)
 
-#define PHPDBG_IS_REGISTERED   (1<<16)
-#define PHPDBG_IS_STEPONEVAL   (1<<17)
-#define PHPDBG_IS_INITIALIZING (1<<18)
-#define PHPDBG_IS_SIGNALED      (1<<19)
-#define PHPDBG_IS_INTERACTIVE  (1<<20)
+#define PHPDBG_IS_REGISTERED   (1<<17)
+#define PHPDBG_IS_STEPONEVAL   (1<<18)
+#define PHPDBG_IS_INITIALIZING (1<<19)
+#define PHPDBG_IS_SIGNALED      (1<<20)
+#define PHPDBG_IS_INTERACTIVE  (1<<21)
 
-#define PHPDBG_HAS_CATCH        (1<<21)
 
 #ifndef _WIN32
 #   define PHPDBG_DEFAULT_FLAGS    (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED)
@@ -140,7 +141,6 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
        phpdbg_param_t lparam;              /* last param */
        FILE *oplog;                        /* opline log */
        HashTable seek;                                         /* seek oplines */
-       HashTable catch;                                        /* seek opcodes */
        zend_ulong flags;                   /* phpdbg flags */
        HashTable registered;                           /* registered */
        phpdbg_frame_t frame;                           /* frame */
index 82be5370156f5aaf11bf225b4bd1e9522accf1dd..efd73a4b8fdc5a2697ad793c217f0289661e6b7a 100644 (file)
@@ -162,6 +162,25 @@ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{
        }
 } /* }}} */
 
+PHPDBG_API void phpdbg_set_breakpoint_opcode(zend_ulong hash TSRMLS_DC) /* {{{ */
+{
+       phpdbg_breakop_t new_break;
+
+       if (zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash)) {
+               return;
+       }
+
+       new_break.hash = hash;
+       new_break.id = PHPDBG_G(bp_count)++;
+
+       zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash,
+               &new_break, sizeof(phpdbg_breakop_t), NULL);
+
+       PHPDBG_G(flags) |= PHPDBG_HAS_OPCODE_BP;
+
+       phpdbg_notice("Breakpoint #%d added", new_break.id);
+} /* }}} */
+
 PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
 {
        if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) {
@@ -334,6 +353,28 @@ int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ *
        return FAILURE;
 } /* }}} */
 
+int phpdbg_find_breakpoint_opcode(zend_uchar opcode TSRMLS_DC) /* {{{ */
+{
+       phpdbg_breakop_t *bp;
+       const char *opname = phpdbg_decode_opcode(opcode);
+
+       if (memcmp(opname, PHPDBG_STRL("UNKNOWN")) == 0) {
+               return FAILURE;
+       }
+
+       if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE],
+               zend_hash_func(opname, strlen(opname)), (void**)&bp) == SUCCESS) {
+               phpdbg_notice("Breakpoint #%d in %s at %s:%u",
+                       bp->id,
+                       opname,
+                       zend_get_executed_filename(TSRMLS_C),
+                       zend_get_executed_lineno(TSRMLS_C));
+
+               return SUCCESS;
+       }
+       return FAILURE;
+} /* }}} */
+
 int phpdbg_find_conditional_breakpoint(TSRMLS_D) /* {{{ */
 {
        phpdbg_breakcond_t *bp;
index 6bb79462302659b7806c538c992b77b86ddc9bc0..c9ff99be204a850179f6db1166504b24a098011b 100644 (file)
@@ -60,6 +60,14 @@ typedef struct _phpdbg_breakline_t {
     int id;
 } phpdbg_breakline_t;
 
+/**
+ * Breakpoint opcode based representation
+ */
+typedef struct _phpdbg_breakop_t {
+       zend_ulong hash;
+       int id;
+} phpdbg_breakop_t;
+
 /**
  * Breakpoint opline based representation
  */
@@ -72,6 +80,7 @@ typedef struct _phpdbg_breakcond_t {
 PHPDBG_API void phpdbg_set_breakpoint_file(const char*, long TSRMLS_DC);
 PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* TSRMLS_DC);
 PHPDBG_API void phpdbg_set_breakpoint_method(const char*, const char* TSRMLS_DC);
+PHPDBG_API void phpdbg_set_breakpoint_opcode(zend_ulong TSRMLS_DC);
 PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong TSRMLS_DC);
 PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t TSRMLS_DC);
 PHPDBG_API void phpdbg_set_breakpoint_expression(const char*, size_t TSRMLS_DC);
@@ -80,7 +89,9 @@ int phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC);
 int phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC);
 int phpdbg_find_breakpoint_method(zend_op_array* TSRMLS_DC);
 int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t TSRMLS_DC);
+int phpdbg_find_breakpoint_opcode(zend_uchar TSRMLS_DC);
 int phpdbg_find_conditional_breakpoint(TSRMLS_D);
+int phpdbg_find_catch(zend_uchar TSRMLS_DC);
 
 PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D);
 PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC);
index d4bf62f04bdcf7a1680bcc3e2d7ea1aab38d9bde..62404b3d31d21779082846ed86b56d6f5687d0b4 100644 (file)
@@ -58,7 +58,7 @@ PHPDBG_BREAK(address) /* {{{ */
                case ADDR_PARAM:
             phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC);
             break;
-            
+
                phpdbg_default_switch_case();
     }
 
@@ -66,7 +66,7 @@ PHPDBG_BREAK(address) /* {{{ */
 } /* }}} */
 
 PHPDBG_BREAK(on) /* {{{ */
-{      
+{
     switch (param->type) {
         case STR_PARAM:
             phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC);
@@ -108,3 +108,16 @@ PHPDBG_BREAK(func) /* {{{ */
 
     return SUCCESS;
 } /* }}} */
+
+PHPDBG_BREAK(op) /* {{{ */
+{
+       switch (param->type) {
+               case STR_PARAM:
+                       phpdbg_set_breakpoint_opcode(zend_hash_func(param->str, param->len) TSRMLS_CC);
+                       break;
+
+               phpdbg_default_switch_case();
+       }
+
+       return SUCCESS;
+} /* }}} */
index b217f8c97791c1f2735ca8df1b496461af997486..a4f55f314b2f3e23a4b5b4ab9509c559e115d9c4 100644 (file)
@@ -34,6 +34,7 @@ PHPDBG_BREAK(address);
 PHPDBG_BREAK(on);
 PHPDBG_BREAK(lineno);
 PHPDBG_BREAK(func);
+PHPDBG_BREAK(op);
 
 /**
  * Commands
@@ -42,6 +43,7 @@ static const phpdbg_command_t phpdbg_break_commands[] = {
        PHPDBG_COMMAND_D_EX(file,        "specify breakpoint by file:line",                        'F', break_file,    NULL, 1),
        PHPDBG_COMMAND_D_EX(method,      "specify breakpoint by class::method",                    'm', break_method,  NULL, 1),
        PHPDBG_COMMAND_D_EX(address,     "specify breakpoint by address",                          'a', break_address, NULL, 1),
+       PHPDBG_COMMAND_D_EX(op,          "specify breakpoint by opcode",                           'O', break_op,      NULL, 1),
        PHPDBG_COMMAND_D_EX(on,          "specify breakpoint by expression",                       'o', break_on,      NULL, 1),
        PHPDBG_COMMAND_D_EX(lineno,      "specify breakpoint by line of currently executing file", 'l', break_lineno,  NULL, 1),
        PHPDBG_COMMAND_D_EX(func,        "specify breakpoint by global function name",             'f', break_func,    NULL, 1),
index 906fbd1b8856014f558b24c6be55c5d48da8ee3a..b8dc23cf4220956f8648f92e45d83a833faff3f8 100644 (file)
@@ -341,19 +341,6 @@ PHPDBG_HELP(back) /* {{{ */
        return SUCCESS;
 } /* }}} */
 
-PHPDBG_HELP(catch) /* {{{ */
-{
-    phpdbg_help_header();
-       phpdbg_writeln("Catch a VM opcode before its execution");
-    phpdbg_writeln(EMPTY);
-    phpdbg_notice("Examples");
-       phpdbg_writeln("\t%scatch ZEND_ADD", PROMPT);
-       phpdbg_writeln("\t%so ZEND_ADD", PROMPT);
-       phpdbg_writeln("\tWill break the execution before the specified opcode is reached");
-       phpdbg_help_footer();
-       return SUCCESS;
-} /* }}} */
-
 PHPDBG_HELP(frame) /* {{{ */
 {
     phpdbg_help_header();
index 942b2265916cb4f4035947d8d5887d4836bcec3b..8ec9ee235fd3f9eba8abb54542d780c627c5c53f 100644 (file)
@@ -44,7 +44,6 @@ PHPDBG_HELP(clean);
 PHPDBG_HELP(clear);
 PHPDBG_HELP(info);
 PHPDBG_HELP(back);
-PHPDBG_HELP(catch);
 PHPDBG_HELP(frame);
 PHPDBG_HELP(quiet);
 PHPDBG_HELP(list);
@@ -72,7 +71,6 @@ static const phpdbg_command_t phpdbg_help_commands[] = {
        PHPDBG_COMMAND_D_EX(clear,    "reset breakpoints to execute without interruption",                                               'c', help_clear,   NULL, 0),
        PHPDBG_COMMAND_D_EX(info,     "quick access to useful information on the console",                               'i', help_info,    NULL, 0),
        PHPDBG_COMMAND_D_EX(back,     "show debug backtrace information during execution",                               't', help_back,    NULL, 0),
-       PHPDBG_COMMAND_D_EX(catch,    "catch an opcode before its execution",                                            'o', help_catch,   NULL, 0),
        PHPDBG_COMMAND_D_EX(frame,    "switch to a frame in the current stack for inspection",                           'f', help_frame,   NULL, 0),
     PHPDBG_COMMAND_D_EX(quiet,    "be quiet during execution",                                                       'Q', help_quiet,   NULL, 0),
        PHPDBG_COMMAND_D_EX(list,     "list code gives you quick access to code",                                                        'l', help_list,    NULL, 0),
index f4666e8a817b58b26b8f7879136e115acf4db2a0..85fb6cf613f82b4d8c39ea4841ff073115f5364f 100644 (file)
@@ -48,7 +48,6 @@ const phpdbg_command_t phpdbg_prompt_commands[] = {
        PHPDBG_COMMAND_D(print,   "print something",                          'p', phpdbg_print_commands, 2),
        PHPDBG_COMMAND_D(break,   "set breakpoint",                           'b', phpdbg_break_commands, 1),
        PHPDBG_COMMAND_D(back,    "show trace",                               't', NULL, 0),
-       PHPDBG_COMMAND_D(catch,   "catch an opcode",                          'o', NULL, 1),
        PHPDBG_COMMAND_D(frame,   "switch to a frame",                        'f', NULL, 1),
        PHPDBG_COMMAND_D(list,    "lists some code",                          'l', phpdbg_list_commands, 2),
        PHPDBG_COMMAND_D(info,    "displays some informations",               'i', phpdbg_info_commands, 1),
@@ -164,38 +163,6 @@ next_line:
        }
 } /* }}} */
 
-int phpdbg_find_catch(zend_uchar opcode TSRMLS_DC) /* {{{ */
-{
-       const char *opname = phpdbg_decode_opcode(opcode);
-
-       if (memcmp(opname, PHPDBG_STRL("UNKNOWN")) == 0) {
-               return FAILURE;
-       }
-
-       return zend_hash_index_exists(&PHPDBG_G(catch),
-               zend_hash_func(opname, strlen(opname))) ? SUCCESS : FAILURE;
-} /* }}} */
-
-PHPDBG_COMMAND(catch) /* {{{ */
-{
-       switch (param->type) {
-               case STR_PARAM: {
-                       int tmp = 0;
-
-                       zend_hash_index_update(&PHPDBG_G(catch),
-                               zend_hash_func(param->str, param->len),
-                               &tmp, sizeof(int), NULL);
-
-                       PHPDBG_G(flags) |= PHPDBG_HAS_CATCH;
-               }
-               break;
-
-               phpdbg_default_switch_case();
-       }
-
-       return SUCCESS;
-} /* }}} */
-
 PHPDBG_COMMAND(exec) /* {{{ */
 {
        switch (param->type) {
@@ -1423,12 +1390,8 @@ zend_vm_enter:
                        DO_INTERACTIVE();
                }
 
-               if (PHPDBG_G(flags) & PHPDBG_HAS_CATCH
-                       && phpdbg_find_catch(execute_data->opline->opcode TSRMLS_CC) == SUCCESS) {
-                       phpdbg_notice("Catched opcode %s at %s:%u",
-                               phpdbg_decode_opcode(execute_data->opline->opcode),
-                               zend_get_executed_filename(TSRMLS_C),
-                               zend_get_executed_lineno(TSRMLS_C));
+               if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP
+                       && phpdbg_find_breakpoint_opcode(execute_data->opline->opcode TSRMLS_CC) == SUCCESS) {
                        DO_INTERACTIVE();
                }
 
index c0832f045f0f9cd2f88a341b78b6715ef05d6369..7392b96813248fd3760d9df5983ad1a6ce253228 100644 (file)
@@ -40,7 +40,6 @@ PHPDBG_COMMAND(frame);
 PHPDBG_COMMAND(print);
 PHPDBG_COMMAND(break);
 PHPDBG_COMMAND(back);
-PHPDBG_COMMAND(catch);
 PHPDBG_COMMAND(list);
 PHPDBG_COMMAND(info);
 PHPDBG_COMMAND(clean);