if (PHPDBG_G(exec)) {
efree(PHPDBG_G(exec));
+ PHPDBG_G(exec) = NULL;
}
if (PHPDBG_G(ops)) {
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
efree(PHPDBG_G(ops));
+ PHPDBG_G(ops) = NULL;
}
+
return SUCCESS;
} /* }}} */
INI_DEFAULT("display_errors", "1");
} /* }}} */
+static jmp_buf phpdbg_main;
+
int main(int argc, char **argv) /* {{{ */
{
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
- char *ini_entries = NULL;
- int ini_entries_len = 0;
- char *exec = NULL;
- size_t exec_len = 0L;
- zend_ulong flags = PHPDBG_DEFAULT_FLAGS;
- char *php_optarg = NULL;
- int php_optind = 1;
+ char *ini_entries;
+ int ini_entries_len;
+ char *exec;
+ size_t exec_len;
+ zend_ulong flags;
+ char *php_optarg;
+ int php_optind;
int opt;
-
+ long cleaning = 0;
+
#ifdef ZTS
void ***tsrm_ls;
#endif
tsrm_ls = ts_resource(0);
#endif
+phpdbg_main:
+ ini_entries = NULL;
+ ini_entries_len = 0;
+ exec = NULL;
+ exec_len = 0;
+ flags = PHPDBG_DEFAULT_FLAGS;
+ php_optarg = NULL;
+ php_optind = 1;
+ opt = 0;
+
while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (opt) {
case 'n':
case 'e': /* set execution context */
exec_len = strlen(php_optarg);
if (exec_len) {
- exec = phpdbg_resolve_path(php_optarg TSRMLS_CC);
+ exec = strdup(php_optarg);
}
break;
PG(modules_activated) = 0;
if (exec) { /* set execution context */
- PHPDBG_G(exec) = exec;
- PHPDBG_G(exec_len) = exec_len;
+ PHPDBG_G(exec) = phpdbg_resolve_path(
+ exec TSRMLS_CC);
+ PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
free(exec);
}
zend_activate_auto_globals(TSRMLS_C);
} zend_end_try();
- /* print blurb */
- phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s",
- PHPDBG_VERSION);
- phpdbg_writeln("To get help using phpdbg type \"help\" and press enter");
- phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
-
+ /* print blurb */
+ phpdbg_welcome(cleaning TSRMLS_CC);
+ /* phpdbg main() */
do {
zend_try {
phpdbg_interactive(TSRMLS_C);
} zend_catch {
-
+ if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) {
+ cleaning = 1;
+ break;
+ } else cleaning = 0;
} zend_end_try();
} while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
sapi_shutdown();
}
+
+ if (cleaning) {
+ goto phpdbg_main;
+ }
#ifdef ZTS
- tsrm_shutdown();
+ /* bugggy */
+ //tsrm_shutdown();
#endif
return 0;
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */
+{
+ /* print blurb */
+ if (!cleaning) {
+ phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s",
+ PHPDBG_VERSION);
+ phpdbg_writeln("To get help using phpdbg type \"help\" and press enter");
+ phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
+ } else {
+ phpdbg_notice("Clean Execution Environment");
+
+ phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files)));
+ }
+} /* }}} */
+
static PHPDBG_COMMAND(exec) /* {{{ */
{
if (expr_len == 0) {
static PHPDBG_COMMAND(quit) /* {{{ */
{
- PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
-
- zend_bailout();
+ /* don't allow this to loop, ever ... */
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+ zend_bailout();
+ }
return SUCCESS;
} /* }}} */
-static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC) /* {{{ */
-{
- return (c->flags & CONST_PERSISTENT) ? 0 : 1;
-} /* }}} */
-
-static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
-{
- return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
-} /* }}} */
-
-static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
-{
- return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
-} /* }}} */
-
static PHPDBG_COMMAND(clean) /* {{{ */
{
if (EG(in_execution)) {
phpdbg_clean(1 TSRMLS_CC);
- phpdbg_notice("Clean Execution Environment");
-
- phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files)));
-
return SUCCESS;
} /* }}} */
void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
{
- zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
-
/* this is implicitly required */
if (PHPDBG_G(ops)) {
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
PHPDBG_G(ops) = NULL;
}
- if (full) {
- zend_hash_reverse_apply(EG(function_table),
- (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
- zend_hash_reverse_apply(EG(class_table),
- (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
- zend_hash_reverse_apply(EG(zend_constants),
- (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
- zend_hash_clean(&EG(included_files));
+ if (full)
+ {
+ PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
+
+ zend_bailout();
}
} /* }}} */