From 2941a4ab500b92c51347641724339b17d993d5f9 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 22:55:52 -0200 Subject: [PATCH 1/6] - print command has optional arguments --- phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 60852b4430b..583549c4a5a 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -67,7 +67,7 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = { PHPDBG_COMMAND_D(until, "continue until reaches next line", 'u', NULL, 0), PHPDBG_COMMAND_D(finish, "continue past the end of the stack", 'f', NULL, 0), PHPDBG_COMMAND_D(leave, "continue until the end of the stack", 'L', NULL, 0), - PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, 1), + PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, 2), PHPDBG_COMMAND_D(break, "set breakpoint", 'b', phpdbg_break_commands, 1), PHPDBG_COMMAND_D(back, "show trace", 't', NULL, 0), PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, 2), From a7c4a6c21b388fdbcec716950161ce0114503167 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 23:04:46 -0200 Subject: [PATCH 2/6] - Removed unreached break stmt --- phpdbg_prompt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 058f3de6ab4..675ea5ca6bc 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -736,7 +736,6 @@ static PHPDBG_COMMAND(list) /* {{{ */ case METHOD_PARAM: return PHPDBG_LIST_HANDLER(method)(param TSRMLS_CC); - break; phpdbg_default_switch_case(); } From 66494ad94e089b53ed292a5b69a6772ecd00b9ac Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 23:05:14 -0200 Subject: [PATCH 3/6] - CS --- phpdbg_prompt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 675ea5ca6bc..e4451c5179e 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -858,8 +858,7 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ PHPDBG_G(ops) = NULL; } - if (full) - { + if (full) { PHPDBG_G(flags) |= PHPDBG_IS_CLEANING; zend_bailout(); From f72b2d6c7c908d2485168e1050743078ff67b4f6 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 23:07:57 -0200 Subject: [PATCH 4/6] - Move phpdbg_welcome to phpdbg.c and staticfy it --- phpdbg.c | 22 ++++++++++++++++++++-- phpdbg_prompt.c | 18 ------------------ phpdbg_prompt.h | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/phpdbg.c b/phpdbg.c index 4226dc3bdbb..14d6625cc64 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -387,6 +387,24 @@ void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */ INI_DEFAULT("display_errors", "1"); } /* }}} */ +static 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))); + } +} /* }}} */ + int main(int argc, char **argv) /* {{{ */ { sapi_module_struct *phpdbg = &phpdbg_sapi_module; @@ -416,12 +434,12 @@ int main(int argc, char **argv) /* {{{ */ setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ - + console = GetConsoleWindow(); if (console) { GetWindowRect(console, &consoleRect); MoveWindow( - console, consoleRect.left, consoleRect.top, 800,600, TRUE); + console, consoleRect.left, consoleRect.top, 800,600, TRUE); } #endif diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index e4451c5179e..3a5dbf6c5dc 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -179,24 +179,6 @@ next_line: } } /* }}} */ -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) /* {{{ */ { switch (param->type) { diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h index ce2864751b2..5f8de2b81d3 100644 --- a/phpdbg_prompt.h +++ b/phpdbg_prompt.h @@ -26,7 +26,6 @@ #define PHPDBG_MAX_CMD 500 void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC); -void phpdbg_welcome(zend_bool cleaning TSRMLS_DC); int phpdbg_interactive(TSRMLS_D); void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC); int phpdbg_compile(TSRMLS_D); From a84ac645850ab31f2e48321a0d462b5bd3af1447 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 23:08:53 -0200 Subject: [PATCH 5/6] - WS --- phpdbg.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/phpdbg.c b/phpdbg.c index 14d6625cc64..0ccb0f4bc32 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -419,10 +419,9 @@ int main(int argc, char **argv) /* {{{ */ size_t oplog_file_len; zend_ulong flags; char *php_optarg; - int php_optind; - int opt; - long cleaning = 0; - + int php_optind; + int opt; + long cleaning = 0; #ifdef ZTS void ***tsrm_ls; #endif From 7e2a4bcc94ea25235c9922ca087610b111e86efa Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Nov 2013 23:18:12 -0200 Subject: [PATCH 6/6] - WS --- phpdbg.c | 206 +++++++++++++++++++++++++++---------------------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/phpdbg.c b/phpdbg.c index 0ccb0f4bc32..ec8d2677c2e 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -443,122 +443,122 @@ int main(int argc, char **argv) /* {{{ */ #endif #ifdef ZTS - tsrm_startup(1, 1, 0, NULL); + tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); #endif phpdbg_main: - ini_entries = NULL; - ini_entries_len = 0; - exec = NULL; - exec_len = 0; - init_file = NULL; - init_file_len = 0; - init_file_default = 1; - oplog_file = NULL; - oplog_file_len = 0; - flags = PHPDBG_DEFAULT_FLAGS; - php_optarg = NULL; - php_optind = 1; - opt = 0; + ini_entries = NULL; + ini_entries_len = 0; + exec = NULL; + exec_len = 0; + init_file = NULL; + init_file_len = 0; + init_file_default = 1; + oplog_file = NULL; + oplog_file_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': - phpdbg->php_ini_ignore = 1; - break; - case 'c': - if (phpdbg->php_ini_path_override) { - free(phpdbg->php_ini_path_override); - } - phpdbg->php_ini_path_override = strdup(php_optarg); - break; - case 'd': { - int len = strlen(php_optarg); - char *val; + while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { + switch (opt) { + case 'n': + phpdbg->php_ini_ignore = 1; + break; + case 'c': + if (phpdbg->php_ini_path_override) { + free(phpdbg->php_ini_path_override); + } + phpdbg->php_ini_path_override = strdup(php_optarg); + break; + case 'd': { + int len = strlen(php_optarg); + char *val; - if ((val = strchr(php_optarg, '='))) { - val++; - if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { - ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); - memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (val - php_optarg); - memcpy(ini_entries + ini_entries_len, "\"", 1); - ini_entries_len++; - memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (val - php_optarg); - memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); - ini_entries_len += sizeof("\n\0\"") - 2; - } else { - ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\n\0")); - memcpy(ini_entries + ini_entries_len, php_optarg, len); - memcpy(ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0")); - ini_entries_len += len + sizeof("\n\0") - 2; - } - } else { - ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("=1\n\0")); - memcpy(ini_entries + ini_entries_len, php_optarg, len); - memcpy(ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0")); - ini_entries_len += len + sizeof("=1\n\0") - 2; - } - } break; - case 'z': - zend_load_extension(php_optarg); - break; + if ((val = strchr(php_optarg, '='))) { + val++; + if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { + ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); + memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); + ini_entries_len += (val - php_optarg); + memcpy(ini_entries + ini_entries_len, "\"", 1); + ini_entries_len++; + memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); + ini_entries_len += len - (val - php_optarg); + memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); + ini_entries_len += sizeof("\n\0\"") - 2; + } else { + ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\n\0")); + memcpy(ini_entries + ini_entries_len, php_optarg, len); + memcpy(ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0")); + ini_entries_len += len + sizeof("\n\0") - 2; + } + } else { + ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("=1\n\0")); + memcpy(ini_entries + ini_entries_len, php_optarg, len); + memcpy(ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0")); + ini_entries_len += len + sizeof("=1\n\0") - 2; + } + } break; + case 'z': + zend_load_extension(php_optarg); + break; - /* begin phpdbg options */ + /* begin phpdbg options */ - case 'e': { /* set execution context */ - exec_len = strlen(php_optarg); - if (exec_len) { - exec = strdup(php_optarg); - } - } break; + case 'e': { /* set execution context */ + exec_len = strlen(php_optarg); + if (exec_len) { + exec = strdup(php_optarg); + } + } break; - case 'I': { /* ignore .phpdbginit */ - init_file_default = 0; - } break; + case 'I': { /* ignore .phpdbginit */ + init_file_default = 0; + } break; - case 'i': { /* set init file */ - init_file_len = strlen(php_optarg); - if (init_file_len) { - init_file = strdup(php_optarg); - } - } break; + case 'i': { /* set init file */ + init_file_len = strlen(php_optarg); + if (init_file_len) { + init_file = strdup(php_optarg); + } + } break; - case 'O': { /* set oplog output */ - oplog_file_len = strlen(php_optarg); - if (oplog_file_len) { - oplog_file = strdup(php_optarg); - } - } break; + case 'O': { /* set oplog output */ + oplog_file_len = strlen(php_optarg); + if (oplog_file_len) { + oplog_file = strdup(php_optarg); + } + } break; - case 'v': /* set quietness off */ - flags &= ~PHPDBG_IS_QUIET; - break; + case 'v': /* set quietness off */ + flags &= ~PHPDBG_IS_QUIET; + break; - case 's': /* set stepping on */ - flags |= PHPDBG_IS_STEPPING; - break; + case 's': /* set stepping on */ + flags |= PHPDBG_IS_STEPPING; + break; - case 'b': /* set colours off */ - flags &= ~PHPDBG_IS_COLOURED; - break; - } - } + case 'b': /* set colours off */ + flags &= ~PHPDBG_IS_COLOURED; + break; + } + } - phpdbg->ini_defaults = phpdbg_ini_defaults; + phpdbg->ini_defaults = phpdbg_ini_defaults; phpdbg->phpinfo_as_text = 1; phpdbg->php_ini_ignore_cwd = 1; sapi_startup(phpdbg); - phpdbg->executable_location = argv[0]; - phpdbg->phpinfo_as_text = 1; - phpdbg->php_ini_ignore = 0; + phpdbg->executable_location = argv[0]; + phpdbg->phpinfo_as_text = 1; + phpdbg->php_ini_ignore = 0; - if (ini_entries) { + if (ini_entries) { ini_entries = realloc(ini_entries, ini_entries_len + sizeof(phpdbg_ini_hardcoded)); memmove(ini_entries + sizeof(phpdbg_ini_hardcoded) - 2, ini_entries, ini_entries_len + 1); memcpy(ini_entries, phpdbg_ini_hardcoded, sizeof(phpdbg_ini_hardcoded) - 2); @@ -568,7 +568,7 @@ phpdbg_main: } ini_entries_len += sizeof(phpdbg_ini_hardcoded) - 2; - phpdbg->ini_entries = ini_entries; + phpdbg->ini_entries = ini_entries; if (phpdbg->startup(phpdbg) == SUCCESS) { zend_activate(TSRMLS_C); @@ -589,14 +589,14 @@ phpdbg_main: free(exec); } - if (oplog_file) { /* open oplog */ - PHPDBG_G(oplog) = fopen(oplog_file, "w+"); - if (!PHPDBG_G(oplog)) { - phpdbg_error( - "Failed to open oplog %s", oplog_file); - } - free(oplog_file); - } + if (oplog_file) { /* open oplog */ + PHPDBG_G(oplog) = fopen(oplog_file, "w+"); + if (!PHPDBG_G(oplog)) { + phpdbg_error( + "Failed to open oplog %s", oplog_file); + } + free(oplog_file); + } /* set flags from command line */ PHPDBG_G(flags) = flags;