- Get rid llist from symbol breakpoint

This commit is contained in:
Felipe Pena 2013-11-10 19:38:58 -02:00
parent 26ec44350e
commit d141bf4ea8
4 changed files with 42 additions and 54 deletions

View file

@ -18,6 +18,7 @@
#include "phpdbg.h"
#include "phpdbg_prompt.h"
#include "phpdbg_bp.h"
ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
@ -44,15 +45,20 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
return SUCCESS;
} /* }}} */
static void php_phpdbg_destroy_break(void *brake) /* {{{ */
static void php_phpdbg_destroy_bp_file(void *brake) /* {{{ */
{
zend_llist_destroy((zend_llist*)brake);
} /* }}} */
static void php_phpdbg_destroy_bp_symbol(void *brake) /* {{{ */
{
efree(((phpdbg_breaksymbol_t*)brake)->symbol);
} /* }}} */
static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
{
zend_hash_init(&PHPDBG_G(bp_files), 8, NULL, php_phpdbg_destroy_break, 0);
zend_hash_init(&PHPDBG_G(bp_symbols), 8, NULL, php_phpdbg_destroy_break, 0);
zend_hash_init(&PHPDBG_G(bp_files), 8, NULL, php_phpdbg_destroy_bp_file, 0);
zend_hash_init(&PHPDBG_G(bp_symbols), 8, NULL, php_phpdbg_destroy_bp_symbol, 0);
return SUCCESS;
} /* }}} */

View file

@ -32,13 +32,6 @@ static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */
efree((char*)bp->filename);
} /* }}} */
static void phpdbg_llist_breaksym_dtor(void *data) /* {{{ */
{
phpdbg_breaksymbol_t *bp = (phpdbg_breaksymbol_t*) data;
efree((char*)bp->symbol);
} /* }}} */
void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
{
phpdbg_breakfile_t new_break;
@ -66,31 +59,21 @@ void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{
zend_llist_add_element(break_files_ptr, &new_break);
} /* }}} */
void phpdbg_set_breakpoint_symbol(const char *name, long opline_num TSRMLS_DC) /* {{{ */
void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */
{
phpdbg_breaksymbol_t new_break;
zend_llist *break_sym_ptr;
size_t name_len = strlen(name);
new_break.symbol = estrndup(name, name_len + 1);
new_break.opline_num = opline_num;
if (!zend_hash_exists(&PHPDBG_G(bp_symbols), name, name_len)) {
phpdbg_breaksymbol_t new_break;
PHPDBG_G(has_sym_bp) = 1;
if (zend_hash_find(&PHPDBG_G(bp_symbols),
new_break.symbol, name_len, (void**)&break_sym_ptr) == FAILURE) {
zend_llist break_syms;
zend_llist_init(&break_syms, sizeof(phpdbg_breaksymbol_t),
phpdbg_llist_breaksym_dtor, 0);
zend_hash_update(&PHPDBG_G(bp_symbols),
new_break.symbol, name_len, &break_syms, sizeof(zend_llist),
(void**)&break_sym_ptr);
}
new_break.symbol = estrndup(name, name_len + 1);
new_break.id = PHPDBG_G(bp_count)++;
zend_llist_add_element(break_sym_ptr, &new_break);
zend_hash_update(&PHPDBG_G(bp_symbols), new_break.symbol,
name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL);
}
} /* }}} */
int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
@ -119,7 +102,7 @@ int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
{
const char *fname;
zend_llist *break_list;
phpdbg_breaksymbol_t *bp;
if (fbc->type != ZEND_USER_FUNCTION) {
return FAILURE;
@ -132,8 +115,9 @@ int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
}
if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
(void**)&break_list) == SUCCESS) {
printf("breakpoint reached!\n");
(void**)&bp) == SUCCESS) {
printf("Breakpoint #%d in %s() at %s\n", bp->id, bp->symbol,
zend_get_executed_filename(TSRMLS_C));
return SUCCESS;
}

View file

@ -34,12 +34,11 @@ typedef struct _phpdbg_breakfile_t {
*/
typedef struct _phpdbg_breaksymbol_t {
const char *symbol;
long opline_num;
int id;
} phpdbg_breaksymbol_t;
void phpdbg_set_breakpoint_file(const char*, long TSRMLS_DC);
void phpdbg_set_breakpoint_symbol(const char*, long TSRMLS_DC);
void phpdbg_set_breakpoint_symbol(const char* TSRMLS_DC);
int phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC);
int phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC);

View file

@ -228,14 +228,13 @@ static PHPDBG_COMMAND(break) /* {{{ */
phpdbg_set_breakpoint_file(resolved_name, line_num TSRMLS_CC);
} else {
char name[200];
const char *opnum_pos = zend_memrchr(expr, '#', expr_len);
long opline_num = opnum_pos ? strtol(opnum_pos+1, NULL, 0) : 0;
size_t name_len = opnum_pos ? opnum_pos - expr : strlen(expr);
size_t name_len = strlen(expr);
name_len = MIN(name_len, 200);
memcpy(name, expr, name_len);
name[name_len] = 0;
phpdbg_set_breakpoint_symbol(name, opline_num TSRMLS_CC);
phpdbg_set_breakpoint_symbol(name TSRMLS_CC);
}
return SUCCESS;
@ -384,17 +383,17 @@ zend_vm_enter:
if (PHPDBG_G(has_sym_bp)) {
zend_execute_data *previous = execute_data->prev_execute_data;
if (previous && (previous != execute_data)) {
if (previous->opline) {
if (previous->opline->opcode == ZEND_DO_FCALL || previous->opline->opcode == ZEND_DO_FCALL_BY_NAME) {
if (phpdbg_find_breakpoint_symbol(previous->function_state.function TSRMLS_CC) == SUCCESS) {
if (previous && previous != execute_data && previous->opline) {
if (previous->opline->opcode == ZEND_DO_FCALL
|| previous->opline->opcode == ZEND_DO_FCALL_BY_NAME) {
if (phpdbg_find_breakpoint_symbol(
previous->function_state.function TSRMLS_CC) == SUCCESS) {
while (phpdbg_interactive(0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
continue;
}
}
}
}
}
}
PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);