php-src/phpdbg_prompt.c

1435 lines
38 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> |
| Authors: Bob Weinand <bwoebi@php.net> |
+----------------------------------------------------------------------+
*/
#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"
2013-11-12 08:26:11 +00:00
#include "phpdbg_print.h"
2013-11-17 15:42:34 +00:00
#include "phpdbg_info.h"
2013-11-13 14:22:01 +00:00
#include "phpdbg_break.h"
#include "phpdbg_bp.h"
#include "phpdbg_opcode.h"
2013-11-12 00:24:24 +00:00
#include "phpdbg_list.h"
2013-11-12 02:19:43 +00:00
#include "phpdbg_utils.h"
#include "phpdbg_prompt.h"
#include "phpdbg_cmd.h"
2013-11-13 21:15:45 +00:00
/* {{{ command declarations */
const phpdbg_command_t phpdbg_prompt_commands[] = {
PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, 1),
2013-11-18 13:23:28 +00:00
PHPDBG_COMMAND_D(compile, "attempt compilation", 'c', NULL, 0),
PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 1),
PHPDBG_COMMAND_D(next, "continue execution", 'n', NULL, 0),
PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, 0),
PHPDBG_COMMAND_D(eval, "evaluate some code", 'E', NULL, 1),
2013-11-18 00:42:07 +00:00
PHPDBG_COMMAND_D(until, "continue past the current line", 'u', NULL, 0),
2013-11-22 17:27:55 +00:00
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),
2013-11-18 00:55:52 +00:00
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(frame, "switch to a frame", 'f', NULL, 1),
PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, 2),
PHPDBG_COMMAND_D(info, "displays some informations", 'i', phpdbg_info_commands, 1),
PHPDBG_COMMAND_D(clean, "clean the execution environment", 'X', NULL, 0),
PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0),
2013-11-17 22:05:21 +00:00
PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, 2),
PHPDBG_COMMAND_D(quiet, "silence some output", 'Q', NULL, 1),
PHPDBG_COMMAND_D(aliases, "show alias list", 'a', NULL, 0),
PHPDBG_COMMAND_D(oplog, "sets oplog output", 'O', NULL, 1),
2013-11-19 01:18:43 +00:00
PHPDBG_COMMAND_D(register,"register a function", 'R', NULL, 1),
2013-11-19 01:56:33 +00:00
PHPDBG_COMMAND_D(shell, "shell a command", '-', NULL, 1),
PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0),
PHPDBG_END_COMMAND
2013-11-13 21:15:45 +00:00
}; /* }}} */
2013-11-10 11:03:29 +00:00
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */
{
2013-11-17 12:07:01 +00:00
zend_bool init_default = 0;
2013-11-15 15:26:51 +00:00
2013-11-17 12:07:01 +00:00
if (!init_file && use_default) {
struct stat sb;
2013-11-17 12:07:01 +00:00
if (VCWD_STAT(".phpdbginit", &sb) != -1) {
init_file = ".phpdbginit";
init_file_len = strlen(".phpdbginit");
init_default = 1;
}
}
2013-11-17 12:07:01 +00:00
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) {
cmd_len = strlen(cmd)-1;
2013-11-23 15:35:30 +00:00
while (cmd_len > 0L && isspace(cmd[cmd_len-1]))
2013-11-17 12:07:01 +00:00
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;
}
}
}
2013-11-17 12:07:01 +00:00
if (in_code) {
if (code == NULL) {
2013-11-18 20:20:07 +00:00
code = malloc(cmd_len + 1);
} else code = realloc(code, code_len + cmd_len + 1);
2013-11-17 12:07:01 +00:00
if (code) {
memcpy(
&code[code_len], cmd, cmd_len);
code_len += cmd_len;
}
goto next_line;
}
2013-11-20 12:10:27 +00:00
2013-11-20 10:04:05 +00:00
{
phpdbg_input_t *input = phpdbg_read_input(cmd TSRMLS_CC);
switch (phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) {
case FAILURE:
phpdbg_error(
"Unrecognized command in %s:%d: %s!", init_file, line, cmd);
break;
}
phpdbg_destroy_input(&input TSRMLS_CC);
2013-11-17 12:07:01 +00:00
}
2013-11-20 12:10:27 +00:00
2013-11-17 12:07:01 +00:00
}
2013-11-15 14:53:40 +00:00
next_line:
2013-11-17 12:07:01 +00:00
line++;
}
2013-11-17 12:07:01 +00:00
if (code) {
free(code);
}
2013-11-17 12:07:01 +00:00
fclose(fp);
} else {
phpdbg_error(
"Failed to open %s for initialization", init_file);
}
2013-11-17 12:07:01 +00:00
if (!init_default) {
free(init_file);
}
}
} /* }}} */
2013-11-10 11:03:29 +00:00
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(exec) /* {{{ */
2013-11-10 18:29:05 +00:00
{
2013-11-17 12:07:01 +00:00
switch (param->type) {
case STR_PARAM: {
struct stat sb;
if (VCWD_STAT(param->str, &sb) != FAILURE) {
2013-11-17 12:12:10 +00:00
if (sb.st_mode & (S_IFREG|S_IFLNK)) {
char *res = phpdbg_resolve_path(param->str TSRMLS_CC);
size_t res_len = strlen(res);
2013-11-23 15:34:36 +00:00
if ((res_len != PHPDBG_G(exec_len)) ||
(memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) {
2013-11-23 15:34:36 +00:00
if (PHPDBG_G(exec)) {
phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
efree(PHPDBG_G(exec));
PHPDBG_G(exec) = NULL;
PHPDBG_G(exec_len) = 0L;
}
if (PHPDBG_G(ops)) {
phpdbg_notice("Destroying compiled opcodes");
phpdbg_clean(0 TSRMLS_CC);
}
2013-11-17 12:07:01 +00:00
PHPDBG_G(exec) = res;
PHPDBG_G(exec_len) = res_len;
2013-11-17 12:07:01 +00:00
phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
} else {
2013-11-23 13:05:36 +00:00
phpdbg_notice("Execution context not changed");
}
2013-11-17 12:07:01 +00:00
} 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();
}
2013-11-16 14:34:49 +00:00
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 11:35:59 +00:00
} /* }}} */
int phpdbg_compile(TSRMLS_D) /* {{{ */
2013-11-10 18:29:05 +00:00
{
zend_file_handle fh;
2013-11-10 13:01:46 +00:00
2013-11-13 21:43:54 +00:00
if (EG(in_execution)) {
phpdbg_error("Cannot compile while in execution");
return FAILURE;
}
2013-11-11 22:02:34 +00:00
2013-11-13 21:43:54 +00:00
phpdbg_notice("Attempting compilation of %s", PHPDBG_G(exec));
2013-11-13 21:43:54 +00:00
if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh,
USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC) == SUCCESS) {
2013-11-13 21:43:54 +00:00
PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE TSRMLS_CC);
zend_destroy_file_handle(&fh TSRMLS_CC);
phpdbg_notice("Success");
return SUCCESS;
2013-11-10 21:07:29 +00:00
} else {
2013-11-13 21:43:54 +00:00
phpdbg_error("Could not open file %s", PHPDBG_G(exec));
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-20 16:19:37 +00:00
PHPDBG_COMMAND(compile) /* {{{ */
2013-11-10 18:29:05 +00:00
{
2013-11-13 21:43:54 +00:00
if (!PHPDBG_G(exec)) {
phpdbg_error("No execution context");
return SUCCESS;
2013-11-10 18:29:05 +00:00
}
2013-11-17 11:28:14 +00:00
2013-11-13 21:43:54 +00:00
if (!EG(in_execution)) {
if (PHPDBG_G(ops)) {
phpdbg_error("Destroying previously compiled opcodes");
phpdbg_clean(0 TSRMLS_CC);
}
}
phpdbg_compile(TSRMLS_C);
2013-11-17 11:28:14 +00:00
return SUCCESS;
2013-11-10 14:28:14 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(step) /* {{{ */
2013-11-10 18:29:05 +00:00
{
2013-11-17 12:07:01 +00:00
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();
}
2013-11-12 02:19:43 +00:00
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 14:28:14 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(next) /* {{{ */
2013-11-10 18:29:05 +00:00
{
return PHPDBG_NEXT;
2013-11-10 15:32:24 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(until) /* {{{ */
{
2013-11-18 01:44:46 +00:00
if (!EG(in_execution)) {
phpdbg_error("Not executing");
return SUCCESS;
}
2013-11-18 14:09:25 +00:00
2013-11-18 01:44:46 +00:00
PHPDBG_G(flags) |= PHPDBG_IN_UNTIL;
{
zend_uint next = 0,
self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
zend_op *opline = &EG(active_op_array)->opcodes[self];
2013-11-18 14:09:25 +00:00
2013-11-18 01:44:46 +00:00
for (next = self; next < EG(active_op_array)->last; next++) {
if (EG(active_op_array)->opcodes[next].lineno != opline->lineno) {
2013-11-18 03:18:37 +00:00
zend_hash_index_update(
2013-11-18 14:09:25 +00:00
&PHPDBG_G(seek),
(zend_ulong) &EG(active_op_array)->opcodes[next],
2013-11-18 03:18:37 +00:00
&EG(active_op_array)->opcodes[next],
sizeof(zend_op), NULL);
2013-11-18 01:44:46 +00:00
break;
}
}
}
2013-11-18 14:09:25 +00:00
return PHPDBG_UNTIL;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(finish) /* {{{ */
2013-11-17 13:59:21 +00:00
{
2013-11-18 01:44:46 +00:00
if (!EG(in_execution)) {
phpdbg_error("Not executing");
return SUCCESS;
}
2013-11-18 14:09:25 +00:00
2013-11-18 01:44:46 +00:00
PHPDBG_G(flags) |= PHPDBG_IN_FINISH;
{
zend_uint next = 0,
self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
2013-11-18 14:09:25 +00:00
for (next = self; next < EG(active_op_array)->last; next++) {
2013-11-18 03:18:37 +00:00
switch (EG(active_op_array)->opcodes[next].opcode) {
case ZEND_RETURN:
case ZEND_THROW:
case ZEND_EXIT:
2013-11-18 10:32:33 +00:00
#ifdef ZEND_YIELD
case ZEND_YIELD:
#endif
2013-11-18 03:18:37 +00:00
zend_hash_index_update(
2013-11-18 14:09:25 +00:00
&PHPDBG_G(seek),
(zend_ulong) &EG(active_op_array)->opcodes[next],
2013-11-18 03:18:37 +00:00
&EG(active_op_array)->opcodes[next],
sizeof(zend_op), NULL);
break;
}
}
}
2013-11-18 14:09:25 +00:00
2013-11-17 13:59:21 +00:00
return PHPDBG_FINISH;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(leave) /* {{{ */
2013-11-17 15:39:23 +00:00
{
2013-11-18 01:44:46 +00:00
if (!EG(in_execution)) {
phpdbg_error("Not executing");
return SUCCESS;
}
2013-11-18 14:09:25 +00:00
2013-11-18 01:44:46 +00:00
PHPDBG_G(flags) |= PHPDBG_IN_LEAVE;
{
zend_uint next = 0,
self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
2013-11-18 14:09:25 +00:00
for (next = self; next < EG(active_op_array)->last; next++) {
2013-11-18 03:18:37 +00:00
switch (EG(active_op_array)->opcodes[next].opcode) {
case ZEND_RETURN:
case ZEND_THROW:
case ZEND_EXIT:
2013-11-18 10:32:33 +00:00
#ifdef ZEND_YIELD
case ZEND_YIELD:
#endif
2013-11-18 03:18:37 +00:00
zend_hash_index_update(
2013-11-18 14:09:25 +00:00
&PHPDBG_G(seek),
(zend_ulong) &EG(active_op_array)->opcodes[next],
2013-11-18 03:18:37 +00:00
&EG(active_op_array)->opcodes[next],
sizeof(zend_op), NULL);
break;
}
}
}
2013-11-18 14:09:25 +00:00
2013-11-17 15:39:23 +00:00
return PHPDBG_LEAVE;
} /* }}} */
2013-11-22 23:30:26 +00:00
static inline void phpdbg_restore_frame(TSRMLS_D) /* {{{ */
{
if (PHPDBG_FRAME(num) == 0) {
return;
}
PHPDBG_FRAME(num) = 0;
/* move things back */
EG(current_execute_data) = PHPDBG_FRAME(execute_data);
EG(opline_ptr) = &PHPDBG_EX(opline);
EG(active_op_array) = PHPDBG_EX(op_array);
EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value);
EG(active_symbol_table) = PHPDBG_EX(symbol_table);
EG(This) = PHPDBG_EX(current_this);
EG(scope) = PHPDBG_EX(current_scope);
EG(called_scope) = PHPDBG_EX(current_called_scope);
} /* }}} */
2013-11-22 23:30:26 +00:00
static inline void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */
{
zend_execute_data *execute_data = PHPDBG_FRAME(num)?PHPDBG_FRAME(execute_data):EG(current_execute_data);
int i = 0;
if (PHPDBG_FRAME(num) == frame) {
phpdbg_notice("Already in frame #%d", frame);
return;
}
while (execute_data) {
if (i++ == frame) {
break;
}
do {
execute_data = execute_data->prev_execute_data;
} while (execute_data && execute_data->opline == NULL);
}
if (execute_data == NULL) {
phpdbg_error("No frame #%d", frame);
return;
}
phpdbg_restore_frame(TSRMLS_C);
if (frame > 0) {
PHPDBG_FRAME(num) = frame;
/* backup things and jump back */
PHPDBG_FRAME(execute_data) = EG(current_execute_data);
EG(current_execute_data) = execute_data;
EG(opline_ptr) = &PHPDBG_EX(opline);
EG(active_op_array) = PHPDBG_EX(op_array);
PHPDBG_FRAME(execute_data)->original_return_value = EG(return_value_ptr_ptr);
EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value);
EG(active_symbol_table) = PHPDBG_EX(symbol_table);
EG(This) = PHPDBG_EX(current_this);
EG(scope) = PHPDBG_EX(current_scope);
EG(called_scope) = PHPDBG_EX(current_called_scope);
}
phpdbg_notice("Switched to frame #%d", frame);
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
);
} /* }}} */
2013-11-22 17:27:55 +00:00
PHPDBG_COMMAND(frame) /* {{{ */
{
switch (param->type) {
case NUMERIC_PARAM:
phpdbg_switch_frame(param->num TSRMLS_CC);
2013-11-22 17:27:55 +00:00
break;
case EMPTY_PARAM:
phpdbg_notice("Currently at frame %d:", PHPDBG_G(frame).num);
2013-11-22 17:27:55 +00:00
break;
phpdbg_default_switch_case();
}
2013-11-22 18:24:27 +00:00
return SUCCESS;
2013-11-22 17:27:55 +00:00
} /* }}} */
2013-11-18 17:00:26 +00:00
static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */
{
zend_fcall_info fci;
2013-11-19 01:30:57 +00:00
zval fname,
*trace,
2013-11-18 17:00:26 +00:00
exception;
/* get filename and linenumber before unsetting exception */
const char *filename = zend_get_executed_filename(TSRMLS_C);
zend_uint lineno = zend_get_executed_lineno(TSRMLS_C);
/* copy exception */
exception = *EG(exception);
zval_copy_ctor(&exception);
EG(exception) = NULL;
phpdbg_error(
2013-11-19 01:30:57 +00:00
"Uncaught %s !",
2013-11-18 17:00:26 +00:00
Z_OBJCE(exception)->name);
/* call __toString */
ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring")-1, 1);
fci.size = sizeof(fci);
fci.function_table = &Z_OBJCE(exception)->function_table;
fci.function_name = &fname;
fci.symbol_table = NULL;
fci.object_ptr = &exception;
fci.retval_ptr_ptr = &trace;
fci.param_count = 0;
fci.params = NULL;
fci.no_separation = 1;
zend_call_function(&fci, NULL TSRMLS_CC);
2013-11-19 01:30:57 +00:00
2013-11-18 17:00:26 +00:00
if (trace) {
phpdbg_writeln(
"Uncaught %s", Z_STRVAL_P(trace));
/* remember to dtor trace */
zval_ptr_dtor(&trace);
}
2013-11-19 01:30:57 +00:00
2013-11-18 17:00:26 +00:00
/* output useful information about address */
phpdbg_writeln(
"Stacked entered at %p in %s on line %lu",
EG(active_op_array)->opcodes, filename, lineno);
2013-11-19 01:30:57 +00:00
2013-11-18 17:00:26 +00:00
zval_dtor(&fname);
zval_dtor(&exception);
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(run) /* {{{ */
2013-11-10 18:29:05 +00:00
{
2013-11-17 12:07:01 +00:00
if (EG(in_execution)) {
phpdbg_error("Cannot start another execution while one is in progress");
return SUCCESS;
2013-11-17 12:07:01 +00:00
}
2013-11-11 22:02:34 +00:00
2013-11-10 18:29:05 +00:00
if (PHPDBG_G(ops) || PHPDBG_G(exec)) {
2013-11-13 14:22:01 +00:00
zend_op **orig_opline = EG(opline_ptr);
zend_op_array *orig_op_array = EG(active_op_array);
zval **orig_retval_ptr = EG(return_value_ptr_ptr);
2013-11-13 21:31:33 +00:00
2013-11-10 18:29:05 +00:00
if (!PHPDBG_G(ops)) {
if (phpdbg_compile(TSRMLS_C) == FAILURE) {
phpdbg_error(
"Failed to compile %s, cannot run", PHPDBG_G(exec));
goto out;
2013-11-10 18:29:05 +00:00
}
}
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);
2013-11-13 14:22:01 +00:00
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
2013-11-18 03:18:37 +00:00
/* clean seek state */
PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
zend_hash_clean(
&PHPDBG_G(seek));
2013-11-18 14:09:25 +00:00
2013-11-10 18:29:05 +00:00
zend_try {
php_output_activate(TSRMLS_C);
2013-11-23 17:09:52 +00:00
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
2013-11-13 14:22:01 +00:00
zend_execute(
EG(active_op_array) TSRMLS_CC);
2013-11-23 17:09:52 +00:00
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
php_output_deactivate(TSRMLS_C);
2013-11-10 18:29:05 +00:00
} zend_catch {
2013-11-13 14:22:01 +00:00
EG(active_op_array) = orig_op_array;
EG(opline_ptr) = orig_opline;
EG(return_value_ptr_ptr) = orig_retval_ptr;
2013-11-23 22:03:17 +00:00
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
2013-11-18 12:09:01 +00:00
phpdbg_error("Caught exit/error from VM");
goto out;
}
2013-11-10 18:29:05 +00:00
} zend_end_try();
2013-11-18 11:51:41 +00:00
if (EG(exception)) {
2013-11-18 17:00:26 +00:00
phpdbg_handle_exception(TSRMLS_C);
2013-11-18 11:51:41 +00:00
}
2013-11-13 21:31:33 +00:00
2013-11-18 11:51:41 +00:00
EG(active_op_array) = orig_op_array;
EG(opline_ptr) = orig_opline;
2013-11-18 14:09:25 +00:00
EG(return_value_ptr_ptr) = orig_retval_ptr;
2013-11-10 18:29:05 +00:00
} else {
phpdbg_error("Nothing to execute!");
2013-11-10 18:29:05 +00:00
}
2013-11-17 11:28:14 +00:00
out:
2013-11-22 22:15:04 +00:00
PHPDBG_FRAME(num) = 0;
return SUCCESS;
2013-11-10 14:43:46 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(eval) /* {{{ */
2013-11-10 18:29:05 +00:00
{
switch (param->type) {
case STR_PARAM: {
zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)==PHPDBG_IS_STEPPING);
zval retval;
2013-11-20 18:52:34 +00:00
if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
}
2013-11-20 18:52:34 +00:00
/* disable stepping while eval() in progress */
PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
2013-11-23 14:25:45 +00:00
zend_try {
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);
}
} zend_end_try();
PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
2013-11-17 11:28:14 +00:00
/* switch stepping back on */
if (stepping &&
!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
}
2013-11-23 15:34:36 +00:00
2013-11-23 14:25:45 +00:00
CG(unclean_shutdown) = 0;
} break;
2013-11-21 23:19:55 +00:00
phpdbg_default_switch_case();
2013-11-17 12:07:01 +00:00
}
2013-11-16 14:34:49 +00:00
2013-11-10 18:29:05 +00:00
return SUCCESS;
2013-11-10 15:16:45 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(back) /* {{{ */
2013-11-10 18:21:49 +00:00
{
2013-11-17 12:07:01 +00:00
if (!EG(in_execution)) {
phpdbg_error("Not executing!");
return SUCCESS;
}
2013-11-17 12:07:01 +00:00
switch (param->type) {
case EMPTY_PARAM:
case NUMERIC_PARAM: {
zval zbacktrace;
2013-11-22 17:27:55 +00:00
zval **tmp, **argstmp;
2013-11-17 12:07:01 +00:00
HashPosition position;
int i = 0,
limit = (param->type == NUMERIC_PARAM) ? param->num : 0;
2013-11-22 17:27:55 +00:00
zval **file, **line, **funcname, **class, **type, **args;
2013-11-22 23:30:26 +00:00
char is_class;
2013-11-22 17:27:55 +00:00
2013-11-17 12:07:01 +00:00
zend_fetch_debug_backtrace(
&zbacktrace, 0, 0, limit TSRMLS_CC);
2013-11-22 17:27:55 +00:00
zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position);
while (1) {
zend_hash_find(Z_ARRVAL_PP(tmp), "file", sizeof("file"), (void **)&file);
zend_hash_find(Z_ARRVAL_PP(tmp), "line", sizeof("line"), (void **)&line);
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == FAILURE) {
phpdbg_write(
"frame #%d {main} at %s:%d",
i, Z_STRVAL_PP(file), Z_LVAL_PP(line));
2013-11-22 17:27:55 +00:00
break;
2013-11-17 12:07:01 +00:00
}
2013-11-22 17:27:55 +00:00
zend_hash_find(Z_ARRVAL_PP(tmp), "function", sizeof("function"), (void **)&funcname);
if ((is_class = zend_hash_find(Z_ARRVAL_PP(tmp), "object", sizeof("object"), (void **)&class)) == FAILURE) {
is_class = zend_hash_find(Z_ARRVAL_PP(tmp), "class", sizeof("class"), (void **)&class);
} else {
2013-11-22 18:24:27 +00:00
zend_get_object_classname(*class, (const char **)&Z_STRVAL_PP(class), (zend_uint *)&Z_STRLEN_PP(class) TSRMLS_CC);
2013-11-22 17:27:55 +00:00
}
if (is_class) {
zend_hash_find(Z_ARRVAL_PP(tmp), "type", sizeof("type"), (void **)&type);
}
phpdbg_write(
2013-11-22 22:15:04 +00:00
"frame #%d: %s%s%s(",
i++, Z_STRVAL_PP(funcname),
is_class == FAILURE?"":Z_STRVAL_PP(type), is_class == FAILURE?"":Z_STRVAL_PP(class));
2013-11-22 17:27:55 +00:00
if (zend_hash_find(Z_ARRVAL_PP(tmp), "args", sizeof("args"), (void **)&args) == SUCCESS) {
HashPosition iterator;
int j = 0;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(args), &iterator);
while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(args), (void **) &argstmp, &iterator) == SUCCESS) {
if (j++) {
phpdbg_write(", ");
}
zend_print_flat_zval_r(*argstmp TSRMLS_CC);
zend_hash_move_forward_ex(Z_ARRVAL_PP(args), &iterator);
}
}
phpdbg_writeln(") at %s:%d", Z_STRVAL_PP(file), Z_LVAL_PP(line));
2013-11-17 12:07:01 +00:00
}
2013-11-17 11:28:14 +00:00
2013-11-17 12:07:01 +00:00
phpdbg_writeln(EMPTY);
zval_dtor(&zbacktrace);
} break;
phpdbg_default_switch_case();
}
return SUCCESS;
2013-11-10 15:16:45 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(print) /* {{{ */
2013-11-10 18:15:00 +00:00
{
2013-11-17 12:07:01 +00:00
switch (param->type) {
case EMPTY_PARAM: {
phpdbg_writeln(SEPARATE);
phpdbg_notice("Execution Context Information");
2013-11-12 08:26:11 +00:00
#ifdef HAVE_LIBREADLINE
2013-11-17 12:07:01 +00:00
phpdbg_writeln("Readline\tyes");
2013-11-12 08:26:11 +00:00
#else
2013-11-17 12:07:01 +00:00
phpdbg_writeln("Readline\tno");
2013-11-12 08:26:11 +00:00
#endif
2013-11-17 12:07:01 +00:00
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();
}
2013-11-10 18:15:00 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(info) /* {{{ */
2013-11-17 15:42:34 +00:00
{
2013-11-21 11:16:14 +00:00
phpdbg_error(
"No information command selected !");
2013-11-21 23:19:55 +00:00
2013-11-17 15:42:34 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(break) /* {{{ */
2013-11-10 14:36:30 +00:00
{
2013-11-16 14:34:49 +00:00
switch (param->type) {
case EMPTY_PARAM:
phpdbg_set_breakpoint_file(
zend_get_executed_filename(TSRMLS_C),
zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
break;
2013-11-13 23:13:41 +00:00
case ADDR_PARAM:
2013-11-16 14:34:49 +00:00
phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC);
2013-11-13 23:13:41 +00:00
break;
case NUMERIC_PARAM:
2013-11-16 14:34:49 +00:00
phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC);
2013-11-13 23:13:41 +00:00
break;
case METHOD_PARAM:
2013-11-16 14:34:49 +00:00
phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC);
2013-11-13 23:13:41 +00:00
break;
case FILE_PARAM:
2013-11-16 14:34:49 +00:00
phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC);
2013-11-14 00:30:03 +00:00
break;
2013-11-13 23:13:41 +00:00
case STR_PARAM:
2013-11-16 14:34:49 +00:00
phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC);
2013-11-13 23:13:41 +00:00
break;
2013-11-17 11:28:14 +00:00
phpdbg_default_switch_case();
2013-11-10 14:36:30 +00:00
}
2013-11-10 14:36:30 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(shell) /* {{{ */
2013-11-18 12:46:10 +00:00
{
/* don't allow this to loop, ever ... */
switch (param->type) {
case STR_PARAM: {
2013-11-20 13:43:58 +00:00
FILE *fd = NULL;
if ((fd=VCWD_POPEN((char*)param->str, "w"))) {
2013-11-18 12:46:10 +00:00
/* do something perhaps ?? do we want input ?? */
fclose(fd);
} else {
phpdbg_error(
"Failed to execute %s", param->str);
2013-11-18 12:46:10 +00:00
}
} break;
2013-11-18 14:09:25 +00:00
2013-11-18 12:46:10 +00:00
phpdbg_default_switch_case();
}
return SUCCESS;
2013-11-19 01:18:43 +00:00
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(register) /* {{{ */
2013-11-19 01:18:43 +00:00
{
switch (param->type) {
case STR_PARAM: {
zend_function *function;
char *lcname = zend_str_tolower_dup(param->str, param->len);
size_t lcname_len = strlen(lcname);
2013-11-19 01:30:57 +00:00
if (!zend_hash_exists(&PHPDBG_G(registered), lcname, lcname_len+1)) {
2013-11-19 01:18:43 +00:00
if (zend_hash_find(EG(function_table), lcname, lcname_len+1, (void**) &function) == SUCCESS) {
zend_hash_update(
&PHPDBG_G(registered), lcname, lcname_len+1, (void*)&function, sizeof(zend_function), NULL);
2013-11-19 01:18:43 +00:00
function_add_ref(function);
2013-11-19 01:30:57 +00:00
2013-11-19 01:18:43 +00:00
phpdbg_notice(
"Registered %s", lcname);
} else {
2013-11-19 17:18:58 +00:00
phpdbg_error("The requested function (%s) could not be found", param->str);
2013-11-19 01:18:43 +00:00
}
} else {
phpdbg_error(
"The requested name (%s) is already in use", lcname);
}
2013-11-19 21:40:01 +00:00
efree(lcname);
2013-11-19 01:18:43 +00:00
} break;
phpdbg_default_switch_case();
}
return SUCCESS;
} /* }}} */
2013-11-18 12:46:10 +00:00
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(quit) /* {{{ */
{
/* don't allow this to loop, ever ... */
2013-11-17 12:07:01 +00:00
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
2013-11-17 12:07:01 +00:00
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
zend_bailout();
}
2013-11-10 11:36:57 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(clean) /* {{{ */
{
2013-11-17 12:07:01 +00:00
if (EG(in_execution)) {
phpdbg_error("Cannot clean environment while executing");
return SUCCESS;
2013-11-13 21:43:54 +00:00
}
2013-11-13 21:31:33 +00:00
2013-11-13 21:43:54 +00:00
phpdbg_notice("Cleaning Execution Environment");
2013-11-13 21:43:54 +00:00
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)));
2013-11-13 21:43:54 +00:00
phpdbg_clean(1 TSRMLS_CC);
2013-11-13 21:31:33 +00:00
2013-11-17 12:07:01 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(clear) /* {{{ */
2013-11-11 13:31:41 +00:00
{
2013-11-17 12:07:01 +00:00
phpdbg_notice("Clearing Breakpoints");
2013-11-13 21:31:33 +00:00
2013-11-17 12:07:01 +00:00
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]));
2013-11-13 21:31:33 +00:00
2013-11-17 12:07:01 +00:00
phpdbg_clear_breakpoints(TSRMLS_C);
2013-11-11 22:02:34 +00:00
2013-11-11 13:31:41 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(aliases) /* {{{ */
2013-11-13 17:35:51 +00:00
{
2013-11-13 21:43:54 +00:00
const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
2013-11-17 12:07:01 +00:00
phpdbg_help_header();
phpdbg_writeln("Below are the aliased, short versions of all supported commands");
2013-11-13 21:43:54 +00:00
while (prompt_command && prompt_command->name) {
if (prompt_command->alias) {
if (prompt_command->subs) {
2013-11-17 12:07:01 +00:00
const phpdbg_command_t *sub_command = prompt_command->subs;
phpdbg_writeln(EMPTY);
2013-11-20 13:56:31 +00:00
phpdbg_writeln(" %c -> %9s", prompt_command->alias, prompt_command->name);
2013-11-17 12:07:01 +00:00
while (sub_command && sub_command->name) {
if (sub_command->alias) {
2013-11-20 13:51:47 +00:00
phpdbg_writeln(" |-------- %c -> %15s\t%s", sub_command->alias,
2013-11-17 12:07:01 +00:00
sub_command->name, sub_command->tip);
}
++sub_command;
}
phpdbg_writeln(EMPTY);
} else {
2013-11-20 13:56:31 +00:00
phpdbg_writeln(" %c -> %9s\t\t\t%s", prompt_command->alias,
2013-11-17 12:07:01 +00:00
prompt_command->name, prompt_command->tip);
}
2013-11-13 21:43:54 +00:00
}
2013-11-17 11:28:14 +00:00
2013-11-13 21:43:54 +00:00
++prompt_command;
2013-11-13 17:35:51 +00:00
}
2013-11-17 12:07:01 +00:00
phpdbg_help_footer();
2013-11-17 11:28:14 +00:00
2013-11-13 17:35:51 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(oplog) /* {{{ */
{
2013-11-17 12:07:01 +00:00
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 {
2013-11-21 11:16:14 +00:00
phpdbg_error("No oplog currently open !");
2013-11-17 12:07:01 +00:00
}
2013-11-21 11:16:14 +00:00
} else {
phpdbg_error(
"No action taken !");
2013-11-17 12:07:01 +00:00
}
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();
}
2013-11-17 11:28:14 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(help) /* {{{ */
{
switch (param->type) {
case EMPTY_PARAM: {
2013-11-17 12:07:01 +00:00
const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
const phpdbg_command_t *help_command = phpdbg_help_commands;
2013-11-13 21:31:33 +00:00
2013-11-17 12:07:01 +00:00
phpdbg_help_header();
phpdbg_writeln("To get help regarding a specific command type \"help command\"");
2013-11-17 12:07:01 +00:00
phpdbg_notice("Commands");
2013-11-17 12:07:01 +00:00
while (prompt_command && prompt_command->name) {
phpdbg_writeln(
" %10s\t%s", prompt_command->name, prompt_command->tip);
2013-11-17 12:07:01 +00:00
++prompt_command;
}
2013-11-13 21:31:33 +00:00
phpdbg_notice("Help Commands");
2013-11-17 12:07:01 +00:00
while (help_command && help_command->name) {
phpdbg_writeln(" %10s\t%s", help_command->name, help_command->tip);
2013-11-17 12:07:01 +00:00
++help_command;
}
2013-11-17 12:07:01 +00:00
phpdbg_help_footer();
} break;
2013-11-20 22:23:34 +00:00
default: {
phpdbg_error(
"No help can be found for the subject \"%s\"", param->str);
}
2013-11-17 12:07:01 +00:00
}
2013-11-10 18:21:49 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(quiet) /* {{{ */
{
2013-11-17 12:07:01 +00:00
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();
}
2013-11-17 11:28:14 +00:00
2013-11-10 21:23:18 +00:00
return SUCCESS;
} /* }}} */
2013-11-20 16:19:37 +00:00
PHPDBG_COMMAND(list) /* {{{ */
2013-11-11 23:40:03 +00:00
{
2013-11-16 23:11:39 +00:00
switch (param->type) {
case NUMERIC_PARAM:
2013-11-17 11:28:14 +00:00
case EMPTY_PARAM:
2013-11-20 13:28:41 +00:00
return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS);
2013-11-17 11:28:14 +00:00
2013-11-16 23:11:39 +00:00
case FILE_PARAM:
2013-11-20 13:28:41 +00:00
return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS);
2013-11-17 11:28:14 +00:00
case STR_PARAM:
2013-11-16 23:11:39 +00:00
phpdbg_list_function_byname(param->str, param->len TSRMLS_CC);
2013-11-17 11:28:14 +00:00
break;
2013-11-16 23:11:39 +00:00
case METHOD_PARAM:
2013-11-20 13:28:41 +00:00
return PHPDBG_LIST_HANDLER(method)(PHPDBG_COMMAND_ARGS);
2013-11-17 11:28:14 +00:00
2013-11-16 23:11:39 +00:00
phpdbg_default_switch_case();
}
2013-11-12 00:24:24 +00:00
return SUCCESS;
2013-11-11 23:40:03 +00:00
} /* }}} */
2013-11-20 13:29:58 +00:00
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
2013-11-19 10:56:50 +00:00
{
2013-11-19 21:54:58 +00:00
phpdbg_input_t *function = input->argv[0];
2013-11-20 12:10:27 +00:00
2013-11-19 21:54:58 +00:00
if (zend_hash_exists(
&PHPDBG_G(registered), function->string, function->length+1)) {
2013-11-20 12:10:27 +00:00
2013-11-19 21:54:58 +00:00
zval fname, *fretval;
2013-11-20 13:29:58 +00:00
zend_fcall_info fci;
2013-11-20 13:28:41 +00:00
2013-11-20 10:49:39 +00:00
ZVAL_STRINGL(&fname, function->string, function->length, 1);
2013-11-19 10:56:50 +00:00
2013-11-20 13:29:58 +00:00
memset(&fci, 0, sizeof(zend_fcall_info));
fci.size = sizeof(zend_fcall_info);
fci.function_table = &PHPDBG_G(registered);
fci.function_name = &fname;
fci.symbol_table = EG(active_symbol_table);
fci.object_ptr = NULL;
fci.retval_ptr_ptr = &fretval;
fci.no_separation = 1;
2013-11-20 13:28:41 +00:00
2013-11-19 21:54:58 +00:00
if (input->argc > 1) {
int param;
zval params;
2013-11-20 13:28:41 +00:00
array_init(&params);
2013-11-20 13:28:41 +00:00
for (param = 0; param < (input->argc-1); param++) {
add_next_index_stringl(
2013-11-20 13:28:41 +00:00
&params,
input->argv[param+1]->string,
input->argv[param+1]->length, 1);
2013-11-20 13:28:41 +00:00
phpdbg_debug(
2013-11-20 13:28:41 +00:00
"created param[%d] from argv[%d]: %s",
param, param+1, input->argv[param+1]->string);
2013-11-19 21:54:58 +00:00
}
2013-11-20 13:28:41 +00:00
2013-11-20 13:29:58 +00:00
zend_fcall_info_args(&fci, &params TSRMLS_CC);
} else {
2013-11-20 13:29:58 +00:00
fci.params = NULL;
fci.param_count = 0;
2013-11-19 10:56:50 +00:00
}
2013-11-20 13:28:41 +00:00
phpdbg_debug(
2013-11-23 15:34:36 +00:00
"created %d params from %d arguments",
2013-11-20 13:29:58 +00:00
fci.param_count, input->argc);
2013-11-20 13:28:41 +00:00
2013-11-20 13:29:58 +00:00
zend_call_function(&fci, NULL TSRMLS_CC);
2013-11-20 13:28:41 +00:00
2013-11-19 10:56:50 +00:00
if (fretval) {
zend_print_zval_r(
fretval, 0 TSRMLS_CC);
phpdbg_writeln(EMPTY);
}
2013-11-20 12:10:27 +00:00
2013-11-20 10:49:39 +00:00
zval_dtor(&fname);
2013-11-20 12:10:27 +00:00
2013-11-19 10:56:50 +00:00
return SUCCESS;
}
2013-11-19 21:40:01 +00:00
2013-11-19 10:56:50 +00:00
return FAILURE;
} /* }}} */
2013-11-19 10:56:50 +00:00
int phpdbg_interactive(TSRMLS_D) /* {{{ */
{
2013-11-17 12:07:01 +00:00
int ret = SUCCESS;
2013-11-22 20:42:57 +00:00
phpdbg_input_t *input;
2013-11-22 22:15:04 +00:00
PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE;
2013-11-19 21:40:01 +00:00
2013-11-22 20:42:57 +00:00
input = phpdbg_read_input(NULL TSRMLS_CC);
2013-11-22 22:15:04 +00:00
2013-11-19 14:06:33 +00:00
if (input && input->length > 0L) {
2013-11-19 13:22:46 +00:00
do {
2013-11-20 10:04:05 +00:00
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) {
2013-11-19 13:22:46 +00:00
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {
phpdbg_error("Failed to execute %s!", input->string);
}
2013-11-17 12:07:01 +00:00
}
2013-11-19 13:22:46 +00:00
break;
2013-11-13 21:31:33 +00:00
2013-11-19 13:22:46 +00:00
case PHPDBG_LEAVE:
case PHPDBG_FINISH:
case PHPDBG_UNTIL:
case PHPDBG_NEXT: {
if (!EG(in_execution)) {
phpdbg_error("Not running");
}
goto out;
}
2013-11-18 17:51:14 +00:00
}
2013-11-19 21:40:01 +00:00
2013-11-19 19:24:21 +00:00
phpdbg_destroy_input(&input TSRMLS_CC);
2013-11-20 10:04:05 +00:00
} while ((input = phpdbg_read_input(NULL TSRMLS_CC)) && (input->length > 0L));
2013-11-19 21:40:01 +00:00
2013-11-20 10:04:05 +00:00
if (input && !input->length)
2013-11-19 14:06:33 +00:00
goto last;
} else {
2013-11-19 14:06:33 +00:00
last:
if (PHPDBG_G(lcmd)) {
ret = PHPDBG_G(lcmd)->handler(
2013-11-20 13:28:41 +00:00
&PHPDBG_G(lparam), input TSRMLS_CC);
goto out;
}
}
2013-11-17 12:07:01 +00:00
2013-11-16 12:02:35 +00:00
out:
2013-11-19 19:24:21 +00:00
phpdbg_destroy_input(&input TSRMLS_CC);
2013-11-22 18:16:25 +00:00
if (EG(in_execution)) {
phpdbg_restore_frame(TSRMLS_C);
2013-11-22 18:16:25 +00:00
}
PHPDBG_G(flags) &= ~PHPDBG_IS_INTERACTIVE;
2013-11-12 09:52:59 +00:00
2013-11-16 12:02:35 +00:00
return ret;
2013-11-21 13:35:39 +00:00
} /* }}} */
2013-11-12 09:52:59 +00:00
void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
{
2013-11-17 12:07:01 +00:00
/* this is implicitly required */
if (PHPDBG_G(ops)) {
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
efree(PHPDBG_G(ops));
PHPDBG_G(ops) = NULL;
}
2013-11-12 09:52:59 +00:00
2013-11-18 01:05:14 +00:00
if (full) {
2013-11-17 12:07:01 +00:00
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
2013-11-17 12:07:01 +00:00
zend_bailout();
}
2013-11-10 18:05:11 +00:00
} /* }}} */
2013-11-15 11:19:26 +00:00
static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 50500
return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC);
#else
#undef EX
#define EX(element) execute_data->element
#undef EX_CV
#define EX_CV(var) EX(CVs)[var]
#undef EX_CVs
#define EX_CVs() EX(CVs)
#undef EX_T
#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
#undef EX_Ts
#define EX_Ts() EX(Ts)
zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc(
ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) +
ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)) +
ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)) * op_array->T TSRMLS_CC);
EX(CVs) = (zval***)((char*)execute_data + ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)));
memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
EX(Ts) = (temp_variable *)(((char*)EX(CVs)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)));
EX(fbc) = NULL;
EX(called_scope) = NULL;
EX(object) = NULL;
EX(old_error_reporting) = NULL;
EX(op_array) = op_array;
EX(symbol_table) = EG(active_symbol_table);
EX(prev_execute_data) = EG(current_execute_data);
EG(current_execute_data) = execute_data;
EX(nested) = nested;
if (!op_array->run_time_cache && op_array->last_cache_slot) {
op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*));
}
if (op_array->this_var != -1 && EG(This)) {
Z_ADDREF_P(EG(This)); /* For $this pointer */
if (!EG(active_symbol_table)) {
EX_CV(op_array->this_var) = (zval**)EX_CVs() + (op_array->last_var + op_array->this_var);
*EX_CV(op_array->this_var) = EG(This);
} else {
if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), (void**)&EX_CV(op_array->this_var))==FAILURE) {
Z_DELREF_P(EG(This));
}
}
}
EX(opline) = UNEXPECTED((op_array->fn_flags & ZEND_ACC_INTERACTIVE) != 0) && EG(start_op) ? EG(start_op) : op_array->opcodes;
EG(opline_ptr) = &EX(opline);
EX(function_state).function = (zend_function *) op_array;
EX(function_state).arguments = NULL;
2013-11-15 11:19:26 +00:00
return execute_data;
#endif
} /* }}} */
#if PHP_VERSION_ID >= 50500
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-15 11:19:26 +00:00
#else
void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
2013-11-18 03:18:37 +00:00
long long flags = 0;
zend_ulong address = 0L;
2013-11-17 12:07:01 +00:00
zend_execute_data *execute_data;
zend_bool nested = 0;
2013-11-15 11:19:26 +00:00
#endif
2013-11-10 15:16:45 +00:00
zend_bool original_in_execution = EG(in_execution);
2013-11-21 13:35:39 +00:00
HashTable vars;
2013-11-21 23:19:55 +00:00
2013-11-15 11:19:26 +00:00
#if PHP_VERSION_ID < 50500
2013-11-17 12:07:01 +00:00
if (EG(exception)) {
return;
}
2013-11-15 11:19:26 +00:00
#endif
2013-11-10 13:01:46 +00:00
EG(in_execution) = 1;
2013-11-15 11:19:26 +00:00
#if PHP_VERSION_ID >= 50500
2013-11-10 13:01:46 +00:00
if (0) {
zend_vm_enter:
2013-11-15 11:19:26 +00:00
execute_data = phpdbg_create_execute_data(EG(active_op_array), 1 TSRMLS_CC);
2013-11-10 13:01:46 +00:00
}
2013-11-21 13:35:39 +00:00
zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
2013-11-15 11:19:26 +00:00
#else
zend_vm_enter:
2013-11-21 13:35:39 +00:00
execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
nested = 1;
zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
2013-11-15 11:19:26 +00:00
#endif
2013-11-10 13:01:46 +00:00
while (1) {
#ifdef ZEND_WIN32
if (EG(timed_out)) {
zend_timeout(0);
}
#endif
#define DO_INTERACTIVE() do {\
2013-11-20 17:01:37 +00:00
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {\
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\
);\
}\
2013-11-17 12:07:01 +00:00
\
do {\
2013-11-18 01:44:46 +00:00
switch (phpdbg_interactive(TSRMLS_C)) {\
2013-11-17 15:39:23 +00:00
case PHPDBG_LEAVE:\
2013-11-17 13:59:21 +00:00
case PHPDBG_FINISH:\
2013-11-17 12:07:01 +00:00
case PHPDBG_UNTIL:\
case PHPDBG_NEXT:{\
goto next;\
}\
}\
} while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));\
} while(0)
2013-11-20 18:52:34 +00:00
/* allow conditional breakpoints and
initialization to access the vm uninterrupted */
2013-11-20 17:48:54 +00:00
if ((PHPDBG_G(flags) & PHPDBG_IN_COND_BP) ||
(PHPDBG_G(flags) & PHPDBG_IS_INITIALIZING)) {
/* skip possible breakpoints */
goto next;
}
2013-11-17 16:10:43 +00:00
/* perform seek operation */
if (PHPDBG_G(flags) & PHPDBG_SEEK_MASK) {
2013-11-18 03:18:37 +00:00
/* current address */
zend_ulong address = (zend_ulong) execute_data->opline;
2013-11-18 14:09:25 +00:00
/* run to next line */
if (PHPDBG_G(flags) & PHPDBG_IN_UNTIL) {
2013-11-18 03:18:37 +00:00
if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
PHPDBG_G(flags) &= ~PHPDBG_IN_UNTIL;
2013-11-18 03:18:37 +00:00
zend_hash_clean(
&PHPDBG_G(seek));
} else {
/* skip possible breakpoints */
goto next;
}
2013-11-17 13:59:21 +00:00
}
2013-11-17 16:10:43 +00:00
/* run to finish */
if (PHPDBG_G(flags) & PHPDBG_IN_FINISH) {
2013-11-18 03:18:37 +00:00
if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
PHPDBG_G(flags) &= ~PHPDBG_IN_FINISH;
2013-11-18 03:18:37 +00:00
zend_hash_clean(
&PHPDBG_G(seek));
}
2013-11-17 13:59:21 +00:00
/* skip possible breakpoints */
goto next;
}
2013-11-18 14:09:25 +00:00
/* break for leave */
if (PHPDBG_G(flags) & PHPDBG_IN_LEAVE) {
2013-11-18 03:18:37 +00:00
if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
PHPDBG_G(flags) &= ~PHPDBG_IN_LEAVE;
2013-11-18 03:18:37 +00:00
zend_hash_clean(
&PHPDBG_G(seek));
phpdbg_notice(
"Breaking for leave at %s:%u",
zend_get_executed_filename(TSRMLS_C),
zend_get_executed_lineno(TSRMLS_C)
);
DO_INTERACTIVE();
} else {
/* skip possible breakpoints */
goto next;
}
}
2013-11-17 13:59:21 +00:00
}
2013-11-13 21:31:33 +00:00
/* not while in conditionals */
2013-11-21 13:35:39 +00:00
phpdbg_print_opline_ex(
execute_data, &vars, 0 TSRMLS_CC);
2013-11-17 16:10:43 +00:00
/* conditions cannot be executed by eval()'d code */
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)
&& (PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)
&& phpdbg_find_conditional_breakpoint(TSRMLS_C) == SUCCESS) {
DO_INTERACTIVE();
}
if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)
&& phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC) == SUCCESS) {
DO_INTERACTIVE();
}
if ((PHPDBG_G(flags) & (PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_SYM_BP))) {
/* check we are at the beginning of the stack */
if (execute_data->opline == EG(active_op_array)->opcodes) {
if (phpdbg_find_breakpoint_symbol(
execute_data->function_state.function TSRMLS_CC) == SUCCESS) {
DO_INTERACTIVE();
}
}
}
2013-11-23 22:03:17 +00:00
if (PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP
&& phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC) == SUCCESS) {
DO_INTERACTIVE();
}
2013-11-23 23:14:16 +00:00
if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP
&& phpdbg_find_breakpoint_opcode(execute_data->opline->opcode TSRMLS_CC) == SUCCESS) {
2013-11-23 22:03:17 +00:00
DO_INTERACTIVE();
}
if (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) {
DO_INTERACTIVE();
}
2013-11-11 17:12:31 +00:00
2013-11-14 16:14:20 +00:00
next:
if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
phpdbg_writeln(EMPTY);
phpdbg_notice("Program received signal SIGINT");
PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
DO_INTERACTIVE();
}
2013-11-21 23:19:55 +00:00
PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
2013-11-17 12:07:01 +00:00
if (PHPDBG_G(vmret) > 0) {
switch (PHPDBG_G(vmret)) {
case 1:
EG(in_execution) = original_in_execution;
2013-11-21 13:35:39 +00:00
zend_hash_destroy(&vars);
2013-11-17 12:07:01 +00:00
return;
case 2:
2013-11-15 11:19:26 +00:00
#if PHP_VERSION_ID < 50500
2013-11-17 12:07:01 +00:00
op_array = EG(active_op_array);
2013-11-15 11:19:26 +00:00
#endif
2013-11-21 13:35:39 +00:00
zend_hash_destroy(&vars);
2013-11-17 12:07:01 +00:00
goto zend_vm_enter;
break;
case 3:
execute_data = EG(current_execute_data);
break;
default:
2013-11-10 13:01:46 +00:00
break;
}
}
}
zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
2013-11-10 18:21:49 +00:00
} /* }}} */