mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00
+compile
This commit is contained in:
parent
6df19b3aa2
commit
b978c20f63
5 changed files with 92 additions and 18 deletions
7
phpdbg.c
7
phpdbg.c
|
@ -22,6 +22,7 @@ ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
|
||||||
|
|
||||||
static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) {
|
static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) {
|
||||||
pg->exec = NULL;
|
pg->exec = NULL;
|
||||||
|
pg->ops = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PHP_MINIT_FUNCTION(phpdbg) {
|
static PHP_MINIT_FUNCTION(phpdbg) {
|
||||||
|
@ -42,9 +43,15 @@ static PHP_RINIT_FUNCTION(phpdbg) {
|
||||||
|
|
||||||
static PHP_RSHUTDOWN_FUNCTION(phpdbg) {
|
static PHP_RSHUTDOWN_FUNCTION(phpdbg) {
|
||||||
zend_hash_destroy(&PHPDBG_G(breaks));
|
zend_hash_destroy(&PHPDBG_G(breaks));
|
||||||
|
|
||||||
if (PHPDBG_G(exec)) {
|
if (PHPDBG_G(exec)) {
|
||||||
efree(PHPDBG_G(exec));
|
efree(PHPDBG_G(exec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PHPDBG_G(ops)) {
|
||||||
|
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
|
||||||
|
efree(PHPDBG_G(ops));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static zend_module_entry sapi_phpdbg_module_entry = {
|
static zend_module_entry sapi_phpdbg_module_entry = {
|
||||||
|
|
5
phpdbg.h
5
phpdbg.h
|
@ -38,8 +38,9 @@
|
||||||
|
|
||||||
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
||||||
HashTable breaks;
|
HashTable breaks;
|
||||||
char *exec; /* file to execute */
|
char *exec; /* file to execute */
|
||||||
size_t exec_len; /* size of exec */
|
size_t exec_len; /* size of exec */
|
||||||
|
zend_op_array *ops; /* op_array */
|
||||||
ZEND_END_MODULE_GLOBALS(phpdbg)
|
ZEND_END_MODULE_GLOBALS(phpdbg)
|
||||||
|
|
||||||
#include "phpdbg_prompt.h"
|
#include "phpdbg_prompt.h"
|
||||||
|
|
|
@ -25,21 +25,35 @@
|
||||||
|
|
||||||
PHPDBG_HELP(exec) /* {{{ */
|
PHPDBG_HELP(exec) /* {{{ */
|
||||||
{
|
{
|
||||||
printf("doing exec help: %s\n", expr);
|
printf("Will attempt execution, if compilation has not yet taken place, it occurs now.\n");
|
||||||
|
printf("The execution context must be set before execution can take place\n");
|
||||||
|
return SUCCESS;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
PHPDBG_HELP(compile) /* {{{ */
|
||||||
|
{
|
||||||
|
printf("Pre-compilation of the execution context provides the opportunity to inspect the opcodes before they are executed\n");
|
||||||
|
printf("The execution context must be set for compilation to succeed\n");
|
||||||
|
printf("If errors occur during compilation they must be resolved before execution can take place.\n");
|
||||||
|
printf("You do not need to exit phpdbg to retry compilation\n");
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
PHPDBG_HELP(print) /* {{{ */
|
PHPDBG_HELP(print) /* {{{ */
|
||||||
{
|
{
|
||||||
printf("doing print help: %s\n", expr);
|
printf("By default, print will show information about the current execution environment\n");
|
||||||
|
printf("To show specific information pass an expression to print, for example:\n");
|
||||||
|
printf("\tprint opcodes[0]\n");
|
||||||
|
printf("Will show the opline @ 0\n");
|
||||||
|
printf("Available print commands:\n");
|
||||||
|
printf("\tNone\n");
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
PHPDBG_HELP(brake) /* {{{ */
|
PHPDBG_HELP(brake) /* {{{ */
|
||||||
{
|
{
|
||||||
printf("doing brake help: %s\n", expr);
|
printf("doing brake help: %s\n", expr);
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
* Helper Forward Declarations
|
* Helper Forward Declarations
|
||||||
*/
|
*/
|
||||||
PHPDBG_HELP(exec);
|
PHPDBG_HELP(exec);
|
||||||
|
PHPDBG_HELP(compile);
|
||||||
PHPDBG_HELP(print);
|
PHPDBG_HELP(print);
|
||||||
PHPDBG_HELP(brake);
|
PHPDBG_HELP(brake);
|
||||||
|
|
||||||
|
@ -39,9 +40,10 @@ PHPDBG_HELP(brake);
|
||||||
* Commands
|
* Commands
|
||||||
*/
|
*/
|
||||||
static const phpdbg_command_t phpdbg_help_commands[] = {
|
static const phpdbg_command_t phpdbg_help_commands[] = {
|
||||||
PHPDBG_HELP_D(exec, "the execution context should be a valid phpdbg path"),
|
PHPDBG_HELP_D(exec, "the execution context should be a valid phpdbg path"),
|
||||||
PHPDBG_HELP_D(print, "printing allows inspection of the execution environment"),
|
PHPDBG_HELP_D(compile, "pre-compilation allows inspection of code before execution"),
|
||||||
PHPDBG_HELP_D(brake, "brake points allow execution interruption"),
|
PHPDBG_HELP_D(print, "printing allows inspection of the execution environment"),
|
||||||
|
PHPDBG_HELP_D(brake, "brake points allow execution interruption"),
|
||||||
{NULL, 0, 0}
|
{NULL, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,15 @@ static PHPDBG_COMMAND(exec) { /* {{{ */
|
||||||
printf(
|
printf(
|
||||||
"Unsetting old execution context: %s\n", PHPDBG_G(exec));
|
"Unsetting old execution context: %s\n", PHPDBG_G(exec));
|
||||||
efree(PHPDBG_G(exec));
|
efree(PHPDBG_G(exec));
|
||||||
|
PHPDBG_G(exec) = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHPDBG_G(ops)) {
|
||||||
|
printf(
|
||||||
|
"Destroying compiled opcodes\n");
|
||||||
|
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
|
||||||
|
efree(PHPDBG_G(ops));
|
||||||
|
PHPDBG_G(ops) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHPDBG_G(exec) = estrndup(
|
PHPDBG_G(exec) = estrndup(
|
||||||
|
@ -39,11 +48,51 @@ static PHPDBG_COMMAND(exec) { /* {{{ */
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
"Set execution context: %s\n", PHPDBG_G(exec));
|
"Set execution context: %s\n", PHPDBG_G(exec));
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
static PHPDBG_COMMAND(compile) { /* {{{ */
|
||||||
|
zend_file_handle fh;
|
||||||
|
|
||||||
|
if (PHPDBG_G(exec)) {
|
||||||
|
|
||||||
|
if (PHPDBG_G(ops)) {
|
||||||
|
printf("Destroying compiled opcodes\n");
|
||||||
|
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
|
||||||
|
efree(PHPDBG_G(ops));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Attempting compilation of %s\n", PHPDBG_G(exec));
|
||||||
|
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);
|
||||||
|
printf("Success\n");
|
||||||
|
return SUCCESS;
|
||||||
|
} else {
|
||||||
|
printf("Could not open file %s\n", PHPDBG_G(exec));
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("No execution context\n");
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
static PHPDBG_COMMAND(print) { /* {{{ */
|
static PHPDBG_COMMAND(print) { /* {{{ */
|
||||||
printf(
|
if (!expr_len) {
|
||||||
"%s\n", expr);
|
printf("Showing Execution Context Information:\n");
|
||||||
|
printf("Exec\t\t%s\n", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
|
||||||
|
printf("Compiled\t%s\n", PHPDBG_G(ops) ? "yes" : "no");
|
||||||
|
if (PHPDBG_G(ops)) {
|
||||||
|
printf("Opcodes\t\t%d\n", PHPDBG_G(ops)->last-1);
|
||||||
|
printf("Variables\t%d\n", PHPDBG_G(ops)->last_var-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf(
|
||||||
|
"%s\n", expr);
|
||||||
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
@ -93,11 +142,12 @@ static PHPDBG_COMMAND(help) /* {{{ */
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
static const phpdbg_command_t phpdbg_prompt_commands[] = {
|
static const phpdbg_command_t phpdbg_prompt_commands[] = {
|
||||||
PHPDBG_COMMAND_D(exec, "set execution context"),
|
PHPDBG_COMMAND_D(exec, "set execution context"),
|
||||||
PHPDBG_COMMAND_D(print, "print something"),
|
PHPDBG_COMMAND_D(compile, "attempt to pre-compile execution context"),
|
||||||
PHPDBG_COMMAND_D(brake, "set brake point"),
|
PHPDBG_COMMAND_D(print, "print something"),
|
||||||
PHPDBG_COMMAND_D(help, "show help menu"),
|
PHPDBG_COMMAND_D(brake, "set brake point"),
|
||||||
PHPDBG_COMMAND_D(quit, "exit phpdbg"),
|
PHPDBG_COMMAND_D(help, "show help menu"),
|
||||||
|
PHPDBG_COMMAND_D(quit, "exit phpdbg"),
|
||||||
{NULL, 0, 0}
|
{NULL, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue