phpdbg_break userland

This commit is contained in:
krakjoe 2013-11-11 14:33:53 +00:00
parent dc3ef20964
commit 34ae94ad9a
5 changed files with 44 additions and 1 deletions

View File

@ -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),

View File

@ -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;
} /* }}} */

View File

@ -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);

View File

@ -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;
} /* }}} */

View File

@ -10,6 +10,8 @@ if (!isset($greeting)) {
echo test();
}
phpdbg_break();
test2();
return true;
?>