Version 0.1.1 2013-00-00
------------------------
-1. New commands:
- - catch (catch an opcode before its execution)
+
Version 0.1.0 2013-11-23
------------------------
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;
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)) {
#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)
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 */
}
} /* }}} */
+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)) {
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;
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
*/
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);
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);
case ADDR_PARAM:
phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC);
break;
-
+
phpdbg_default_switch_case();
}
} /* }}} */
PHPDBG_BREAK(on) /* {{{ */
-{
+{
switch (param->type) {
case STR_PARAM:
phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC);
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;
+} /* }}} */
PHPDBG_BREAK(on);
PHPDBG_BREAK(lineno);
PHPDBG_BREAK(func);
+PHPDBG_BREAK(op);
/**
* 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),
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();
PHPDBG_HELP(clear);
PHPDBG_HELP(info);
PHPDBG_HELP(back);
-PHPDBG_HELP(catch);
PHPDBG_HELP(frame);
PHPDBG_HELP(quiet);
PHPDBG_HELP(list);
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),
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),
}
} /* }}} */
-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) {
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();
}
PHPDBG_COMMAND(print);
PHPDBG_COMMAND(break);
PHPDBG_COMMAND(back);
-PHPDBG_COMMAND(catch);
PHPDBG_COMMAND(list);
PHPDBG_COMMAND(info);
PHPDBG_COMMAND(clean);