void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */
{
- zend_bool init_default = 0;
+ zend_bool init_default = 0;
- if (!init_file && use_default) {
- struct stat sb;
+ if (!init_file && use_default) {
+ struct stat sb;
- if (VCWD_STAT(".phpdbginit", &sb) != -1) {
- init_file = ".phpdbginit";
- init_file_len = strlen(".phpdbginit");
- init_default = 1;
- }
- }
+ if (VCWD_STAT(".phpdbginit", &sb) != -1) {
+ init_file = ".phpdbginit";
+ init_file_len = strlen(".phpdbginit");
+ init_default = 1;
+ }
+ }
- if (init_file) {
- FILE *fp = fopen(init_file, "r");
- if (fp) {
- int line = 1;
-
- char cmd[PHPDBG_MAX_CMD];
- size_t cmd_len = 0L;
- char *code = NULL;
- size_t code_len = 0L;
- zend_bool in_code = 0;
-
- while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
- phpdbg_command_t *selected = NULL;
-
- cmd_len = strlen(cmd)-1;
-
- while (*cmd && isspace(cmd[cmd_len-1]))
- cmd_len--;
-
- cmd[cmd_len] = '\0';
-
- if (*cmd && cmd_len > 0L && cmd[0] != '#') {
- if (cmd_len == 2) {
- if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) {
- in_code = 1;
- goto next_line;
- } else {
- if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) {
- in_code = 0;
- code[code_len] = '\0';
- {
- zend_eval_stringl(
- code, code_len, NULL, "phpdbginit code" TSRMLS_CC);
- }
- free(code);
- code = NULL;
- goto next_line;
- }
- }
- }
+ if (init_file) {
+ FILE *fp = fopen(init_file, "r");
+ if (fp) {
+ int line = 1;
+
+ char cmd[PHPDBG_MAX_CMD];
+ size_t cmd_len = 0L;
+ char *code = NULL;
+ size_t code_len = 0L;
+ zend_bool in_code = 0;
+
+ while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
+ phpdbg_command_t *selected = NULL;
+
+ cmd_len = strlen(cmd)-1;
+
+ while (*cmd && isspace(cmd[cmd_len-1]))
+ cmd_len--;
+
+ cmd[cmd_len] = '\0';
+
+ if (*cmd && cmd_len > 0L && cmd[0] != '#') {
+ if (cmd_len == 2) {
+ if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) {
+ in_code = 1;
+ goto next_line;
+ } else {
+ if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) {
+ in_code = 0;
+ code[code_len] = '\0';
+ {
+ zend_eval_stringl(
+ code, code_len, NULL, "phpdbginit code" TSRMLS_CC);
+ }
+ free(code);
+ code = NULL;
+ goto next_line;
+ }
+ }
+ }
- if (in_code) {
- if (code == NULL) {
- code = malloc(cmd_len);
- } else code = realloc(code, code_len + cmd_len);
-
- if (code) {
- memcpy(
- &code[code_len], cmd, cmd_len);
- code_len += cmd_len;
- }
- goto next_line;
- }
+ if (in_code) {
+ if (code == NULL) {
+ code = malloc(cmd_len);
+ } else code = realloc(code, code_len + cmd_len);
+
+ if (code) {
+ memcpy(
+ &code[code_len], cmd, cmd_len);
+ code_len += cmd_len;
+ }
+ goto next_line;
+ }
- switch (phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
- case FAILURE:
- phpdbg_error(
- "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
- break;
- }
- }
+ switch (phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
+ case FAILURE:
+ phpdbg_error(
+ "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
+ break;
+ }
+ }
next_line:
- line++;
- }
+ line++;
+ }
- if (code) {
- free(code);
- }
+ if (code) {
+ free(code);
+ }
- fclose(fp);
- } else {
- phpdbg_error(
- "Failed to open %s for initialization", init_file);
- }
+ fclose(fp);
+ } else {
+ phpdbg_error(
+ "Failed to open %s for initialization", init_file);
+ }
- if (!init_default) {
- free(init_file);
- }
- }
+ if (!init_default) {
+ free(init_file);
+ }
+ }
} /* }}} */
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)));
- }
+ 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) {
- case STR_PARAM: {
- struct stat sb;
-
- if (VCWD_STAT(param->str, &sb) != FAILURE) {
- if (sb.st_mode & S_IFREG|S_IFLNK) {
- if (PHPDBG_G(exec)) {
- phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
- efree(PHPDBG_G(exec));
- PHPDBG_G(exec) = NULL;
- }
-
- if (PHPDBG_G(ops)) {
- phpdbg_notice("Destroying compiled opcodes");
- phpdbg_clean(0 TSRMLS_CC);
- }
-
- PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
-
- if (!PHPDBG_G(exec)) {
- phpdbg_error("Cannot get real file path");
- return SUCCESS;
- }
-
- PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
-
- phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
-
- } else {
- phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
- }
- } else {
- phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
- }
- } break;
-
- phpdbg_default_switch_case();
- }
+ switch (param->type) {
+ case STR_PARAM: {
+ struct stat sb;
+
+ if (VCWD_STAT(param->str, &sb) != FAILURE) {
+ if (sb.st_mode & S_IFREG|S_IFLNK) {
+ if (PHPDBG_G(exec)) {
+ phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
+ efree(PHPDBG_G(exec));
+ PHPDBG_G(exec) = NULL;
+ }
+
+ if (PHPDBG_G(ops)) {
+ phpdbg_notice("Destroying compiled opcodes");
+ phpdbg_clean(0 TSRMLS_CC);
+ }
+
+ PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
+
+ if (!PHPDBG_G(exec)) {
+ phpdbg_error("Cannot get real file path");
+ return SUCCESS;
+ }
+
+ PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
+
+ phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
+
+ } else {
+ phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
+ }
+ } else {
+ phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
+ }
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(step) /* {{{ */
{
- switch (param->type) {
- case EMPTY_PARAM:
- case NUMERIC_PARAM: {
- if (param->type == NUMERIC_PARAM && param->num) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
- } else {
- PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
- }
-
- phpdbg_notice("Stepping %s",
- (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
- } break;
-
- phpdbg_default_switch_case();
- }
+ switch (param->type) {
+ case EMPTY_PARAM:
+ case NUMERIC_PARAM: {
+ if (param->type == NUMERIC_PARAM && param->num) {
+ PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ } else {
+ PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
+ }
+
+ phpdbg_notice("Stepping %s",
+ (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(run) /* {{{ */
{
- if (EG(in_execution)) {
+ if (EG(in_execution)) {
phpdbg_error("Cannot start another execution while one is in progress");
return SUCCESS;
- }
+ }
if (PHPDBG_G(ops) || PHPDBG_G(exec)) {
zend_op **orig_opline = EG(opline_ptr);
static PHPDBG_COMMAND(eval) /* {{{ */
{
- switch (param->type) {
- case STR_PARAM: {
- zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
- zval retval;
-
- PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
-
- /* disable stepping while eval() in progress */
- PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
- if (zend_eval_stringl(param->str, param->len,
- &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
- zend_print_zval_r(
- &retval, 0 TSRMLS_CC);
- phpdbg_writeln(EMPTY);
- zval_dtor(&retval);
- }
- PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
+ switch (param->type) {
+ case STR_PARAM: {
+ zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
+ zval retval;
+
+ PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+
+ /* disable stepping while eval() in progress */
+ PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
+ if (zend_eval_stringl(param->str, param->len,
+ &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
+ zend_print_zval_r(
+ &retval, 0 TSRMLS_CC);
+ phpdbg_writeln(EMPTY);
+ zval_dtor(&retval);
+ }
+ PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
/* switch stepping back on */
- if (stepping) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
- }
- } break;
+ if (stepping) {
+ PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ }
+ } break;
- phpdbg_default_switch_case();
- }
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(back) /* {{{ */
{
- if (!EG(in_execution)) {
- phpdbg_error("Not executing!");
- return SUCCESS;
- }
+ if (!EG(in_execution)) {
+ phpdbg_error("Not executing!");
+ return SUCCESS;
+ }
- switch (param->type) {
- case EMPTY_PARAM:
- case NUMERIC_PARAM: {
- zval zbacktrace;
- zval **tmp;
- HashPosition position;
- int i = 0,
- limit = (param->type == NUMERIC_PARAM) ? param->num : 0;
-
- zend_fetch_debug_backtrace(
- &zbacktrace, 0, 0, limit TSRMLS_CC);
-
- for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
- zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position)) {
- if (i++) {
- phpdbg_writeln(",");
- }
- zend_print_flat_zval_r(*tmp TSRMLS_CC);
- }
-
- phpdbg_writeln(EMPTY);
- zval_dtor(&zbacktrace);
- } break;
-
- phpdbg_default_switch_case();
- }
+ switch (param->type) {
+ case EMPTY_PARAM:
+ case NUMERIC_PARAM: {
+ zval zbacktrace;
+ zval **tmp;
+ HashPosition position;
+ int i = 0,
+ limit = (param->type == NUMERIC_PARAM) ? param->num : 0;
+
+ zend_fetch_debug_backtrace(
+ &zbacktrace, 0, 0, limit TSRMLS_CC);
+
+ for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
+ zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == SUCCESS;
+ zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position)) {
+ if (i++) {
+ phpdbg_writeln(",");
+ }
+ zend_print_flat_zval_r(*tmp TSRMLS_CC);
+ }
- return SUCCESS;
+ phpdbg_writeln(EMPTY);
+ zval_dtor(&zbacktrace);
+ } break;
+
+ phpdbg_default_switch_case();
+ }
+
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(print) /* {{{ */
{
- switch (param->type) {
- case EMPTY_PARAM: {
- phpdbg_writeln(SEPARATE);
- phpdbg_notice("Execution Context Information");
+ switch (param->type) {
+ case EMPTY_PARAM: {
+ phpdbg_writeln(SEPARATE);
+ phpdbg_notice("Execution Context Information");
#ifdef HAVE_LIBREADLINE
- phpdbg_writeln("Readline\tyes");
+ phpdbg_writeln("Readline\tyes");
#else
- phpdbg_writeln("Readline\tno");
+ phpdbg_writeln("Readline\tno");
#endif
- phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
- phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no");
- phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
- phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
- phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off");
-
- if (PHPDBG_G(ops)) {
- phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last);
-
- if (PHPDBG_G(ops)->last_var) {
- phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1);
- } else {
- phpdbg_writeln("Variables\tNone");
- }
- }
-
- phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no");
- if (EG(in_execution)) {
- phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret));
- }
- phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files)));
-
- phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC);
-
- phpdbg_writeln(SEPARATE);
- } break;
-
- phpdbg_default_switch_case();
- }
+ phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
+ phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no");
+ phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+ phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
+ phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off");
+
+ if (PHPDBG_G(ops)) {
+ phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last);
+
+ if (PHPDBG_G(ops)->last_var) {
+ phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1);
+ } else {
+ phpdbg_writeln("Variables\tNone");
+ }
+ }
+
+ phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no");
+ if (EG(in_execution)) {
+ phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret));
+ }
+ phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files)));
+
+ phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC);
+
+ phpdbg_writeln(SEPARATE);
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(quit) /* {{{ */
{
/* don't allow this to loop, ever ... */
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
- zend_bailout();
- }
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+ zend_bailout();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(clean) /* {{{ */
{
- if (EG(in_execution)) {
- phpdbg_error("Cannot clean environment while executing");
- return SUCCESS;
+ if (EG(in_execution)) {
+ phpdbg_error("Cannot clean environment while executing");
+ return SUCCESS;
}
phpdbg_notice("Cleaning Execution Environment");
phpdbg_clean(1 TSRMLS_CC);
- return SUCCESS;
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(clear) /* {{{ */
{
- phpdbg_notice("Clearing Breakpoints");
+ phpdbg_notice("Clearing Breakpoints");
- phpdbg_writeln("File\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
- phpdbg_writeln("Methods\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
- phpdbg_writeln("Oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
- phpdbg_writeln("Conditionals\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]));
+ phpdbg_writeln("File\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
+ phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
+ phpdbg_writeln("Methods\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
+ phpdbg_writeln("Oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
+ phpdbg_writeln("Conditionals\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]));
- phpdbg_clear_breakpoints(TSRMLS_C);
+ phpdbg_clear_breakpoints(TSRMLS_C);
return SUCCESS;
} /* }}} */
{
const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
- phpdbg_help_header();
- phpdbg_writeln("Below are the aliased, short versions of all supported commands");
+ phpdbg_help_header();
+ phpdbg_writeln("Below are the aliased, short versions of all supported commands");
while (prompt_command && prompt_command->name) {
if (prompt_command->alias) {
if (prompt_command->subs) {
- const phpdbg_command_t *sub_command = prompt_command->subs;
- phpdbg_writeln(EMPTY);
- phpdbg_writeln("\t%c -> %s", prompt_command->alias, prompt_command->name);
- while (sub_command && sub_command->name) {
- if (sub_command->alias) {
- phpdbg_writeln("\t|------- %c -> %s\t%s", sub_command->alias,
- sub_command->name, sub_command->tip);
- }
- ++sub_command;
- }
- phpdbg_writeln(EMPTY);
- } else {
- phpdbg_writeln("\t%c -> %s\t%s", prompt_command->alias,
- prompt_command->name, prompt_command->tip);
- }
+ const phpdbg_command_t *sub_command = prompt_command->subs;
+ phpdbg_writeln(EMPTY);
+ phpdbg_writeln("\t%c -> %s", prompt_command->alias, prompt_command->name);
+ while (sub_command && sub_command->name) {
+ if (sub_command->alias) {
+ phpdbg_writeln("\t|------- %c -> %s\t%s", sub_command->alias,
+ sub_command->name, sub_command->tip);
+ }
+ ++sub_command;
+ }
+ phpdbg_writeln(EMPTY);
+ } else {
+ phpdbg_writeln("\t%c -> %s\t%s", prompt_command->alias,
+ prompt_command->name, prompt_command->tip);
+ }
}
++prompt_command;
}
- phpdbg_help_footer();
+ phpdbg_help_footer();
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(oplog) /* {{{ */
{
- switch (param->type) {
- case EMPTY_PARAM:
- case NUMERIC_PARAM:
- if ((param->type != NUMERIC_PARAM) || !param->num) {
- if (PHPDBG_G(oplog)) {
- phpdbg_notice("Disabling oplog");
- fclose(
- PHPDBG_G(oplog));
- } else {
- phpdbg_error("No oplog currently open");
- }
- }
- break;
-
- case STR_PARAM: {
- /* open oplog */
- FILE *old = PHPDBG_G(oplog);
-
- PHPDBG_G(oplog) = fopen(param->str, "w+");
- if (!PHPDBG_G(oplog)) {
- phpdbg_error("Failed to open %s for oplog", param->str);
- PHPDBG_G(oplog) = old;
- } else {
- if (old) {
- phpdbg_notice("Closing previously open oplog");
- fclose(old);
- }
- phpdbg_notice("Successfully opened oplog %s", param->str);
- }
- } break;
-
- phpdbg_default_switch_case();
- }
+ switch (param->type) {
+ case EMPTY_PARAM:
+ case NUMERIC_PARAM:
+ if ((param->type != NUMERIC_PARAM) || !param->num) {
+ if (PHPDBG_G(oplog)) {
+ phpdbg_notice("Disabling oplog");
+ fclose(
+ PHPDBG_G(oplog));
+ } else {
+ phpdbg_error("No oplog currently open");
+ }
+ }
+ break;
+
+ case STR_PARAM: {
+ /* open oplog */
+ FILE *old = PHPDBG_G(oplog);
+
+ PHPDBG_G(oplog) = fopen(param->str, "w+");
+ if (!PHPDBG_G(oplog)) {
+ phpdbg_error("Failed to open %s for oplog", param->str);
+ PHPDBG_G(oplog) = old;
+ } else {
+ if (old) {
+ phpdbg_notice("Closing previously open oplog");
+ fclose(old);
+ }
+ phpdbg_notice("Successfully opened oplog %s", param->str);
+ }
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
{
switch (param->type) {
case EMPTY_PARAM: {
- const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
- const phpdbg_command_t *help_command = phpdbg_help_commands;
+ const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
+ const phpdbg_command_t *help_command = phpdbg_help_commands;
- phpdbg_help_header();
- phpdbg_writeln("To get help regarding a specific command type \"help command\"");
+ phpdbg_help_header();
+ phpdbg_writeln("To get help regarding a specific command type \"help command\"");
- phpdbg_notice("Commands");
+ phpdbg_notice("Commands");
- while (prompt_command && prompt_command->name) {
- phpdbg_writeln(
- "\t%s\t%s", prompt_command->name, prompt_command->tip);
- ++prompt_command;
- }
+ while (prompt_command && prompt_command->name) {
+ phpdbg_writeln(
+ "\t%s\t%s", prompt_command->name, prompt_command->tip);
+ ++prompt_command;
+ }
- phpdbg_notice("Helpers Loaded");
+ phpdbg_notice("Helpers Loaded");
- while (help_command && help_command->name) {
- phpdbg_writeln("\t%s\t%s", help_command->name, help_command->tip);
- ++help_command;
- }
+ while (help_command && help_command->name) {
+ phpdbg_writeln("\t%s\t%s", help_command->name, help_command->tip);
+ ++help_command;
+ }
- phpdbg_notice("Command Line Options and Flags");
- phpdbg_writeln("\tOption\tExample\t\t\tPurpose");
- phpdbg_writeln(EMPTY);
- phpdbg_writeln("\t-c\t-c/my/php.ini\t\tSet php.ini file to load");
- phpdbg_writeln("\t-d\t-dmemory_limit=4G\tSet a php.ini directive");
- phpdbg_writeln("\t-n\t-N/A\t\t\tDisable default php.ini");
- phpdbg_writeln("\t-e\t-emytest.php\t\tSet execution context");
- phpdbg_writeln("\t-v\tN/A\t\t\tEnable opline output while executing");
- phpdbg_writeln("\t-s\tN/A\t\t\tEnable stepping");
- phpdbg_writeln("\t-b\tN/A\t\t\tDisable the use of colours");
- phpdbg_writeln("\t-i\t-imy.init\t\tSet the phpdbginit file");
- phpdbg_writeln("\t-I\tN/A\t\t\tDisable loading .phpdbginit");
- phpdbg_writeln("\t-O\t-Omy.oplog\t\tSets oplog output file");
- phpdbg_help_footer();
- } break;
-
- phpdbg_default_switch_case();
- }
+ phpdbg_notice("Command Line Options and Flags");
+ phpdbg_writeln("\tOption\tExample\t\t\tPurpose");
+ phpdbg_writeln(EMPTY);
+ phpdbg_writeln("\t-c\t-c/my/php.ini\t\tSet php.ini file to load");
+ phpdbg_writeln("\t-d\t-dmemory_limit=4G\tSet a php.ini directive");
+ phpdbg_writeln("\t-n\t-N/A\t\t\tDisable default php.ini");
+ phpdbg_writeln("\t-e\t-emytest.php\t\tSet execution context");
+ phpdbg_writeln("\t-v\tN/A\t\t\tEnable opline output while executing");
+ phpdbg_writeln("\t-s\tN/A\t\t\tEnable stepping");
+ phpdbg_writeln("\t-b\tN/A\t\t\tDisable the use of colours");
+ phpdbg_writeln("\t-i\t-imy.init\t\tSet the phpdbginit file");
+ phpdbg_writeln("\t-I\tN/A\t\t\tDisable loading .phpdbginit");
+ phpdbg_writeln("\t-O\t-Omy.oplog\t\tSets oplog output file");
+ phpdbg_help_footer();
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(quiet) /* {{{ */
{
- switch (param->type) {
- case NUMERIC_PARAM: {
- if (param->num) {
- PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
- } else {
- PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
- }
- phpdbg_notice("Quietness %s",
- (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "enabled" : "disabled");
- } break;
-
- phpdbg_default_switch_case();
- }
+ switch (param->type) {
+ case NUMERIC_PARAM: {
+ if (param->num) {
+ PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
+ } else {
+ PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
+ }
+ phpdbg_notice("Quietness %s",
+ (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "enabled" : "disabled");
+ } break;
+
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
return SUCCESS;
} /* }}} */
-int phpdbg_do_cmd( const phpdbg_command_t *command,
- phpdbg_command_t **selected,
- char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
+int phpdbg_do_cmd( const phpdbg_command_t *command,
+ phpdbg_command_t **selected,
+ char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
{
- int rc = FAILURE;
+ int rc = FAILURE;
char *expr = NULL;
#ifndef _WIN32
#endif
size_t expr_len = (cmd != NULL) ? strlen(cmd) : 0;
- phpdbg_param_t *param = NULL;
+ phpdbg_param_t *param = NULL;
while (command && command->name && command->handler) {
if ((command->name_len == expr_len
- && memcmp(cmd, command->name, expr_len) == 0)
- || ((expr_len == 1) && (command->alias && command->alias == cmd_line[0]))) {
+ && memcmp(cmd, command->name, expr_len) == 0)
+ || ((expr_len == 1) && (command->alias && command->alias == cmd_line[0]))) {
- param = emalloc(sizeof(phpdbg_param_t));
+ param = emalloc(sizeof(phpdbg_param_t));
PHPDBG_G(last) = (phpdbg_command_t*) command;
- /* urm ... */
- if (PHPDBG_G(lparam)) {
- //phpdbg_clear_param(
- // PHPDBG_G(lparam) TSRMLS_CC);
- //efree(PHPDBG_G(lparam));
- }
+ /* urm ... */
+ if (PHPDBG_G(lparam)) {
+ //phpdbg_clear_param(
+ // PHPDBG_G(lparam) TSRMLS_CC);
+ //efree(PHPDBG_G(lparam));
+ }
- phpdbg_parse_param(
- expr,
- (cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
- param TSRMLS_CC);
+ phpdbg_parse_param(
+ expr,
+ (cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
+ param TSRMLS_CC);
- PHPDBG_G(lparam) = param;
+ PHPDBG_G(lparam) = param;
- if (command->subs && (param->type == STR_PARAM)) {
- if (phpdbg_do_cmd(command->subs, selected, param->str, param->len TSRMLS_CC) == SUCCESS) {
- rc = SUCCESS;
- /* because we can */
- phpdbg_clear_param(param TSRMLS_CC);
- efree(param);
- goto done;
- }
- }
+ if (command->subs && (param->type == STR_PARAM)) {
+ if (phpdbg_do_cmd(command->subs, selected, param->str, param->len TSRMLS_CC) == SUCCESS) {
+ rc = SUCCESS;
+ /* because we can */
+ phpdbg_clear_param(param TSRMLS_CC);
+ efree(param);
+ goto done;
+ }
+ }
- *selected = (phpdbg_command_t*) command;
+ *selected = (phpdbg_command_t*) command;
rc = command->handler(param TSRMLS_CC);
- break;
- }
- ++command;
- }
+ break;
+ }
+ ++command;
+ }
done:
- if (selected && param) {
- phpdbg_debug(
- "phpdbg_do_cmd(%s, \"%s\"): %d",
- command->name, phpdbg_get_param_type(param TSRMLS_CC), (rc==SUCCESS));
- }
+ if (selected && param) {
+ phpdbg_debug(
+ "phpdbg_do_cmd(%s, \"%s\"): %d",
+ command->name, phpdbg_get_param_type(param TSRMLS_CC), (rc==SUCCESS));
+ }
return rc;
} /* }}} */
int phpdbg_interactive(TSRMLS_D) /* {{{ */
{
- size_t cmd_len;
- int ret = SUCCESS;
+ size_t cmd_len;
+ int ret = SUCCESS;
#ifndef HAVE_LIBREADLINE
- char cmd[PHPDBG_MAX_CMD];
+ char cmd[PHPDBG_MAX_CMD];
while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING) &&
- phpdbg_write(PROMPT) &&
- (fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) {
- cmd_len = strlen(cmd) - 1;
+ phpdbg_write(PROMPT) &&
+ (fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) {
+ cmd_len = strlen(cmd) - 1;
#else
- char *cmd = NULL;
+ char *cmd = NULL;
- while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+ while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
cmd = readline(PROMPT);
cmd_len = cmd ? strlen(cmd) : 0;
#endif
/* trim space from end of input */
while (*cmd && isspace(cmd[cmd_len-1]))
- cmd_len--;
+ cmd_len--;
/* ensure string is null terminated */
cmd[cmd_len] = '\0';
if (*cmd && cmd_len > 0L) {
- /* keep a cursor to selected command */
- phpdbg_command_t *selected = NULL;
+ /* keep a cursor to selected command */
+ phpdbg_command_t *selected = NULL;
#ifdef HAVE_LIBREADLINE
- add_history(cmd);
+ add_history(cmd);
#endif
- switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
- case FAILURE:
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+ switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
+ case FAILURE:
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
phpdbg_error("Failed to execute %s!", cmd);
- }
- break;
+ }
+ break;
case PHPDBG_UNTIL:
- case PHPDBG_NEXT: {
- if (!EG(in_execution)) {
+ case PHPDBG_NEXT: {
+ if (!EG(in_execution)) {
phpdbg_error("Not running");
- }
- goto out;
- }
- }
+ }
+ goto out;
+ }
+ }
#ifdef HAVE_LIBREADLINE
- if (cmd) {
- free(cmd);
- cmd = NULL;
- }
+ if (cmd) {
+ free(cmd);
+ cmd = NULL;
+ }
#endif
} else if (PHPDBG_G(last)) {
ret = PHPDBG_G(last)->handler(PHPDBG_G(lparam) TSRMLS_CC);
goto out;
}
}
+
out:
#ifdef HAVE_LIBREADLINE
- if (cmd) {
- free(cmd);
- }
+ if (cmd) {
+ free(cmd);
+ }
#endif
return ret;
void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC) /* {{{ */
{
/* force out a line while stepping so the user knows what is happening */
- if (ignore_flags ||
- (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) ||
- (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ||
- (PHPDBG_G(oplog)))) {
-
- zend_op *opline = execute_data->opline;
-
- if (ignore_flags ||
- (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) ||
- (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) {
- /* output line info */
- phpdbg_notice("#%lu %p %s %s",
- opline->lineno,
- opline,
- phpdbg_decode_opcode(opline->opcode),
- execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
+ if (ignore_flags ||
+ (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) ||
+ (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ||
+ (PHPDBG_G(oplog)))) {
+
+ zend_op *opline = execute_data->opline;
+
+ if (ignore_flags ||
+ (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) ||
+ (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) {
+ /* output line info */
+ phpdbg_notice("#%lu %p %s %s",
+ opline->lineno,
+ opline,
+ phpdbg_decode_opcode(opline->opcode),
+ execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
}
- if (!ignore_flags && PHPDBG_G(oplog)) {
- phpdbg_log_ex(PHPDBG_G(oplog), "#%lu %p %s %s",
- opline->lineno,
- opline,
- phpdbg_decode_opcode(opline->opcode),
- execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
- }
+ if (!ignore_flags && PHPDBG_G(oplog)) {
+ phpdbg_log_ex(PHPDBG_G(oplog), "#%lu %p %s %s",
+ opline->lineno,
+ opline,
+ phpdbg_decode_opcode(opline->opcode),
+ execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
+ }
}
} /* }}} */
void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
{
- /* this is implicitly required */
- if (PHPDBG_G(ops)) {
- destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
- efree(PHPDBG_G(ops));
- PHPDBG_G(ops) = NULL;
- }
+ /* this is implicitly required */
+ if (PHPDBG_G(ops)) {
+ destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
+ efree(PHPDBG_G(ops));
+ PHPDBG_G(ops) = NULL;
+ }
- if (full)
- {
- PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
+ if (full)
+ {
+ PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
- zend_bailout();
- }
+ zend_bailout();
+ }
} /* }}} */
static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */
#else
void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
- zend_execute_data *execute_data;
- zend_bool nested = 0;
+ zend_execute_data *execute_data;
+ zend_bool nested = 0;
#endif
zend_bool original_in_execution = EG(in_execution);
int last_step = 0;
const char *last_file;
#if PHP_VERSION_ID < 50500
- if (EG(exception)) {
- return;
- }
+ if (EG(exception)) {
+ return;
+ }
#endif
EG(in_execution) = 1;
}
#else
zend_vm_enter:
- execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
- nested = 1;
+ execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
+ nested = 1;
#endif
while (1) {
#endif
#define DO_INTERACTIVE() do {\
- phpdbg_list_file(\
- zend_get_executed_filename(TSRMLS_C), \
- 3, \
- zend_get_executed_lineno(TSRMLS_C)-1, \
- zend_get_executed_lineno(TSRMLS_C) \
- TSRMLS_CC\
- );\
- \
- do {\
- switch (last_step = phpdbg_interactive(TSRMLS_C)) {\
- case PHPDBG_UNTIL:\
- case PHPDBG_NEXT:{\
- goto next;\
- }\
- }\
- } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));\
+ phpdbg_list_file(\
+ zend_get_executed_filename(TSRMLS_C), \
+ 3, \
+ zend_get_executed_lineno(TSRMLS_C)-1, \
+ zend_get_executed_lineno(TSRMLS_C) \
+ TSRMLS_CC\
+ );\
+ \
+ do {\
+ switch (last_step = phpdbg_interactive(TSRMLS_C)) {\
+ case PHPDBG_UNTIL:\
+ case PHPDBG_NEXT:{\
+ goto next;\
+ }\
+ }\
+ } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));\
} while(0)
/* allow conditional breakpoints to access the vm uninterrupted */
PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
- if (PHPDBG_G(vmret) > 0) {
- switch (PHPDBG_G(vmret)) {
- case 1:
- EG(in_execution) = original_in_execution;
- return;
- case 2:
+ if (PHPDBG_G(vmret) > 0) {
+ switch (PHPDBG_G(vmret)) {
+ case 1:
+ EG(in_execution) = original_in_execution;
+ return;
+ case 2:
#if PHP_VERSION_ID < 50500
- op_array = EG(active_op_array);
+ op_array = EG(active_op_array);
#endif
- goto zend_vm_enter;
- break;
- case 3:
- execute_data = EG(current_execute_data);
- break;
- default:
+ goto zend_vm_enter;
+ break;
+ case 3:
+ execute_data = EG(current_execute_data);
+ break;
+ default:
break;
}
}