From 217c906ea57fecdf78469048bb1384c0e1ff2a19 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 11 Nov 2013 22:33:17 -0200 Subject: [PATCH 1/2] - Improve error message and added check for fstat return --- phpdbg_list.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpdbg_list.c b/phpdbg_list.c index 9102a797fc6..d4603155312 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -33,11 +33,14 @@ void phpdbg_list_file(const char *filename, long count, long offset) /* {{{ */ unsigned int line = 0, displayed = 0; if ((fd = open(filename, O_RDONLY)) == -1) { - printf("[Failed to open file to list]\n"); + printf("[Failed to open file %s to list]\n", filename); return; } - fstat(fd, &st); + if (fstat(fd, &st) == -1) { + printf("[Failed to stat file %s]\n", filename); + goto out; + } last_pos = mem = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); end_pos = mem + st.st_size; @@ -67,6 +70,6 @@ void phpdbg_list_file(const char *filename, long count, long offset) /* {{{ */ } munmap(mem, st.st_size); +out: close(fd); - } /* }}} */ From 8ec5d30097e83ec753153a9504c8755f719c5f82 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 11 Nov 2013 23:41:14 -0200 Subject: [PATCH 2/2] - Added PHPDBG_BP_MASK macro --- phpdbg.h | 1 + phpdbg_bp.c | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/phpdbg.h b/phpdbg.h index 457d682ce67..2e392e9dbb1 100644 --- a/phpdbg.h +++ b/phpdbg.h @@ -50,6 +50,7 @@ #define PHPDBG_HAS_SYM_BP 0x00000010 #define PHPDBG_HAS_OPLINE_BP 0x00000100 #define PHPDBG_HAS_METHOD_BP 0x00001000 +#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP) #define PHPDBG_IS_STEPPING 0x00010000 #define PHPDBG_IS_QUIET 0x00100000 diff --git a/phpdbg_bp.c b/phpdbg_bp.c index e1138193d30..d147d59e515 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -36,7 +36,7 @@ static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */ static void phpdbg_class_breaks_dtor(void *data) /* {{{ */ { phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data; - + efree((char*)bp->class_name); efree((char*)bp->func_name); } /* }}} */ @@ -92,33 +92,33 @@ void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */ } } /* }}} */ -void phpdbg_set_breakpoint_method(const char* class_name, +void phpdbg_set_breakpoint_method(const char* class_name, size_t class_len, - const char* func_name, + const char* func_name, size_t func_len TSRMLS_DC) /* {{{ */ { HashTable class_breaks, *class_table; - + if (zend_hash_find(&PHPDBG_G(bp_methods), class_name, class_len, (void**)&class_table) != SUCCESS) { zend_hash_init( &class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0); zend_hash_update( - &PHPDBG_G(bp_methods), - class_name, class_len, + &PHPDBG_G(bp_methods), + class_name, class_len, (void**)&class_breaks, sizeof(HashTable), (void**)&class_table); } if (!zend_hash_exists(class_table, func_name, func_len)) { phpdbg_breakmethod_t new_break; - + PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP; - + new_break.class_name = class_name; new_break.class_len = class_len; new_break.func_name = func_name; new_break.func_len = func_len; new_break.id = PHPDBG_G(bp_count)++; - + zend_hash_update(class_table, func_name, func_len, &new_break, sizeof(phpdbg_breakmethod_t), NULL); printf( "[Breakpoint #%d added at %s::%s]\n", new_break.id, class_name, func_name); @@ -200,9 +200,9 @@ int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */ if (fbc->type != ZEND_USER_FUNCTION) { return FAILURE; } - + ops = (zend_op_array*)fbc; - + if (ops->scope) { /* find method breaks here */ return phpdbg_find_breakpoint_method( @@ -231,13 +231,13 @@ int phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */ HashTable *class_table; phpdbg_breakmethod_t *bp; - if (zend_hash_find(&PHPDBG_G(bp_methods), ops->scope->name, ops->scope->name_length, + if (zend_hash_find(&PHPDBG_G(bp_methods), ops->scope->name, ops->scope->name_length, (void**)&class_table) == SUCCESS) { if (zend_hash_find( class_table, - ops->function_name, + ops->function_name, strlen(ops->function_name), (void**)&bp) == SUCCESS) { - + printf( "[Breakpoint #%d in %s::%s() at %s:%u]\n", bp->id, bp->class_name, bp->func_name, zend_get_executed_filename(TSRMLS_C), @@ -271,8 +271,8 @@ void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */ zend_hash_clean(&PHPDBG_G(bp_symbols)); zend_hash_clean(&PHPDBG_G(bp_oplines)); zend_hash_clean(&PHPDBG_G(bp_methods)); - - PHPDBG_G(flags) &= ~(PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP); + + PHPDBG_G(flags) &= ~PHPDBG_BP_MASK; PHPDBG_G(bp_count) = 0; } /* }}} */