return SUCCESS;
} /* }}} */
-/* {{{ proto mixed phpdbg_exec(string context)
+/* {{{ proto mixed phpdbg_exec(string context)
Attempt to set the execution context for phpdbg
If the execution context was set previously it is returned
- If the execution context was not set previously boolean true is returned
+ If the execution context was not set previously boolean true is returned
If the request to set the context fails, boolean false is returned, and an E_WARNING raised */
-static PHP_FUNCTION(phpdbg_exec)
+static PHP_FUNCTION(phpdbg_exec)
{
char *exec = NULL;
zend_ulong exec_len = 0L;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) {
return;
}
-
+
{
struct stat sb;
zend_bool result = 1;
-
+
if (VCWD_STAT(exec, &sb) != FAILURE) {
if (sb.st_mode & (S_IFREG|S_IFLNK)) {
if (PHPDBG_G(exec)) {
efree(PHPDBG_G(exec));
result = 0;
}
-
+
PHPDBG_G(exec) = estrndup(exec, exec_len);
PHPDBG_G(exec_len) = exec_len;
-
- if (result)
+
+ if (result)
ZVAL_BOOL(return_value, 1);
} else {
zend_error(
if (php_module_startup(module, &sapi_phpdbg_module_entry, 1) == FAILURE) {
return FAILURE;
}
-
+
phpdbg_booted=1;
-
+
return SUCCESS;
} /* }}} */
int phpdbg_open_socket(const char *interface, short port) /* {{{ */
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
-
+
switch (fd) {
case -1:
return -1;
-
+
default: {
int reuse = 1;
case -1:
close(fd);
return -2;
-
+
default: {
struct sockaddr_in address;
-
+
memset(&address, 0, sizeof(address));
-
+
address.sin_port = htons(port);
address.sin_family = AF_INET;
-
+
if ((*interface == '*')) {
- address.sin_addr.s_addr = htonl(INADDR_ANY);
+ address.sin_addr.s_addr = htonl(INADDR_ANY);
} else if (!inet_pton(AF_INET, interface, &address.sin_addr)) {
close(fd);
return -3;
}
-
+
switch (bind(fd, (struct sockaddr *)&address, sizeof(address))) {
case -1:
close(fd);
return -4;
-
+
default: {
listen(fd, 5);
}
}
}
}
-
+
return fd;
} /* }}} */
static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
-{
+{
if ((*socket)[0] >= 0) {
shutdown(
(*socket)[0], SHUT_RDWR);
close((*socket)[0]);
}
-
+
if (streams[0]) {
fclose(streams[0]);
}
-
+
if ((*socket)[1] >= 0) {
shutdown(
(*socket)[1], SHUT_RDWR);
close((*socket)[1]);
}
-
+
if (streams[1]) {
fclose(streams[1]);
}
dup2((*socket)[0], fileno(stdin));
dup2((*socket)[1], fileno(stdout));
-
+
setbuf(stdout, NULL);
streams[0] = fdopen((*socket)[0], "r");
streams[1] = fdopen((*socket)[1], "w");
-
+
return SUCCESS;
} /* }}} */
#endif
tsrm_startup(1, 1, 0, NULL);
tsrm_ls = ts_resource(0);
-#endif
+#endif
- phpdbg_setup_watchpoints();
+ phpdbg_setup_watchpoints(TSRMLS_C);
phpdbg_main:
if (!cleaning) {
run = 0;
step = 0;
sapi_name = NULL;
-
-
+
+
while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (opt) {
case 'r':
ini_entries_len += len + sizeof("=1\n\0") - 2;
}
} break;
-
+
case 'z':
zend_extensions_len++;
if (zend_extensions) {
exec = strdup(php_optarg);
}
} break;
-
+
case 'S': { /* set SAPI name */
if (sapi_name) {
free(sapi_name);
if (init_file) {
free(init_file);
}
-
+
init_file_len = strlen(php_optarg);
if (init_file_len) {
init_file = strdup(php_optarg);
#ifndef _WIN32
/* if you pass a listen port, we will accept input on listen port */
/* and write output to listen port * 2 */
-
+
case 'l': { /* set listen ports */
if (sscanf(php_optarg, "%d/%d", &listen[0], &listen[1]) != 2) {
if (sscanf(php_optarg, "%d", &listen[0]) != 1) {
}
}
} break;
-
+
case 'a': { /* set bind address */
free(address);
if (!php_optarg) {
if (sapi_name) {
phpdbg->name = sapi_name;
}
-
+
phpdbg->ini_defaults = phpdbg_ini_defaults;
phpdbg->phpinfo_as_text = 1;
phpdbg->php_ini_ignore_cwd = 1;
memcpy(ini_entries, phpdbg_ini_hardcoded, sizeof(phpdbg_ini_hardcoded));
}
ini_entries_len += sizeof(phpdbg_ini_hardcoded) - 2;
-
+
if (zend_extensions_len) {
zend_ulong zend_extension = 0L;
-
+
while (zend_extension < zend_extensions_len) {
const char *ze = zend_extensions[zend_extension];
size_t ze_len = strlen(ze);
-
+
ini_entries = realloc(
ini_entries, ini_entries_len + (ze_len + (sizeof("zend_extension=\n"))));
memcpy(&ini_entries[ini_entries_len], "zend_extension=", (sizeof("zend_extension=\n")-1));
free(zend_extensions[zend_extension]);
zend_extension++;
}
-
+
free(zend_extensions);
}
phpdbg->ini_entries = ini_entries;
-
+
if (phpdbg->startup(phpdbg) == SUCCESS) {
-
+
zend_activate(TSRMLS_C);
#ifdef ZEND_SIGNALS
#endif
PG(modules_activated) = 0;
-
+
/* set flags from command line */
PHPDBG_G(flags) = flags;
PHPDBG_G(io)[PHPDBG_STDIN] = stdin;
PHPDBG_G(io)[PHPDBG_STDOUT] = stdout;
PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
-
+
if (exec) { /* set execution context */
PHPDBG_G(exec) = phpdbg_resolve_path(
exec TSRMLS_CC);
/* renegociate connections */
phpdbg_open_sockets(
address, listen, &server, &socket, streams);
-
+
/* set streams */
if (streams[0] && streams[1]) {
PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING;
}
-
+
/* this must be forced */
CG(unclean_shutdown) = 0;
}
}
} zend_end_try();
} while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
-
+
/* this must be forced */
CG(unclean_shutdown) = 0;
-
+
phpdbg_out:
#ifndef _WIN32
if (PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED) {
goto phpdbg_interact;
}
#endif
-
+
if (ini_entries) {
free(ini_entries);
}
#ifndef _WIN32
if (address) {
- free(address);
+ free(address);
}
#endif
if (sapi_name) {
free(sapi_name);
}
-
+
free(bp_tmp_file);
return 0;
return (size_t)phpdbg_get_page_boundary(addr + size - 1) - (size_t)phpdbg_get_page_boundary(addr) + phpdbg_pagesize;
}
-phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *watch_addr) {
+phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *watch_addr TSRMLS_DC) {
phpdbg_watchpoint_t *watch;
phpdbg_btree *branch = PHPDBG_G(watchpoint_tree);
int i = sizeof(void *) * 8 - 1, last_superior_i = -1;
addr = info->si_addr;
- watch = phpdbg_check_for_watchpoint(addr);
+ watch = phpdbg_check_for_watchpoint(addr TSRMLS_CC);
if (watch == NULL) {
return FAILURE;
(*branch)->watchpoint = watch;
}
-void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch) {
+void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch TSRMLS_DC) {
int m;
watch->addr.ptr = addr;
}
}
-void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch) {
- phpdbg_create_addr_watchpoint(zv, sizeof(zval), watch);
+void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch TSRMLS_DC) {
+ phpdbg_create_addr_watchpoint(zv, sizeof(zval), watch TSRMLS_CC);
watch->type = WATCH_ON_ZVAL;
}
if (zend_hash_find(EG(current_execute_data)->symbol_table, name, len + 1, (void **)&zv) == SUCCESS) {
zend_hash_add(&PHPDBG_G(watchpoints), name, len, &watch, sizeof(phpdbg_watchpoint_t *), NULL);
phpdbg_store_watchpoint(watch TSRMLS_CC);
- phpdbg_create_zval_watchpoint(*zv, watch);
+ phpdbg_create_zval_watchpoint(*zv, watch TSRMLS_CC);
return SUCCESS;
}