php-src/phpdbg_prompt.c

600 lines
18 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| 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> |
+----------------------------------------------------------------------+
*/
#include <stdio.h>
#include <string.h>
#include "zend.h"
2013-11-10 13:01:46 +00:00
#include "zend_compile.h"
#include "phpdbg.h"
#include "phpdbg_help.h"
#include "phpdbg_bp.h"
#include "phpdbg_opcode.h"
static const phpdbg_command_t phpdbg_prompt_commands[];
2013-11-10 11:03:29 +00:00
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(exec) /* {{{ */
{
if (PHPDBG_G(exec)) {
2013-11-11 14:03:14 +00:00
printf("[Unsetting old execution context: %s]\n", PHPDBG_G(exec));
2013-11-10 18:29:05 +00:00
efree(PHPDBG_G(exec));
PHPDBG_G(exec) = NULL;
}
2013-11-10 11:48:01 +00:00
2013-11-10 18:29:05 +00:00
if (PHPDBG_G(ops)) {
2013-11-11 14:03:14 +00:00
printf("[Destroying compiled opcodes]\n");
2013-11-10 18:29:05 +00:00
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
efree(PHPDBG_G(ops));
PHPDBG_G(ops) = NULL;
}
2013-11-10 11:36:57 +00:00
2013-11-10 18:29:05 +00:00
PHPDBG_G(exec) = estrndup(expr, PHPDBG_G(exec_len) = expr_len);
2013-11-10 11:36:57 +00:00
2013-11-11 14:03:14 +00:00
printf("[Set execution context: %s]\n", PHPDBG_G(exec));
2013-11-10 11:48:01 +00:00
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 11:35:59 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static inline int phpdbg_compile(TSRMLS_D) /* {{{ */
{
zend_file_handle fh;
2013-11-10 13:01:46 +00:00
2013-11-10 21:07:29 +00:00
if (!EG(in_execution)) {
2013-11-11 14:03:14 +00:00
printf("[Attempting compilation of %s]\n", PHPDBG_G(exec));
2013-11-10 21:07:29 +00:00
if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh,
USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC) == SUCCESS) {
PHPDBG_G(ops) = zend_compile_file(
&fh, ZEND_INCLUDE TSRMLS_CC);
zend_destroy_file_handle(&fh TSRMLS_CC);
2013-11-11 14:03:14 +00:00
printf("[Success]\n");
2013-11-10 21:07:29 +00:00
return SUCCESS;
} else {
2013-11-11 14:03:14 +00:00
printf("[Could not open file %s]\n", PHPDBG_G(exec));
2013-11-10 21:07:29 +00:00
}
} else {
2013-11-11 14:03:14 +00:00
printf("[Cannot compile while in execution]\n");
2013-11-10 21:07:29 +00:00
}
2013-11-10 21:38:58 +00:00
2013-11-10 18:29:05 +00:00
return FAILURE;
2013-11-10 11:03:29 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(compile) /* {{{ */
{
if (PHPDBG_G(exec)) {
2013-11-11 14:07:07 +00:00
if (!EG(in_execution)) {
if (PHPDBG_G(ops)) {
printf("[Destroying previously compiled opcodes]\n");
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
efree(PHPDBG_G(ops));
PHPDBG_G(ops)=NULL;
}
2013-11-10 18:29:05 +00:00
}
return phpdbg_compile(TSRMLS_C);
} else {
2013-11-11 14:03:14 +00:00
printf("[No execution context]\n");
2013-11-10 18:29:05 +00:00
return FAILURE;
}
2013-11-10 14:28:14 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(step) /* {{{ */
{
PHPDBG_G(stepping) = atoi(expr);
2013-11-11 11:54:41 +00:00
printf(
2013-11-11 14:03:14 +00:00
"[Stepping %s]\n", PHPDBG_G(stepping) ? "on" : "off");
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 14:28:14 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(next) /* {{{ */
{
return PHPDBG_NEXT;
2013-11-10 15:32:24 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(run) /* {{{ */
{
if (EG(in_execution)) {
2013-11-11 17:01:33 +00:00
printf("[Cannot start another execution while one is in progress]\n");
return FAILURE;
}
2013-11-10 18:29:05 +00:00
if (PHPDBG_G(ops) || PHPDBG_G(exec)) {
if (!PHPDBG_G(ops)) {
if (phpdbg_compile(TSRMLS_C) == FAILURE) {
2013-11-11 14:03:14 +00:00
printf("[Failed to compile %s, cannot run]\n", PHPDBG_G(exec));
2013-11-10 18:29:05 +00:00
return FAILURE;
}
}
2013-11-10 15:21:20 +00:00
2013-11-10 18:29:05 +00:00
EG(active_op_array) = PHPDBG_G(ops);
EG(return_value_ptr_ptr) = &PHPDBG_G(retval);
zend_try {
zend_execute(EG(active_op_array) TSRMLS_CC);
} zend_catch {
if (!PHPDBG_G(quitting)) {
2013-11-11 14:03:14 +00:00
printf("[Caught excetion in VM]\n");
2013-11-10 18:29:05 +00:00
return FAILURE;
} else return SUCCESS;
} zend_end_try();
return SUCCESS;
} else {
2013-11-11 14:03:14 +00:00
printf("[Nothing to execute !]\n");
2013-11-10 18:29:05 +00:00
return FAILURE;
}
2013-11-10 14:43:46 +00:00
} /* }}} */
2013-11-10 18:29:05 +00:00
static PHPDBG_COMMAND(eval) /* {{{ */
{
zval retval;
2013-11-11 17:09:08 +00:00
if (expr_len) {
2013-11-10 21:57:43 +00:00
if (zend_eval_stringl((char*)expr, expr_len-1,
&retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
2013-11-10 18:29:05 +00:00
zend_print_zval_r(&retval, 0 TSRMLS_CC);
printf("\n");
zval_dtor(&retval);
}
} else {
2013-11-11 14:03:14 +00:00
printf("[No expression provided !]\n");
2013-11-10 18:29:05 +00:00
return FAILURE;
}
2013-11-10 15:21:20 +00:00
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 15:16:45 +00:00
} /* }}} */
2013-11-10 18:21:49 +00:00
static PHPDBG_COMMAND(back) /* {{{ */
{
if (!EG(in_execution)) {
2013-11-11 14:03:14 +00:00
printf("[Not executing !]\n");
2013-11-10 18:21:49 +00:00
return FAILURE;
}
zval zbacktrace;
zval **tmp;
HashPosition position;
int i = 0, limit = (expr != NULL) ? atoi(expr) : 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++) {
printf(",\n");
}
zend_print_flat_zval_r(*tmp TSRMLS_CC);
}
2013-11-10 18:21:49 +00:00
printf("\n");
zval_dtor(&zbacktrace);
2013-11-10 18:21:49 +00:00
return SUCCESS;
2013-11-10 15:16:45 +00:00
} /* }}} */
2013-11-10 18:15:00 +00:00
static PHPDBG_COMMAND(print) /* {{{ */
{
if (expr_len) {
printf("%s\n", expr);
return SUCCESS;
}
2013-11-11 11:54:41 +00:00
#ifdef HAVE_READLINE_H
printf("HAVE READLINE\n");
#endif
printf("--------------------------------------\n");
printf("Execution Context Information:\n");
2013-11-10 18:15:00 +00:00
printf("Exec\t\t%s\n", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
printf("Compiled\t%s\n", PHPDBG_G(ops) ? "yes" : "no");
printf("Stepping\t%s\n", PHPDBG_G(stepping) ? "on" : "off");
if (PHPDBG_G(ops)) {
printf("Opcodes\t\t%d\n", PHPDBG_G(ops)->last);
if (PHPDBG_G(ops)->last_var) {
printf("Variables\t%d\n", PHPDBG_G(ops)->last_var-1);
} else {
printf("Variables\tNone\n");
}
}
printf("Executing\t%s\n", EG(in_execution) ? "yes" : "no");
if (EG(in_execution)) {
printf("VM Return\t%d\n", PHPDBG_G(vmret));
}
printf("Classes\t\t%d\n", zend_hash_num_elements(EG(class_table)));
printf("Functions\t%d\n", zend_hash_num_elements(EG(function_table)));
printf("Constants\t%d\n", zend_hash_num_elements(EG(zend_constants)));
printf("Included\t%d\n", zend_hash_num_elements(&EG(included_files)));
if (PHPDBG_G(has_file_bp)) {
HashPosition position;
zend_llist *points;
printf("--------------------------------------\n");
printf("File Break Point Information:\n");
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_files), &position);
zend_hash_get_current_data_ex(&PHPDBG_G(bp_files), (void**) &points, &position) == SUCCESS;
zend_hash_move_forward_ex(&PHPDBG_G(bp_files), &position)) {
zend_llist_position lposition;
phpdbg_breakfile_t *brake;
if ((brake = zend_llist_get_first_ex(points, &lposition))) {
printf("%s:\n", brake->filename);
do {
printf("\t%lu\n", brake->line);
} while ((brake = zend_llist_get_next_ex(points, &lposition)));
}
}
}
#if 0
if (PHPDBG_G(has_sym_bp)) {
HashPosition position;
zend_llist *points;
printf("--------------------------------------\n");
printf("Symbol Break Point Information:\n");
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_symbols), &position);
zend_hash_get_current_data_ex(&PHPDBG_G(bp_symbols), (void**) &points, &position) == SUCCESS;
zend_hash_move_forward_ex(&PHPDBG_G(bp_symbols), &position)) {
zend_llist_position lposition;
phpdbg_breaksymbol_t *brake;
if ((brake = zend_llist_get_first_ex(points, &lposition))) {
printf("%s:\n", brake->symbol);
do {
printf("\t%d\n", brake->id);
} while ((brake = zend_llist_get_next_ex(points, &lposition)));
}
}
}
#endif
2013-11-11 12:07:11 +00:00
if (PHPDBG_G(has_opline_bp)) {
HashPosition position;
phpdbg_breakline_t *brake;
printf("--------------------------------------\n");
printf("Opline Break Point Information:\n");
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_oplines), &position);
zend_hash_get_current_data_ex(&PHPDBG_G(bp_oplines), (void**) &brake, &position) == SUCCESS;
zend_hash_move_forward_ex(&PHPDBG_G(bp_oplines), &position)) {
2013-11-11 13:04:21 +00:00
printf("#%d\t%s\n", brake->id, brake->name);
2013-11-11 12:07:11 +00:00
}
}
printf("--------------------------------------\n");
2013-11-10 18:15:00 +00:00
return SUCCESS;
} /* }}} */
2013-11-10 14:36:30 +00:00
static PHPDBG_COMMAND(break) /* {{{ */
{
const char *line_pos = zend_memrchr(expr, ':', expr_len);
2013-11-11 09:36:33 +00:00
2013-11-10 14:36:30 +00:00
if (line_pos) {
char path[MAXPATHLEN], resolved_name[MAXPATHLEN];
long line_num = strtol(line_pos+1, NULL, 0);
2013-11-11 09:36:33 +00:00
if (line_num) {
memcpy(path, expr, line_pos - expr);
path[line_pos - expr] = 0;
2013-11-11 09:36:33 +00:00
if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
2013-11-11 14:03:14 +00:00
printf("[Failed to expand path %s]\n", path);
2013-11-11 09:36:33 +00:00
return FAILURE;
}
2013-11-11 09:36:33 +00:00
phpdbg_set_breakpoint_file(resolved_name, line_num TSRMLS_CC);
} else {
2013-11-11 14:03:14 +00:00
printf("[No line specified in expression %s]\n", expr);
2013-11-11 09:36:33 +00:00
return FAILURE;
}
} else {
2013-11-11 11:54:41 +00:00
if (expr_len > 2 && expr[0] == '0' && expr[1] == 'x') {
phpdbg_set_breakpoint_opline(expr TSRMLS_CC);
} else {
char name[200];
size_t name_len = strlen(expr);
2013-11-11 11:54:41 +00:00
name_len = MIN(name_len, 200);
memcpy(name, expr, name_len);
name[name_len] = 0;
2013-11-11 11:54:41 +00:00
phpdbg_set_breakpoint_symbol(name TSRMLS_CC);
}
2013-11-10 14:36:30 +00:00
}
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(quit) /* {{{ */
{
2013-11-10 16:30:36 +00:00
PHPDBG_G(quitting)=1;
zend_bailout();
2013-11-10 11:36:57 +00:00
return SUCCESS;
} /* }}} */
static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC) /* {{{ */
{
return (c->flags & CONST_PERSISTENT) ? 0 : 1;
} /* }}} */
static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
{
return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
} /* }}} */
static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
{
return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
} /* }}} */
static PHPDBG_COMMAND(clean) /* {{{ */
{
2013-11-11 14:03:14 +00:00
printf("[Cleaning Environment:]\n");
printf("[\tClasses: %d]\n", zend_hash_num_elements(EG(class_table)));
printf("[\tFunctions: %d]\n", zend_hash_num_elements(EG(function_table)));
printf("[\tConstants: %d]\n", zend_hash_num_elements(EG(zend_constants)));
printf("[\tIncluded: %d]\n", zend_hash_num_elements(&EG(included_files)));
zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
zend_hash_clean(&EG(included_files));
2013-11-11 14:03:14 +00:00
printf("[Clean Environment:]\n");
printf("[\tClasses: %d]\n", zend_hash_num_elements(EG(class_table)));
printf("[\tFunctions: %d]\n", zend_hash_num_elements(EG(function_table)));
printf("[\tConstants: %d]\n", zend_hash_num_elements(EG(zend_constants)));
printf("[\tIncluded: %d]\n", zend_hash_num_elements(&EG(included_files)));
return SUCCESS;
} /* }}} */
2013-11-11 13:31:41 +00:00
static PHPDBG_COMMAND(clear) /* {{{ */
{
2013-11-11 14:03:14 +00:00
printf("[Clearing Breakpoints:]\n");
printf("[\tFile\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_files)));
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_symbols)));
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_oplines)));
2013-11-11 13:31:41 +00:00
zend_hash_clean(&PHPDBG_G(bp_files));
zend_hash_clean(&PHPDBG_G(bp_symbols));
zend_hash_clean(&PHPDBG_G(bp_oplines));
2013-11-11 14:33:53 +00:00
PHPDBG_G(has_file_bp) = 0;
PHPDBG_G(has_sym_bp) = 0;
PHPDBG_G(has_opline_bp) = 0;
2013-11-11 13:31:41 +00:00
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(help) /* {{{ */
{
2013-11-11 14:03:14 +00:00
printf("[Welcome to phpdbg, the interactive PHP debugger.]\n");
2013-11-10 11:36:57 +00:00
2013-11-10 18:21:49 +00:00
if (!expr_len) {
const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
const phpdbg_command_t *help_command = phpdbg_help_commands;
printf("To get help regarding a specific command type \"help command\"\n");
printf("Commands:\n");
while (prompt_command && prompt_command->name) {
printf("\t%s\t%s\n", prompt_command->name, prompt_command->tip);
++prompt_command;
}
2013-11-10 11:36:57 +00:00
2013-11-10 18:21:49 +00:00
printf("Helpers Loaded:\n");
while (help_command && help_command->name) {
printf("\t%s\t%s\n", help_command->name, help_command->tip);
++help_command;
}
} else {
2013-11-10 20:06:19 +00:00
if (phpdbg_do_cmd(phpdbg_help_commands, (char*)expr, expr_len TSRMLS_CC) == FAILURE) {
2013-11-10 18:21:49 +00:00
printf("failed to find help command: %s\n", expr);
}
}
2013-11-11 14:03:14 +00:00
printf("[Please report bugs to <https://github.com/krakjoe/phpdbg/issues>]\n");
2013-11-10 18:21:49 +00:00
return SUCCESS;
} /* }}} */
2013-11-10 21:23:18 +00:00
static PHPDBG_COMMAND(quiet) { /* {{{ */
PHPDBG_G(quiet) = atoi(expr);
return SUCCESS;
} /* }}} */
2013-11-10 11:03:29 +00:00
static const phpdbg_command_t phpdbg_prompt_commands[] = {
2013-11-10 11:48:01 +00:00
PHPDBG_COMMAND_D(exec, "set execution context"),
PHPDBG_COMMAND_D(compile, "attempt to pre-compile execution context"),
2013-11-10 14:28:14 +00:00
PHPDBG_COMMAND_D(step, "step through execution"),
2013-11-10 21:09:35 +00:00
PHPDBG_COMMAND_D(next, "continue execution"),
2013-11-10 13:01:46 +00:00
PHPDBG_COMMAND_D(run, "attempt execution"),
2013-11-10 14:43:46 +00:00
PHPDBG_COMMAND_D(eval, "evaluate some code"),
2013-11-10 11:48:01 +00:00
PHPDBG_COMMAND_D(print, "print something"),
PHPDBG_COMMAND_D(break, "set breakpoint"),
2013-11-10 15:16:45 +00:00
PHPDBG_COMMAND_D(back, "show backtrace"),
PHPDBG_COMMAND_D(clean, "clean the execution environment"),
2013-11-11 13:31:41 +00:00
PHPDBG_COMMAND_D(clear, "clear breakpoints"),
2013-11-10 11:35:59 +00:00
PHPDBG_COMMAND_D(help, "show help menu"),
2013-11-10 21:23:18 +00:00
PHPDBG_COMMAND_D(quiet, "silence some output"),
2013-11-10 11:35:59 +00:00
PHPDBG_COMMAND_D(quit, "exit phpdbg"),
{NULL, 0, 0}
};
int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
{
char *params = NULL;
const char *cmd = strtok_r(cmd_line, " ", &params);
size_t expr_len = cmd != NULL ? strlen(cmd) : 0;
2013-11-10 11:36:57 +00:00
while (command && command->name) {
if (command->name_len == expr_len
&& memcmp(cmd, command->name, expr_len) == 0) {
2013-11-11 11:54:41 +00:00
PHPDBG_G(last) = (phpdbg_command_t*) command;
PHPDBG_G(last_params) = params;
PHPDBG_G(last_params_len) = cmd_len - expr_len;
return command->handler(params, cmd_len - expr_len TSRMLS_CC);
}
++command;
}
return FAILURE;
} /* }}} */
int phpdbg_interactive(TSRMLS_D) /* {{{ */
{
char cmd[PHPDBG_MAX_CMD];
printf("phpdbg> ");
while (!PHPDBG_G(quitting) &&
2013-11-10 16:30:36 +00:00
fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
size_t cmd_len = strlen(cmd) - 1;
2013-11-10 18:10:23 +00:00
if (cmd[cmd_len] == '\n') {
cmd[cmd_len] = 0;
}
2013-11-10 11:36:57 +00:00
if (cmd_len) {
2013-11-10 14:28:14 +00:00
switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
2013-11-10 16:34:12 +00:00
if (!PHPDBG_G(quitting)) {
printf(
2013-11-11 14:03:14 +00:00
"[Failed to execute %s !]\n", cmd);
2013-11-10 16:34:12 +00:00
}
2013-11-10 14:28:14 +00:00
break;
2013-11-10 15:11:56 +00:00
2013-11-10 22:44:28 +00:00
case PHPDBG_NEXT:
2013-11-10 14:28:14 +00:00
return PHPDBG_NEXT;
2013-11-10 18:15:00 +00:00
2013-11-10 14:28:14 +00:00
}
} else if (PHPDBG_G(last)) {
PHPDBG_G(last)->handler(
PHPDBG_G(last_params), PHPDBG_G(last_params_len) TSRMLS_CC);
}
2013-11-10 11:36:57 +00:00
2013-11-10 16:33:35 +00:00
if (!PHPDBG_G(quitting)) {
printf("phpdbg> ");
}
}
2013-11-10 15:11:56 +00:00
2013-11-10 14:28:14 +00:00
return SUCCESS;
} /* }}} */
2013-11-10 13:01:46 +00:00
2013-11-10 20:06:19 +00:00
static void phpdbg_print_opline(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
{
2013-11-10 21:23:18 +00:00
if (!PHPDBG_G(quiet)) {
zend_op *opline = execute_data->opline;
2013-11-10 18:15:00 +00:00
2013-11-10 21:23:18 +00:00
printf("[OPLINE: %p:%s]\n", opline, phpdbg_decode_opcode(opline->opcode));
}
2013-11-10 18:05:11 +00:00
} /* }}} */
2013-11-10 18:21:49 +00:00
void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
2013-11-10 13:01:46 +00:00
{
2013-11-10 15:16:45 +00:00
zend_bool original_in_execution = EG(in_execution);
2013-11-10 13:01:46 +00:00
EG(in_execution) = 1;
if (0) {
zend_vm_enter:
execute_data = zend_create_execute_data_from_op_array(EG(active_op_array), 1 TSRMLS_CC);
}
while (1) {
#ifdef ZEND_WIN32
if (EG(timed_out)) {
zend_timeout(0);
}
#endif
2013-11-11 17:06:30 +00:00
phpdbg_print_opline(
execute_data TSRMLS_CC);
2013-11-10 21:28:12 +00:00
if (PHPDBG_G(has_file_bp)
2013-11-10 20:06:19 +00:00
&& phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC) == SUCCESS) {
while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
if (!PHPDBG_G(quitting)) {
continue;
}
}
}
2013-11-10 21:29:14 +00:00
if (PHPDBG_G(has_sym_bp) && execute_data->opline->opcode != ZEND_RETURN) {
2013-11-10 20:59:35 +00:00
zend_execute_data *previous = execute_data->prev_execute_data;
2013-11-10 21:38:58 +00:00
if (previous && previous != execute_data && previous->opline) {
if (previous->opline->opcode == ZEND_DO_FCALL
|| previous->opline->opcode == ZEND_DO_FCALL_BY_NAME) {
if (phpdbg_find_breakpoint_symbol(
previous->function_state.function TSRMLS_CC) == SUCCESS) {
while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
if (!PHPDBG_G(quitting)) {
continue;
}
2013-11-10 21:38:58 +00:00
}
}
}
}
2013-11-10 20:59:35 +00:00
}
2013-11-11 11:54:41 +00:00
if (PHPDBG_G(has_opline_bp)
&& phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC) == SUCCESS) {
while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
if (!PHPDBG_G(quitting)) {
continue;
}
2013-11-11 11:54:41 +00:00
}
}
2013-11-10 15:11:56 +00:00
PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
2013-11-10 21:38:58 +00:00
2013-11-10 15:11:56 +00:00
if (PHPDBG_G(stepping)) {
while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {
if (!PHPDBG_G(quitting)) {
continue;
}
2013-11-10 15:11:56 +00:00
}
2013-11-10 14:36:30 +00:00
}
2013-11-10 14:28:14 +00:00
if (PHPDBG_G(vmret) > 0) {
switch (PHPDBG_G(vmret)) {
2013-11-10 13:01:46 +00:00
case 1:
EG(in_execution) = original_in_execution;
return;
case 2:
goto zend_vm_enter;
break;
case 3:
execute_data = EG(current_execute_data);
break;
default:
break;
}
}
}
zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
2013-11-10 18:21:49 +00:00
} /* }}} */