From: Bob Weinand Date: Wed, 11 Dec 2013 20:31:22 +0000 (+0100) Subject: Committed the damned new files X-Git-Tag: php-5.6.0beta2~1^2~37^2~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e5d78192eb4727dff34aba9275cd4dc9230f38c;p=php Committed the damned new files --- diff --git a/phpdbg_watch.c b/phpdbg_watch.c new file mode 100644 index 0000000000..e54431f3e0 --- /dev/null +++ b/phpdbg_watch.c @@ -0,0 +1,69 @@ +#include "zend.h" +#include "phpdbg.h" +#include "phpdbg_watch.h" +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +long phpdbg_pagesize; + +void phpdbg_setup_watchpoints() { +#ifdef _SC_PAGE_SIZE + phpdbg_pagesize = sysconf(_SC_PAGE_SIZE); +#endif +#ifdef _SC_PAGESIZE + phpdbg_pagesize = sysconf(_SC_PAGESIZE); +#endif +#ifdef _SC_NUTC_OS_PAGESIZE + phpdbg_pagesize = sysconf(_SC_NUTC_OS_PAGESIZE); +#endif +} + +int phpdbg_check_for_watchpoint(void *addr) { + return FAILURE; +} + +int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC) { + printf("Text"); + return FAILURE; +} + +void phpdbg_create_addr_watchpoint(void *addr, size_t size) { + int m; + + /* pagesize is assumed to be in the range of 2^x */ + m= mprotect((void *)((unsigned long)addr & ~(phpdbg_pagesize - 1)), ((size - 1) & ~(phpdbg_pagesize - 1)) | phpdbg_pagesize, PROT_NONE | PROT_READ); + + printf("\n!!!!!\n%d\n!!!!!\n", m); +} + +void phpdbg_create_zval_watchpoint(zval *zv) { + phpdbg_create_addr_watchpoint(zv, sizeof(zval)); +} + +int phpdbg_create_var_watchpoint(char *name, size_t len TSRMLS_DC) { + zval *zv; + + if (!EG(active_op_array)) { + phpdbg_error("No active op array!"); + return SUCCESS; + } + + if (!EG(active_symbol_table)) { + zend_rebuild_symbol_table(TSRMLS_C); + + if (!EG(active_symbol_table)) { + phpdbg_error("No active symbol table!"); + return SUCCESS; + } + } + + /* Lookup current symbol table */ + if (zend_hash_find(EG(current_execute_data)->symbol_table, name, len + 1, (void **)&zv) == SUCCESS) { + phpdbg_create_zval_watchpoint(zv); + return SUCCESS; + } + + return FAILURE; +} diff --git a/phpdbg_watch.h b/phpdbg_watch.h new file mode 100644 index 0000000000..3d142070b3 --- /dev/null +++ b/phpdbg_watch.h @@ -0,0 +1,43 @@ +#ifndef PHPDBG_WATCH_H +#define PHPDBG_WATCH_H + +#include "TSRM.h" +#include "phpdbg_cmd.h" + +#define PHPDBG_WATCH(name) PHPDBG_COMMAND(watch_##name) + +/** +* Printer Forward Declarations +*/ +/*PHPDBG_WATCH();*/ + + +/* Watchpoint functions/typedefs */ + +typedef enum { + WATCH_ON_ZVAL, + WATCH_ON_HASHTABLE, + WATCH_ON_PTR +} phpdbg_watchtype; + +typedef struct _phpdbg_watchpoint_t phpdbg_watchpoint_t; + +struct _phpdbg_watchpoint_t { + phpdbg_watchpoint_t *parent; + char *str; + union { + zval *zv; + HashTable *ht; + void *ptr; + } addr; + int size; + phpdbg_watchtype type; +}; + +void phpdbg_setup_watchpoints(); + +int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC); + +int phpdbg_create_var_watchpoint(char *name, size_t len TSRMLS_DC); + +#endif