com php-src: Add info constants (alias: i d) command: phpdbg_help.c phpdbg_info.c phpdbg_info.h
| From: | Bob Weinand | Date: | Mon, 20 Oct 2014 19:14:13 +0000 |
| Subject: | com php-src: Add info constants (alias: i d) command: phpdbg_help.c phpdbg_info.c phpdbg_info.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82531@lists.php.net to get a copy of this message | ||
Commit: 3e5a4c6f305a48e53f8da5f1245ae91f2b8c672b
Author: Bob Weinand <bobwei9@hotmail.com> Mon, 20 Oct 2014 21:14:13 +0200
Parents: 6c6b356f637c1677a4f1b6f946fb899c2769aea5
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3e5a4c6f305a48e53f8da5f1245ae91f2b8c672b
Log:
Add info constants (alias: i d) command
Changed paths:
M phpdbg_help.c
M phpdbg_info.c
M phpdbg_info.h
Diff:
diff --git a/phpdbg_help.c b/phpdbg_help.c
index edb617f..8a7084b 100644
--- a/phpdbg_help.c
+++ b/phpdbg_help.c
@@ -653,15 +653,16 @@ phpdbg_help_text_t phpdbg_help_text[] = {
"Specific info commands are show below:" CR CR
" **Target** **Alias** **Purpose**" CR
-" **break** **b** show current breakpoints" CR
-" **files** **F** show included files" CR
-" **classes** **c** show loaded classes" CR
-" **funcs** **f** show loaded functions" CR
-" **error** **e** show last error" CR
-" **vars** **v** show active variables" CR
-" **globals** **g** show superglobal variables" CR
-" **literal** **l** show active literal constants" CR
-" **memory** **m** show memory manager stats"
+" **break** **b** show current breakpoints" CR
+" **files** **F** show included files" CR
+" **classes** **c** show loaded classes" CR
+" **funcs** **f** show loaded functions" CR
+" **error** **e** show last error" CR
+" **constants** **d** show user-defined constants" CR
+" **vars** **v** show active variables" CR
+" **globals** **g** show superglobal variables" CR
+" **literal** **l** show active literal constants" CR
+" **memory** **m** show memory manager stats"
},
// ******** same issue about breakpoints in called frames
diff --git a/phpdbg_info.c b/phpdbg_info.c
index e7857e1..7435287 100644
--- a/phpdbg_info.c
+++ b/phpdbg_info.c
@@ -31,15 +31,16 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[14], flags)
const phpdbg_command_t phpdbg_info_commands[] = {
- PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b',
info_break, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(files, "show included files", 'F',
info_files, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c',
info_classes, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f',
info_funcs, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(error, "show last error", 'e',
info_error, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v',
info_vars, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(globals, "show superglobals", 'g',
info_globals, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l',
info_literal, NULL, 0, PHPDBG_ASYNC_SAFE),
- PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm',
info_memory, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b',
info_break, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(files, "show included files", 'F',
info_files, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c',
info_classes, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f',
info_funcs, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(error, "show last error", 'e',
info_error, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(constants, "show user defined constants", 'd',
info_constants, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v',
info_vars, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(globals, "show superglobals", 'g',
info_globals, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l',
info_literal, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm',
info_memory, NULL, 0, PHPDBG_ASYNC_SAFE),
PHPDBG_END_COMMAND
};
@@ -96,6 +97,67 @@ PHPDBG_INFO(error) /* {{{ */
return SUCCESS;
} /* }}} */
+PHPDBG_INFO(constants) /* {{{ */
+{
+ HashPosition pos;
+ HashTable consts;
+ zend_constant *data;
+
+ zend_hash_init(&consts, 8, NULL, NULL, 0);
+
+ if (EG(zend_constants)) {
+ phpdbg_try_access {
+ zend_hash_internal_pointer_reset_ex(EG(zend_constants), &pos);
+ while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &data, &pos) ==
SUCCESS) {
+ if (data->module_number == PHP_USER_CONSTANT) {
+ zend_hash_update(&consts, data->name, data->name_len, (void **) &data,
sizeof(zend_constant *), NULL);
+ }
+ zend_hash_move_forward_ex(EG(zend_constants), &pos);
+ }
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Cannot fetch all the constants, invalid
data source");
+ } phpdbg_end_try_access();
+ }
+
+ phpdbg_notice("constantinfo", "num=\"%d\"", "User-defined
constants (%d)", zend_hash_num_elements(&consts));
+
+ if (zend_hash_num_elements(&consts)) {
+ phpdbg_out("Address Refs Type Constant\n");
+ for (zend_hash_internal_pointer_reset_ex(&consts, &pos);
+ zend_hash_get_current_data_ex(&consts, (void **) &data, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(&consts, &pos)) {
+ data = *(zend_constant **) data;
+
+#define VARIABLEINFO(attrs, msg, ...) phpdbg_writeln("constant",
"address=\"%p\" refcount=\"%d\" type=\"%s\"
name=\"%.*s\" " attrs, "%-18p %-7d %-9s %.*s" msg, &data->value,
Z_REFCOUNT(data->value), zend_zval_type_name(&data->value), data->name_len - 1,
data->name, ##__VA_ARGS__)
+
+ switch (Z_TYPE(data->value)) {
+ case IS_STRING:
+ phpdbg_try_access {
+ VARIABLEINFO("length=\"%d\" value=\"%.*s%s\"", "\nstring
(%d) \"%.*s%s\"", Z_STRLEN(data->value), Z_STRLEN(data->value) < 255 ?
Z_STRLEN(data->value) : 255, Z_STRVAL(data->value), Z_STRLEN(data->value) > 255 ?
"..." : "");
+ } phpdbg_catch_access {
+ VARIABLEINFO("", "");
+ } phpdbg_end_try_access();
+ break;
+ case IS_BOOL:
+ VARIABLEINFO("value=\"%s\"", "\nbool (%s)",
Z_LVAL(data->value) ? "true" : "false");
+ break;
+ case IS_LONG:
+ VARIABLEINFO("value=\"%ld\"", "\nint (%ld)",
Z_LVAL(data->value));
+ break;
+ case IS_DOUBLE:
+ VARIABLEINFO("value=\"%lf\"", "\ndouble (%lf)",
Z_DVAL(data->value));
+ break;
+ default:
+ VARIABLEINFO("", "");
+
+#undef VARIABLEINFO
+ }
+ }
+ }
+
+ return SUCCESS;
+} /* }}} */
+
static int phpdbg_arm_auto_global(zend_auto_global *auto_global TSRMLS_DC) {
if (auto_global->armed) {
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
@@ -175,8 +237,8 @@ static int phpdbg_print_symbols(zend_bool show_globals TSRMLS_DC) {
if (zend_hash_num_elements(&vars)) {
phpdbg_out("Address Refs Type Variable\n");
for (zend_hash_internal_pointer_reset_ex(&vars, &pos);
- zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS;
- zend_hash_move_forward_ex(&vars, &pos)) {
+ zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(&vars, &pos)) {
char *var;
zend_bool invalid_data = 1;
@@ -222,6 +284,8 @@ static int phpdbg_print_symbols(zend_bool show_globals TSRMLS_DC) {
VARIABLEINFO("", "");
}
}
+
+#undef VARIABLEINFO
} phpdbg_end_try_access();
if (invalid_data) {
diff --git a/phpdbg_info.h b/phpdbg_info.h
index 6930cdd..aac9fa3 100644
--- a/phpdbg_info.h
+++ b/phpdbg_info.h
@@ -30,6 +30,7 @@ PHPDBG_INFO(break);
PHPDBG_INFO(classes);
PHPDBG_INFO(funcs);
PHPDBG_INFO(error);
+PHPDBG_INFO(constants);
PHPDBG_INFO(vars);
PHPDBG_INFO(globals);
PHPDBG_INFO(literal);