2013-11-12 02:19:43 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 5 |
|
|
|
|
+----------------------------------------------------------------------+
|
2014-01-17 22:09:07 +00:00
|
|
|
| Copyright (c) 1997-2014 The PHP Group |
|
2013-11-12 02:19:43 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| 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: Felipe Pena <felipe@php.net> |
|
|
|
|
| Authors: Joe Watkins <joe.watkins@live.co.uk> |
|
2013-12-18 10:02:50 +00:00
|
|
|
| Authors: Bob Weinand <bwoebi@php.net> |
|
2013-11-12 02:19:43 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2013-11-12 13:33:51 +00:00
|
|
|
#include <stdio.h>
|
2013-11-12 02:19:43 +00:00
|
|
|
#include <ctype.h>
|
2013-12-02 13:25:20 +00:00
|
|
|
#include <string.h>
|
2013-11-12 15:17:24 +00:00
|
|
|
#include "zend.h"
|
2013-11-12 22:39:39 +00:00
|
|
|
#include "php.h"
|
|
|
|
#include "spprintf.h"
|
|
|
|
#include "phpdbg.h"
|
2013-11-13 01:35:39 +00:00
|
|
|
#include "phpdbg_opcode.h"
|
2013-11-12 02:19:43 +00:00
|
|
|
#include "phpdbg_utils.h"
|
|
|
|
|
2013-11-17 23:34:11 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include "win32/time.h"
|
2014-02-02 16:35:28 +00:00
|
|
|
#elif defined(HAVE_SYS_IOCTL_H)
|
2014-02-16 16:41:50 +00:00
|
|
|
# include "sys/ioctl.h"
|
2014-06-14 21:48:17 +00:00
|
|
|
# ifndef GWINSZ_IN_SYS_IOCTL
|
|
|
|
# include <termios.h>
|
|
|
|
# endif
|
2013-11-17 23:34:11 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-12 22:39:39 +00:00
|
|
|
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
|
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
/* {{{ color structures */
|
|
|
|
const static phpdbg_color_t colors[] = {
|
2013-11-26 10:02:58 +00:00
|
|
|
PHPDBG_COLOR_D("none", "0;0"),
|
|
|
|
|
|
|
|
PHPDBG_COLOR_D("white", "0;64"),
|
|
|
|
PHPDBG_COLOR_D("white-bold", "1;64"),
|
|
|
|
PHPDBG_COLOR_D("white-underline", "4;64"),
|
|
|
|
PHPDBG_COLOR_D("red", "0;31"),
|
|
|
|
PHPDBG_COLOR_D("red-bold", "1;31"),
|
|
|
|
PHPDBG_COLOR_D("red-underline", "4;31"),
|
|
|
|
PHPDBG_COLOR_D("green", "0;32"),
|
|
|
|
PHPDBG_COLOR_D("green-bold", "1;32"),
|
|
|
|
PHPDBG_COLOR_D("green-underline", "4;32"),
|
|
|
|
PHPDBG_COLOR_D("yellow", "0;33"),
|
|
|
|
PHPDBG_COLOR_D("yellow-bold", "1;33"),
|
|
|
|
PHPDBG_COLOR_D("yellow-underline", "4;33"),
|
|
|
|
PHPDBG_COLOR_D("blue", "0;34"),
|
|
|
|
PHPDBG_COLOR_D("blue-bold", "1;34"),
|
|
|
|
PHPDBG_COLOR_D("blue-underline", "4;34"),
|
|
|
|
PHPDBG_COLOR_D("purple", "0;35"),
|
|
|
|
PHPDBG_COLOR_D("purple-bold", "1;35"),
|
|
|
|
PHPDBG_COLOR_D("purple-underline", "4;35"),
|
|
|
|
PHPDBG_COLOR_D("cyan", "0;36"),
|
|
|
|
PHPDBG_COLOR_D("cyan-bold", "1;36"),
|
|
|
|
PHPDBG_COLOR_D("cyan-underline", "4;36"),
|
|
|
|
PHPDBG_COLOR_D("black", "0;30"),
|
|
|
|
PHPDBG_COLOR_D("black-bold", "1;30"),
|
|
|
|
PHPDBG_COLOR_D("black-underline", "4;30"),
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_COLOR_END
|
|
|
|
}; /* }}} */
|
|
|
|
|
2014-02-23 07:33:48 +00:00
|
|
|
/* {{{ */
|
|
|
|
const static phpdbg_element_t elements[] = {
|
|
|
|
PHPDBG_ELEMENT_D("prompt", PHPDBG_COLOR_PROMPT),
|
|
|
|
PHPDBG_ELEMENT_D("error", PHPDBG_COLOR_ERROR),
|
|
|
|
PHPDBG_ELEMENT_D("notice", PHPDBG_COLOR_NOTICE),
|
|
|
|
PHPDBG_ELEMENT_END
|
|
|
|
}; /* }}} */
|
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */
|
2013-11-12 02:19:43 +00:00
|
|
|
{
|
2013-11-26 10:02:58 +00:00
|
|
|
if (!str)
|
|
|
|
return 0;
|
2013-11-14 13:04:59 +00:00
|
|
|
|
2013-11-12 02:19:43 +00:00
|
|
|
for (; *str; str++) {
|
2013-11-25 19:33:52 +00:00
|
|
|
if (isspace(*str) || *str == '-') {
|
2013-11-12 02:19:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return isdigit(*str);
|
|
|
|
}
|
2013-11-12 02:28:52 +00:00
|
|
|
return 0;
|
2013-11-12 02:19:43 +00:00
|
|
|
} /* }}} */
|
2013-11-12 02:50:15 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API int phpdbg_is_empty(const char *str) /* {{{ */
|
2013-11-12 02:50:15 +00:00
|
|
|
{
|
2013-11-26 10:02:58 +00:00
|
|
|
if (!str)
|
|
|
|
return 1;
|
2013-11-19 21:26:40 +00:00
|
|
|
|
2013-11-12 02:50:15 +00:00
|
|
|
for (; *str; str++) {
|
|
|
|
if (isspace(*str)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} /* }}} */
|
2013-11-12 12:58:19 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API int phpdbg_is_addr(const char *str) /* {{{ */
|
2013-11-12 12:58:19 +00:00
|
|
|
{
|
|
|
|
return str[0] && str[1] && memcmp(str, "0x", 2) == 0;
|
|
|
|
} /* }}} */
|
2013-11-12 13:33:51 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, char **method) /* {{{ */
|
2013-11-12 13:33:51 +00:00
|
|
|
{
|
2013-11-16 14:55:53 +00:00
|
|
|
char *sep = NULL;
|
|
|
|
|
2013-12-07 14:35:35 +00:00
|
|
|
if (strstr(str, "#") != NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-11-26 10:02:58 +00:00
|
|
|
if (strstr(str, " ") != NULL)
|
|
|
|
return 0;
|
2013-11-19 21:26:40 +00:00
|
|
|
|
2013-11-16 14:55:53 +00:00
|
|
|
sep = strstr(str, "::");
|
2013-11-12 13:33:51 +00:00
|
|
|
|
2013-11-12 13:39:02 +00:00
|
|
|
if (!sep || sep == str || sep+2 == str+len-1) {
|
2013-11-12 13:33:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-13 19:32:21 +00:00
|
|
|
if (class != NULL) {
|
2013-12-18 17:00:26 +00:00
|
|
|
|
|
|
|
if (str[0] == '\\') {
|
|
|
|
str++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
2013-11-26 10:02:58 +00:00
|
|
|
*class = estrndup(str, sep - str);
|
|
|
|
(*class)[sep - str] = 0;
|
2013-11-13 19:32:21 +00:00
|
|
|
}
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-11-13 19:32:21 +00:00
|
|
|
if (method != NULL) {
|
2013-11-26 10:02:58 +00:00
|
|
|
*method = estrndup(sep+2, str + len - (sep + 2));
|
2013-11-13 19:32:21 +00:00
|
|
|
}
|
2013-11-12 13:33:51 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
} /* }}} */
|
2013-11-12 22:39:39 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */
|
2013-11-13 23:13:41 +00:00
|
|
|
{
|
2013-11-13 23:36:02 +00:00
|
|
|
char resolved_name[MAXPATHLEN];
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-11-13 23:36:02 +00:00
|
|
|
if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
|
|
|
|
return NULL;
|
2013-11-13 23:13:41 +00:00
|
|
|
}
|
2013-11-13 23:36:02 +00:00
|
|
|
|
|
|
|
return estrdup(resolved_name);
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
|
2013-11-13 23:36:02 +00:00
|
|
|
{
|
2013-11-14 00:29:44 +00:00
|
|
|
const char *file = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
|
|
|
|
if (memcmp(file, "[no active file]", sizeof("[no active file]")) == 0) {
|
|
|
|
return PHPDBG_G(exec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
2013-11-13 23:36:02 +00:00
|
|
|
} /* }}} */
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-12-08 19:37:35 +00:00
|
|
|
PHPDBG_API const zend_function *phpdbg_get_function(const char *fname, const char *cname TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
zend_function *func = NULL;
|
|
|
|
size_t fname_len = strlen(fname);
|
|
|
|
char *lcname = zend_str_tolower_dup(fname, fname_len);
|
|
|
|
|
|
|
|
if (cname) {
|
|
|
|
zend_class_entry **ce;
|
|
|
|
size_t cname_len = strlen(cname);
|
|
|
|
char *lc_cname = zend_str_tolower_dup(cname, cname_len);
|
|
|
|
int ret = zend_lookup_class(lc_cname, cname_len, &ce TSRMLS_CC);
|
|
|
|
|
|
|
|
efree(lc_cname);
|
|
|
|
|
|
|
|
if (ret == SUCCESS) {
|
|
|
|
zend_hash_find(&(*ce)->function_table, lcname, fname_len+1,
|
|
|
|
(void**)&func);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zend_hash_find(EG(function_table), lcname, fname_len+1,
|
|
|
|
(void**)&func);
|
|
|
|
}
|
|
|
|
|
|
|
|
efree(lcname);
|
|
|
|
return func;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
PHPDBG_API char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{{ */
|
2013-11-19 21:26:40 +00:00
|
|
|
{
|
|
|
|
const char *p = str;
|
|
|
|
char *new = NULL;
|
|
|
|
|
|
|
|
while (p && isspace(*p)) {
|
|
|
|
++p;
|
|
|
|
--len;
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:35:45 +00:00
|
|
|
while (*p && isspace(*(p + len -1))) {
|
2013-11-19 21:26:40 +00:00
|
|
|
--len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0) {
|
2013-11-19 21:35:45 +00:00
|
|
|
new = estrndup("", sizeof(""));
|
2013-11-19 21:26:40 +00:00
|
|
|
*new_len = 0;
|
2013-11-19 21:35:45 +00:00
|
|
|
} else {
|
|
|
|
new = estrndup(p, len);
|
|
|
|
*(new + len) = '\0';
|
2013-11-19 21:26:40 +00:00
|
|
|
|
2013-11-19 21:35:45 +00:00
|
|
|
if (new_len) {
|
|
|
|
*new_len = len;
|
|
|
|
}
|
2013-11-19 21:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-09-28 00:57:12 +00:00
|
|
|
PHPDBG_API int phpdbg_print(int type TSRMLS_DC, int fd, const char *format, ...) { /* {{{ */
|
2013-11-26 10:02:58 +00:00
|
|
|
int rc = 0;
|
2014-09-28 00:57:12 +00:00
|
|
|
char *buffer = NULL, *outbuf = NULL;
|
2013-11-13 05:36:01 +00:00
|
|
|
va_list args;
|
2013-11-12 22:39:39 +00:00
|
|
|
|
2013-11-13 01:44:59 +00:00
|
|
|
if (format != NULL && strlen(format) > 0L) {
|
2013-11-26 10:02:58 +00:00
|
|
|
va_start(args, format);
|
|
|
|
vspprintf(&buffer, 0, format, args);
|
|
|
|
va_end(args);
|
2013-11-13 01:44:59 +00:00
|
|
|
}
|
2013-11-12 22:39:39 +00:00
|
|
|
|
2013-11-26 10:02:58 +00:00
|
|
|
/* TODO(anyone) colours */
|
2013-11-12 23:10:53 +00:00
|
|
|
|
2013-11-12 22:39:39 +00:00
|
|
|
switch (type) {
|
2013-11-13 21:15:45 +00:00
|
|
|
case P_ERROR:
|
2014-09-24 22:55:17 +00:00
|
|
|
if (!PHPDBG_G(last_was_newline)) {
|
2014-09-28 00:57:12 +00:00
|
|
|
write(fd, "\n", 1);
|
2014-09-24 22:55:17 +00:00
|
|
|
PHPDBG_G(last_was_newline) = 1;
|
|
|
|
}
|
2013-11-24 19:34:18 +00:00
|
|
|
if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "\033[%sm[%s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_ERROR]->code, buffer);
|
2013-11-24 19:34:18 +00:00
|
|
|
} else {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "[%s]\n", buffer);
|
2013-11-24 19:34:18 +00:00
|
|
|
}
|
2013-11-12 22:39:39 +00:00
|
|
|
break;
|
|
|
|
|
2013-11-13 21:15:45 +00:00
|
|
|
case P_NOTICE:
|
2014-09-24 22:55:17 +00:00
|
|
|
if (!PHPDBG_G(last_was_newline)) {
|
2014-09-28 00:57:12 +00:00
|
|
|
write(fd, "\n", 1);
|
2014-09-24 22:55:17 +00:00
|
|
|
PHPDBG_G(last_was_newline) = 1;
|
|
|
|
}
|
2013-11-24 19:34:18 +00:00
|
|
|
if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "\033[%sm[%s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_NOTICE]->code, buffer);
|
2013-11-24 19:34:18 +00:00
|
|
|
} else {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "[%s]\n", buffer);
|
2013-11-24 19:34:18 +00:00
|
|
|
}
|
2013-11-12 23:10:53 +00:00
|
|
|
break;
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-11-13 21:15:45 +00:00
|
|
|
case P_WRITELN: {
|
2013-11-26 10:02:58 +00:00
|
|
|
if (buffer) {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "%s\n", buffer);
|
2013-11-12 23:31:46 +00:00
|
|
|
} else {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = 1;
|
|
|
|
outbuf = estrdup("\n");
|
2013-11-12 23:31:46 +00:00
|
|
|
}
|
2014-09-24 22:55:17 +00:00
|
|
|
PHPDBG_G(last_was_newline) = 1;
|
2013-11-12 23:31:46 +00:00
|
|
|
} break;
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-11-26 10:02:58 +00:00
|
|
|
case P_WRITE:
|
|
|
|
if (buffer) {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "%s", buffer);
|
2014-09-24 22:55:17 +00:00
|
|
|
PHPDBG_G(last_was_newline) = buffer[strlen(buffer) - 1] == '\n';
|
2013-11-26 10:02:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-11-19 21:26:40 +00:00
|
|
|
|
2013-11-14 21:10:44 +00:00
|
|
|
/* no formatting on logging output */
|
2013-11-26 10:02:58 +00:00
|
|
|
case P_LOG:
|
|
|
|
if (buffer) {
|
|
|
|
struct timeval tp;
|
|
|
|
if (gettimeofday(&tp, NULL) == SUCCESS) {
|
2014-09-28 00:57:12 +00:00
|
|
|
rc = spprintf(&outbuf, 0, "[%ld %.8F]: %s\n", tp.tv_sec, tp.tv_usec / 1000000.00, buffer);
|
2013-11-26 10:02:58 +00:00
|
|
|
} else {
|
|
|
|
rc = FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-11-12 22:39:39 +00:00
|
|
|
}
|
2013-11-12 22:55:39 +00:00
|
|
|
|
2014-09-28 00:57:12 +00:00
|
|
|
if (outbuf) {
|
|
|
|
rc = write(fd, outbuf, rc);
|
|
|
|
efree(outbuf);
|
|
|
|
}
|
|
|
|
|
2013-11-12 22:55:39 +00:00
|
|
|
if (buffer) {
|
|
|
|
efree(buffer);
|
|
|
|
}
|
2013-11-13 23:13:41 +00:00
|
|
|
|
2013-11-13 08:05:26 +00:00
|
|
|
return rc;
|
2013-11-12 22:39:39 +00:00
|
|
|
} /* }}} */
|
2013-11-24 17:50:22 +00:00
|
|
|
|
2014-09-28 00:57:12 +00:00
|
|
|
PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...) { /* {{{ */
|
2013-11-30 14:34:16 +00:00
|
|
|
int rc = 0;
|
2013-12-08 19:37:35 +00:00
|
|
|
|
2013-11-30 14:34:16 +00:00
|
|
|
va_list args;
|
|
|
|
struct timeval tp;
|
2013-12-08 19:37:35 +00:00
|
|
|
|
2013-11-30 14:34:16 +00:00
|
|
|
va_start(args, fmt);
|
2013-12-01 17:00:28 +00:00
|
|
|
if (gettimeofday(&tp, NULL) == SUCCESS) {
|
2013-11-30 14:34:16 +00:00
|
|
|
char friendly[100];
|
2014-09-28 00:57:12 +00:00
|
|
|
char *format = NULL, *buffer = NULL, *outbuf = NULL;
|
2013-12-25 18:50:25 +00:00
|
|
|
const time_t tt = tp.tv_sec;
|
2013-12-08 19:37:35 +00:00
|
|
|
|
2013-12-25 18:50:25 +00:00
|
|
|
strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tt));
|
2014-09-28 00:57:12 +00:00
|
|
|
spprintf(&buffer, 0, friendly, tp.tv_usec/1000);
|
|
|
|
spprintf(&format, 0, "[%s]: %s\n", buffer, fmt);
|
|
|
|
rc = vspprintf(&outbuf, 0, format, args);
|
2013-11-30 17:19:01 +00:00
|
|
|
|
2014-09-28 00:57:12 +00:00
|
|
|
if (outbuf) {
|
|
|
|
rc = write(fd, outbuf, rc);
|
|
|
|
efree(outbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
efree(format);
|
|
|
|
efree(buffer);
|
2013-11-30 14:34:16 +00:00
|
|
|
}
|
|
|
|
va_end(args);
|
2013-12-08 19:37:35 +00:00
|
|
|
|
2013-11-30 14:34:16 +00:00
|
|
|
return rc;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-11-24 20:14:33 +00:00
|
|
|
PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */
|
2013-11-24 17:50:22 +00:00
|
|
|
{
|
|
|
|
const phpdbg_color_t *color = colors;
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
while (color && color->name) {
|
|
|
|
if (name_length == color->name_length &&
|
|
|
|
memcmp(name, color->name, name_length) == SUCCESS) {
|
2013-11-24 19:34:18 +00:00
|
|
|
phpdbg_debug(
|
|
|
|
"phpdbg_get_color(%s, %lu): %s", name, name_length, color->code);
|
2013-11-24 17:50:22 +00:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
++color;
|
|
|
|
}
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
phpdbg_debug(
|
|
|
|
"phpdbg_get_color(%s, %lu): failed", name, name_length);
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 17:50:22 +00:00
|
|
|
return NULL;
|
|
|
|
} /* }}} */
|
2013-11-24 19:34:18 +00:00
|
|
|
|
|
|
|
PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
PHPDBG_G(colors)[element] = color;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
const phpdbg_color_t *color = phpdbg_get_color(name, name_length TSRMLS_CC);
|
2013-11-24 20:14:33 +00:00
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
if (color) {
|
|
|
|
phpdbg_set_color(element, color TSRMLS_CC);
|
|
|
|
} else PHPDBG_G(colors)[element] = colors;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-11-24 20:16:46 +00:00
|
|
|
PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D) /* {{{ */
|
|
|
|
{
|
|
|
|
return colors;
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-02-24 09:26:03 +00:00
|
|
|
PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC) {
|
2014-02-23 07:33:48 +00:00
|
|
|
const phpdbg_element_t *element = elements;
|
|
|
|
|
|
|
|
while (element && element->name) {
|
|
|
|
if (len == element->name_length) {
|
|
|
|
if (strncasecmp(name, element->name, len) == SUCCESS) {
|
|
|
|
return element->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
element++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PHPDBG_COLOR_INVALID;
|
|
|
|
}
|
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
/* free formatted prompt */
|
|
|
|
if (PHPDBG_G(prompt)[1]) {
|
|
|
|
free(PHPDBG_G(prompt)[1]);
|
|
|
|
PHPDBG_G(prompt)[1] = NULL;
|
|
|
|
}
|
|
|
|
/* free old prompt */
|
|
|
|
if (PHPDBG_G(prompt)[0]) {
|
|
|
|
free(PHPDBG_G(prompt)[0]);
|
|
|
|
PHPDBG_G(prompt)[0] = NULL;
|
|
|
|
}
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
/* copy new prompt */
|
|
|
|
PHPDBG_G(prompt)[0] = strdup(prompt);
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */
|
2013-12-08 19:37:35 +00:00
|
|
|
{
|
2013-11-24 19:34:18 +00:00
|
|
|
/* find cached prompt */
|
|
|
|
if (PHPDBG_G(prompt)[1]) {
|
|
|
|
return PHPDBG_G(prompt)[1];
|
|
|
|
}
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
/* create cached prompt */
|
2014-06-29 09:26:03 +00:00
|
|
|
#ifndef HAVE_LIBEDIT
|
|
|
|
/* TODO: libedit doesn't seems to support coloured prompt */
|
2013-11-24 19:34:18 +00:00
|
|
|
if ((PHPDBG_G(flags) & PHPDBG_IS_COLOURED)) {
|
2013-11-24 20:11:54 +00:00
|
|
|
asprintf(
|
2013-11-24 19:34:18 +00:00
|
|
|
&PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
|
|
|
|
PHPDBG_G(colors)[PHPDBG_COLOR_PROMPT]->code,
|
|
|
|
PHPDBG_G(prompt)[0]);
|
2014-06-29 09:26:03 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2013-11-24 20:11:54 +00:00
|
|
|
asprintf(
|
2013-11-24 19:34:18 +00:00
|
|
|
&PHPDBG_G(prompt)[1], "%s ",
|
|
|
|
PHPDBG_G(prompt)[0]);
|
|
|
|
}
|
2013-11-24 20:11:54 +00:00
|
|
|
|
2013-11-24 19:34:18 +00:00
|
|
|
return PHPDBG_G(prompt)[1];
|
|
|
|
} /* }}} */
|
2013-12-19 16:05:38 +00:00
|
|
|
|
|
|
|
int phpdbg_rebuild_symtable(TSRMLS_D) {
|
|
|
|
if (!EG(active_op_array)) {
|
|
|
|
phpdbg_error("No active op array!");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EG(active_symbol_table)) {
|
|
|
|
zend_rebuild_symbol_table(TSRMLS_C);
|
|
|
|
|
|
|
|
if (!EG(active_symbol_table)) {
|
|
|
|
phpdbg_error("No active symbol table!");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2014-03-23 22:32:13 +00:00
|
|
|
|
2014-02-02 16:35:28 +00:00
|
|
|
PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D) /* {{{ */
|
|
|
|
{
|
|
|
|
int columns;
|
2014-02-16 16:41:50 +00:00
|
|
|
#ifdef _WIN32
|
2014-02-02 16:35:28 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
2014-06-14 21:48:17 +00:00
|
|
|
#elif defined(HAVE_SYS_IOCTL_H) && defined (TIOCGWINSZ)
|
2014-02-02 16:35:28 +00:00
|
|
|
struct winsize w;
|
|
|
|
|
2014-06-12 21:13:50 +00:00
|
|
|
columns = ioctl(fileno(stdout), TIOCGWINSZ, &w) == 0 ? w.ws_col : 80;
|
2014-02-02 16:35:28 +00:00
|
|
|
#else
|
2014-06-12 21:13:50 +00:00
|
|
|
columns = 80;
|
2014-02-02 16:35:28 +00:00
|
|
|
#endif
|
|
|
|
return columns;
|
|
|
|
} /* }}} */
|
2014-09-28 00:57:12 +00:00
|
|
|
|
|
|
|
PHPDBG_API void phpdbg_set_async_io(int fd) {
|
|
|
|
#ifndef _WIN32
|
|
|
|
int flags;
|
|
|
|
fcntl(STDIN_FILENO, F_SETOWN, getpid());
|
|
|
|
flags = fcntl(STDIN_FILENO, F_GETFL);
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, flags | FASYNC);
|
|
|
|
#endif
|
|
|
|
}
|
2014-10-02 23:29:41 +00:00
|
|
|
|
|
|
|
int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry ***ce TSRMLS_DC) {
|
|
|
|
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
|
|
|
|
char *lc_name, *lc_free;
|
|
|
|
int lc_length, ret = FAILURE;
|
|
|
|
|
|
|
|
if (name == NULL || !name_length) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lc_free = lc_name = emalloc(name_length + 1);
|
|
|
|
zend_str_tolower_copy(lc_name, name, name_length);
|
|
|
|
lc_length = name_length + 1;
|
|
|
|
|
|
|
|
if (lc_name[0] == '\\') {
|
|
|
|
lc_name += 1;
|
|
|
|
lc_length -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
phpdbg_try_access {
|
|
|
|
ret = zend_hash_find(EG(class_table), lc_name, lc_length, (void **) &ce);
|
|
|
|
} phpdbg_catch_access {
|
|
|
|
phpdbg_error("Could not fetch class %.*s, invalid data source", name_length, name);
|
|
|
|
} phpdbg_end_try_access();
|
|
|
|
|
|
|
|
efree(lc_free);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return zend_lookup_class(name, name_length, ce TSRMLS_CC);
|
|
|
|
}
|
|
|
|
}
|