From: krakjoe Date: Mon, 11 Nov 2013 14:33:53 +0000 (+0000) Subject: phpdbg_break userland X-Git-Tag: php-5.6.0alpha1~110^2~483 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34ae94ad9a080b0a4862344a51fa0da8dfd4d80f;p=php phpdbg_break userland --- diff --git a/phpdbg.c b/phpdbg.c index 214a6fb0fb..6ed4e654df 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -94,10 +94,27 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ return SUCCESS; } /* }}} */ +static PHP_FUNCTION(phpdbg_break) /* {{{ */ +{ + if (EG(active_op_array)) { + phpdbg_set_breakpoint_opline_ex( + EG(active_op_array)->opcodes TSRMLS_CC); + } +} /* }}} */ + +zend_function_entry phpdbg_user_functions[] = { + PHP_FE(phpdbg_break, NULL) +#ifdef PHP_FE_END + PHP_FE_END +#else + {NULL,NULL,NULL} +#endif +}; + static zend_module_entry sapi_phpdbg_module_entry = { STANDARD_MODULE_HEADER, "phpdbg", - NULL, + phpdbg_user_functions, PHP_MINIT(phpdbg), NULL, PHP_RINIT(phpdbg), diff --git a/phpdbg_bp.c b/phpdbg_bp.c index 8185196bd1..e17608c609 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -104,6 +104,24 @@ void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */ } } /* }}} */ +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; + + asprintf((char**)&new_break.name, "%#x", opline); + + new_break.opline = opline; + new_break.id = PHPDBG_G(bp_count)++; + + zend_hash_index_update(&PHPDBG_G(bp_oplines), opline, &new_break, sizeof(phpdbg_breakline_t), NULL); + + printf("[Breakpoint #%d added at %#x]\n", new_break.id, new_break.opline); + } +} /* }}} */ + int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */ { size_t name_len = strlen(op_array->filename); @@ -166,3 +184,4 @@ int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ * return FAILURE; } /* }}} */ + diff --git a/phpdbg_bp.h b/phpdbg_bp.h index f6a8b6bcd7..1f04af9f6c 100644 --- a/phpdbg_bp.h +++ b/phpdbg_bp.h @@ -52,6 +52,7 @@ typedef struct _phpdbg_breakline_t { void phpdbg_set_breakpoint_file(const char*, long TSRMLS_DC); void phpdbg_set_breakpoint_symbol(const char* TSRMLS_DC); void phpdbg_set_breakpoint_opline(const char* TSRMLS_DC); +void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t TSRMLS_DC); int phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC); int phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC); diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 8db72ed44a..f0f299ec51 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -376,6 +376,10 @@ static PHPDBG_COMMAND(clear) /* {{{ */ zend_hash_clean(&PHPDBG_G(bp_symbols)); zend_hash_clean(&PHPDBG_G(bp_oplines)); + PHPDBG_G(has_file_bp) = 0; + PHPDBG_G(has_sym_bp) = 0; + PHPDBG_G(has_opline_bp) = 0; + return SUCCESS; } /* }}} */ diff --git a/test.php b/test.php index bed99d3e9b..3ac566ce76 100644 --- a/test.php +++ b/test.php @@ -10,6 +10,8 @@ if (!isset($greeting)) { echo test(); } +phpdbg_break(); + test2(); return true; ?>