1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Felipe Pena <felipe@php.net> |
14 | Authors: Joe Watkins <joe.watkins@live.co.uk> |
15 | Authors: Bob Weinand <bwoebi@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19 #ifndef PHPDBG_UTILS_H
20 #define PHPDBG_UTILS_H
21
22 /**
23 * Input scan functions
24 */
25 PHPDBG_API int phpdbg_is_numeric(const char*);
26 PHPDBG_API int phpdbg_is_empty(const char*);
27 PHPDBG_API int phpdbg_is_addr(const char*);
28 PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
29 PHPDBG_API const char *phpdbg_current_file(void);
30 PHPDBG_API char *phpdbg_resolve_path(const char*);
31 PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
32 PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char*);
33
34 /* {{{ Color Management */
35 #define PHPDBG_COLOR_LEN 12
36 #define PHPDBG_COLOR_D(color, code) \
37 {color, sizeof(color)-1, code}
38 #define PHPDBG_COLOR_END \
39 {NULL, 0L, {0}}
40 #define PHPDBG_ELEMENT_LEN 3
41 #define PHPDBG_ELEMENT_D(name, id) \
42 {name, sizeof(name)-1, id}
43 #define PHPDBG_ELEMENT_END \
44 {NULL, 0L, 0}
45
46 #define PHPDBG_COLOR_INVALID -1
47 #define PHPDBG_COLOR_PROMPT 0
48 #define PHPDBG_COLOR_ERROR 1
49 #define PHPDBG_COLOR_NOTICE 2
50 #define PHPDBG_COLORS 3
51
52 typedef struct _phpdbg_color_t {
53 char *name;
54 size_t name_length;
55 const char code[PHPDBG_COLOR_LEN];
56 } phpdbg_color_t;
57
58 typedef struct _phpdbg_element_t {
59 char *name;
60 size_t name_length;
61 int id;
62 } phpdbg_element_t;
63
64 PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length);
65 PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color);
66 PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length);
67 PHPDBG_API const phpdbg_color_t *phpdbg_get_colors(void);
68 PHPDBG_API int phpdbg_get_element(const char *name, size_t len); /* }}} */
69
70 /* {{{ Prompt Management */
71 PHPDBG_API void phpdbg_set_prompt(const char*);
72 PHPDBG_API const char *phpdbg_get_prompt(void); /* }}} */
73
74 /* {{{ Console size */
75 PHPDBG_API int phpdbg_get_terminal_width(void);
76 PHPDBG_API int phpdbg_get_terminal_height(void); /* }}} */
77
78 PHPDBG_API void phpdbg_set_async_io(int fd);
79
80 int phpdbg_rebuild_symtable(void);
81
82 int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce);
83
84 char *phpdbg_get_property_key(char *key);
85
86 typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv);
87 typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg);
88
89 PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent);
90 PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg);
91
92 int phpdbg_is_auto_global(char *name, int len);
93
94 PHPDBG_API void phpdbg_xml_var_dump(zval *zv);
95
96 char *phpdbg_short_zval_print(zval *zv, int maxlen);
97
98 PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception);
99
phpdbg_user_execute_data(zend_execute_data * ex)100 static zend_always_inline zend_execute_data *phpdbg_user_execute_data(zend_execute_data *ex) {
101 while (!ex->func || !ZEND_USER_CODE(ex->func->common.type)) {
102 ex = ex->prev_execute_data;
103 ZEND_ASSERT(ex);
104 }
105 return ex;
106 }
107
108 #ifdef ZTS
109 #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
110 zend_output_globals *output_globals_ptr; \
111 zend_output_globals original_output_globals; \
112 output_globals_ptr = TSRMG_BULK_STATIC(output_globals_id, zend_output_globals *);
113 #else
114 #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
115 zend_output_globals *output_globals_ptr; \
116 zend_output_globals original_output_globals; \
117 output_globals_ptr = &output_globals;
118 #endif
119
120 #define PHPDBG_OUTPUT_BACKUP_SWAP() \
121 original_output_globals = *output_globals_ptr; \
122 memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \
123 php_output_activate();
124
125 #define PHPDBG_OUTPUT_BACKUP() \
126 PHPDBG_OUTPUT_BACKUP_DEFINES() \
127 PHPDBG_OUTPUT_BACKUP_SWAP()
128
129 #define PHPDBG_OUTPUT_BACKUP_RESTORE() \
130 php_output_deactivate(); \
131 *output_globals_ptr = original_output_globals;
132
133 #endif /* PHPDBG_UTILS_H */
134