2013-11-09 22:35:03 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 5 |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1997-2013 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Joe Watkins <joe.watkins@live.co.uk> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
2013-11-09 23:07:04 +00:00
|
|
|
|
2013-11-10 10:44:42 +00:00
|
|
|
#include "phpdbg.h"
|
|
|
|
|
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
|
|
|
|
|
2013-11-10 13:01:46 +00:00
|
|
|
void (*zend_execute_old)(zend_execute_data *execute_data TSRMLS_DC);
|
|
|
|
void (*zend_execute_internal_old)(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
|
|
|
|
|
2013-11-10 11:03:29 +00:00
|
|
|
static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) {
|
2013-11-10 13:01:46 +00:00
|
|
|
pg->exec = NULL;
|
|
|
|
pg->ops = NULL;
|
2013-11-10 11:03:29 +00:00
|
|
|
}
|
2013-11-10 10:44:42 +00:00
|
|
|
|
|
|
|
static PHP_MINIT_FUNCTION(phpdbg) {
|
2013-11-10 13:01:46 +00:00
|
|
|
ZEND_INIT_MODULE_GLOBALS(phpdbg, php_phpdbg_globals_ctor, NULL);
|
|
|
|
|
|
|
|
zend_execute_old = zend_execute_ex;
|
|
|
|
zend_execute_ex = phpdbg_execute_ex;
|
2013-11-10 10:44:42 +00:00
|
|
|
|
2013-11-10 13:01:46 +00:00
|
|
|
return SUCCESS;
|
2013-11-10 10:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void php_phpdbg_destroy_break(void *brake) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHP_RINIT_FUNCTION(phpdbg) {
|
|
|
|
zend_hash_init(&PHPDBG_G(breaks), 8, NULL, php_phpdbg_destroy_break, 0);
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHP_RSHUTDOWN_FUNCTION(phpdbg) {
|
2013-11-10 13:01:46 +00:00
|
|
|
zend_hash_destroy(&PHPDBG_G(breaks));
|
2013-11-10 11:35:59 +00:00
|
|
|
|
2013-11-10 13:01:46 +00:00
|
|
|
if (PHPDBG_G(exec)) {
|
|
|
|
efree(PHPDBG_G(exec));
|
|
|
|
}
|
2013-11-10 11:35:59 +00:00
|
|
|
|
2013-11-10 13:01:46 +00:00
|
|
|
if (PHPDBG_G(ops)) {
|
|
|
|
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
|
|
|
|
efree(PHPDBG_G(ops));
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
2013-11-10 10:44:42 +00:00
|
|
|
}
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 22:47:39 +00:00
|
|
|
static zend_module_entry sapi_phpdbg_module_entry = {
|
2013-11-09 22:35:03 +00:00
|
|
|
STANDARD_MODULE_HEADER,
|
2013-11-09 22:47:39 +00:00
|
|
|
"phpdbg",
|
2013-11-09 22:35:03 +00:00
|
|
|
NULL,
|
2013-11-10 10:44:42 +00:00
|
|
|
PHP_MINIT(phpdbg),
|
2013-11-09 22:35:03 +00:00
|
|
|
NULL,
|
2013-11-10 10:44:42 +00:00
|
|
|
PHP_RINIT(phpdbg),
|
|
|
|
PHP_RSHUTDOWN(phpdbg),
|
2013-11-09 22:35:03 +00:00
|
|
|
NULL,
|
|
|
|
"0.1",
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
static inline int php_sapi_phpdbg_module_startup(sapi_module_struct *module) /* {{{ */
|
|
|
|
{
|
2013-11-09 22:47:39 +00:00
|
|
|
if (php_module_startup(module, &sapi_phpdbg_module_entry, 1) == FAILURE) {
|
2013-11-09 22:35:03 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-11-09 22:47:39 +00:00
|
|
|
/* {{{ sapi_module_struct phpdbg_sapi_module
|
2013-11-09 22:35:03 +00:00
|
|
|
*/
|
2013-11-09 22:47:39 +00:00
|
|
|
static sapi_module_struct phpdbg_sapi_module = {
|
2013-11-09 23:07:04 +00:00
|
|
|
"phpdbg", /* name */
|
|
|
|
"phpdbg", /* pretty name */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 22:47:39 +00:00
|
|
|
php_sapi_phpdbg_module_startup, /* startup */
|
2013-11-09 22:35:03 +00:00
|
|
|
php_module_shutdown_wrapper, /* shutdown */
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
NULL, /* activate */
|
|
|
|
NULL, /* deactivate */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
NULL, /* unbuffered write */
|
|
|
|
NULL, /* flush */
|
|
|
|
NULL, /* get uid */
|
|
|
|
NULL, /* getenv */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
php_error, /* error handler */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
NULL, /* header handler */
|
|
|
|
NULL, /* send headers handler */
|
|
|
|
NULL, /* send header handler */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
NULL, /* read POST data */
|
|
|
|
NULL, /* read Cookies */
|
2013-11-09 22:35:03 +00:00
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
NULL, /* register server variables */
|
|
|
|
NULL, /* Log message */
|
|
|
|
NULL, /* Get request time */
|
|
|
|
NULL, /* Child terminate */
|
2013-11-09 22:35:03 +00:00
|
|
|
STANDARD_SAPI_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
int main(int argc, char **argv) /* {{{ */
|
|
|
|
{
|
2013-11-10 00:34:38 +00:00
|
|
|
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
|
2013-11-09 22:35:03 +00:00
|
|
|
#ifdef ZTS
|
2013-11-09 23:07:04 +00:00
|
|
|
void ***tsrm_ls;
|
|
|
|
tsrm_startup(1, 1, 0, NULL);
|
|
|
|
|
|
|
|
tsrm_ls = ts_resource(0);
|
2013-11-09 22:35:03 +00:00
|
|
|
#endif
|
2013-11-09 23:07:04 +00:00
|
|
|
|
2013-11-09 22:47:39 +00:00
|
|
|
#ifdef PHP_WIN32
|
2013-11-09 23:07:04 +00:00
|
|
|
_fmode = _O_BINARY; /* sets default for file streams to binary */
|
|
|
|
setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
|
|
|
|
setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
|
|
|
|
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
2013-11-09 22:47:39 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
phpdbg->executable_location = argv[0];
|
|
|
|
|
|
|
|
sapi_startup(phpdbg);
|
|
|
|
|
|
|
|
if (phpdbg->startup(phpdbg) == SUCCESS) {
|
|
|
|
zend_activate(TSRMLS_C);
|
2013-11-09 22:35:03 +00:00
|
|
|
|
|
|
|
#ifdef ZEND_SIGNALS
|
2013-11-09 23:07:04 +00:00
|
|
|
zend_try {
|
|
|
|
zend_signals_activate(TSRMLS_C);
|
|
|
|
} zend_end_try();
|
2013-11-09 22:35:03 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
PG(modules_activated) = 0;
|
|
|
|
|
|
|
|
zend_try {
|
|
|
|
zend_activate_modules(TSRMLS_C);
|
|
|
|
} zend_end_try();
|
|
|
|
|
2013-11-10 01:30:32 +00:00
|
|
|
zend_try {
|
2013-11-10 10:44:42 +00:00
|
|
|
phpdbg_interactive(argc, argv TSRMLS_CC);
|
2013-11-10 01:30:32 +00:00
|
|
|
} zend_end_try();
|
2013-11-09 23:07:04 +00:00
|
|
|
|
|
|
|
if (PG(modules_activated)) {
|
|
|
|
zend_try {
|
|
|
|
zend_deactivate_modules(TSRMLS_C);
|
|
|
|
} zend_end_try();
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_deactivate(TSRMLS_C);
|
|
|
|
|
|
|
|
zend_try {
|
|
|
|
zend_post_deactivate_modules(TSRMLS_C);
|
|
|
|
} zend_end_try();
|
|
|
|
|
2013-11-09 22:35:03 +00:00
|
|
|
#ifdef ZEND_SIGNALS
|
2013-11-09 23:07:04 +00:00
|
|
|
zend_try {
|
|
|
|
zend_signal_deactivate(TSRMLS_C);
|
|
|
|
} zend_end_try();
|
2013-11-09 22:35:03 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
php_module_shutdown(TSRMLS_C);
|
|
|
|
|
|
|
|
sapi_shutdown();
|
|
|
|
}
|
|
|
|
|
2013-11-09 22:35:03 +00:00
|
|
|
#ifdef ZTS
|
2013-11-09 23:07:04 +00:00
|
|
|
tsrm_shutdown();
|
2013-11-09 22:35:03 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-09 23:07:04 +00:00
|
|
|
return 0;
|
2013-11-09 22:35:03 +00:00
|
|
|
} /* }}} */
|