mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
- Initial code for breakpoint on function
This commit is contained in:
parent
8532076c64
commit
16930d85f8
4 changed files with 82 additions and 15 deletions
5
phpdbg.h
5
phpdbg.h
|
@ -40,8 +40,8 @@
|
||||||
#define PHPDBG_NEXT 2
|
#define PHPDBG_NEXT 2
|
||||||
|
|
||||||
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
||||||
HashTable break_files;
|
HashTable bp_files;
|
||||||
HashTable break_symbols;
|
HashTable bp_symbols;
|
||||||
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_op_array *ops; /* op_array */
|
||||||
|
@ -49,6 +49,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
||||||
zend_bool stepping; /* stepping */
|
zend_bool stepping; /* stepping */
|
||||||
int vmret; /* return from last opcode handler execution */
|
int vmret; /* return from last opcode handler execution */
|
||||||
zend_bool has_file_bp; /* file-based breakpoint has been set */
|
zend_bool has_file_bp; /* file-based breakpoint has been set */
|
||||||
|
zend_bool has_sym_bp; /* symbol-based breakpoint has been set */
|
||||||
ZEND_END_MODULE_GLOBALS(phpdbg)
|
ZEND_END_MODULE_GLOBALS(phpdbg)
|
||||||
|
|
||||||
#include "phpdbg_prompt.h"
|
#include "phpdbg_prompt.h"
|
||||||
|
|
|
@ -35,6 +35,13 @@ static void phpdbg_llist_breakfile_dtor(void *data)
|
||||||
efree((char*)bp->filename);
|
efree((char*)bp->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void phpdbg_llist_breaksym_dtor(void *data)
|
||||||
|
{
|
||||||
|
phpdbg_breaksymbol_t *bp = (phpdbg_breaksymbol_t*) data;
|
||||||
|
|
||||||
|
efree((char*)bp->symbol);
|
||||||
|
}
|
||||||
|
|
||||||
static PHPDBG_COMMAND(exec) { /* {{{ */
|
static PHPDBG_COMMAND(exec) { /* {{{ */
|
||||||
if (PHPDBG_G(exec)) {
|
if (PHPDBG_G(exec)) {
|
||||||
printf(
|
printf(
|
||||||
|
@ -154,10 +161,10 @@ static PHPDBG_COMMAND(back) { /* {{{ */
|
||||||
HashPosition position;
|
HashPosition position;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int limit = (expr != NULL) ? atoi(expr) : 0;
|
int limit = (expr != NULL) ? atoi(expr) : 0;
|
||||||
|
|
||||||
zend_fetch_debug_backtrace(
|
zend_fetch_debug_backtrace(
|
||||||
&zbacktrace, 0, 0, limit TSRMLS_CC);
|
&zbacktrace, 0, 0, limit TSRMLS_CC);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
|
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_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == SUCCESS;
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position)) {
|
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position)) {
|
||||||
|
@ -166,11 +173,11 @@ static PHPDBG_COMMAND(back) { /* {{{ */
|
||||||
}
|
}
|
||||||
zend_print_flat_zval_r(*tmp TSRMLS_CC);
|
zend_print_flat_zval_r(*tmp TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
zval_dtor(&zbacktrace);
|
zval_dtor(&zbacktrace);
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
printf("Not executing !\n");
|
printf("Not executing !\n");
|
||||||
|
@ -226,18 +233,42 @@ static PHPDBG_COMMAND(break) /* {{{ */
|
||||||
|
|
||||||
PHPDBG_G(has_file_bp) = 1;
|
PHPDBG_G(has_file_bp) = 1;
|
||||||
|
|
||||||
if (zend_hash_find(&PHPDBG_G(break_files),
|
if (zend_hash_find(&PHPDBG_G(bp_files),
|
||||||
new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
|
new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
|
||||||
zend_llist break_files;
|
zend_llist break_files;
|
||||||
|
|
||||||
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
|
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
|
||||||
phpdbg_llist_breakfile_dtor, 0);
|
phpdbg_llist_breakfile_dtor, 0);
|
||||||
|
|
||||||
zend_hash_update(&PHPDBG_G(break_files),
|
zend_hash_update(&PHPDBG_G(bp_files),
|
||||||
new_break.filename, name_len, &break_files, sizeof(zend_llist),
|
new_break.filename, name_len, &break_files, sizeof(zend_llist),
|
||||||
(void**)&break_files_ptr);
|
(void**)&break_files_ptr);
|
||||||
}
|
}
|
||||||
zend_llist_add_element(break_files_ptr, &new_break);
|
zend_llist_add_element(break_files_ptr, &new_break);
|
||||||
|
} else {
|
||||||
|
const char *opline_num_pos = zend_memrchr(expr, '#', expr_len);
|
||||||
|
long opline_num = opline_num_pos ? strtol(opline_num_pos+1, NULL, 0) : 0;
|
||||||
|
phpdbg_breaksymbol_t new_break;
|
||||||
|
zend_llist *break_sym_ptr;
|
||||||
|
size_t name_len = opline_num_pos ? opline_num_pos - expr : strlen(expr);
|
||||||
|
|
||||||
|
new_break.symbol = estrndup(expr, name_len);
|
||||||
|
new_break.opline_num = opline_num;
|
||||||
|
|
||||||
|
PHPDBG_G(has_sym_bp) = 1;
|
||||||
|
|
||||||
|
if (zend_hash_find(&PHPDBG_G(bp_symbols),
|
||||||
|
new_break.symbol, name_len, (void**)&break_sym_ptr) == FAILURE) {
|
||||||
|
zend_llist break_syms;
|
||||||
|
|
||||||
|
zend_llist_init(&break_syms, sizeof(phpdbg_breaksymbol_t),
|
||||||
|
phpdbg_llist_breaksym_dtor, 0);
|
||||||
|
|
||||||
|
zend_hash_update(&PHPDBG_G(bp_symbols),
|
||||||
|
new_break.symbol, name_len, &break_syms, sizeof(zend_llist),
|
||||||
|
(void**)&break_sym_ptr);
|
||||||
|
}
|
||||||
|
zend_llist_add_element(break_sym_ptr, &new_break);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
@ -316,12 +347,12 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
int phpdbg_breakpoint(zend_op_array *op_array TSRMLS_DC) /* {{{ */
|
int phpdbg_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
size_t name_len = strlen(op_array->filename);
|
size_t name_len = strlen(op_array->filename);
|
||||||
zend_llist *break_list;
|
zend_llist *break_list;
|
||||||
|
|
||||||
if (zend_hash_find(&PHPDBG_G(break_files), op_array->filename, name_len,
|
if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
|
||||||
(void**)&break_list) == SUCCESS) {
|
(void**)&break_list) == SUCCESS) {
|
||||||
zend_llist_element *le;
|
zend_llist_element *le;
|
||||||
|
|
||||||
|
@ -338,6 +369,30 @@ int phpdbg_breakpoint(zend_op_array *op_array TSRMLS_DC) /* {{{ */
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
int phpdbg_breakpoint_symbol(zend_function *fbc TSRMLS_DC)
|
||||||
|
{
|
||||||
|
const char *fname;
|
||||||
|
zend_llist *break_list;
|
||||||
|
|
||||||
|
if (fbc->type != ZEND_USER_FUNCTION) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fname = ((zend_op_array*)fbc)->function_name;
|
||||||
|
|
||||||
|
if (!fname) {
|
||||||
|
fname = "main";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
|
||||||
|
(void**)&break_list) == SUCCESS) {
|
||||||
|
printf("breakpoint reached!\n");
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
int phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
|
int phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
char cmd[PHPDBG_MAX_CMD];
|
char cmd[PHPDBG_MAX_CMD];
|
||||||
|
@ -389,7 +444,15 @@ zend_vm_enter:
|
||||||
printf("[OPLINE: %p]\n", execute_data->opline);
|
printf("[OPLINE: %p]\n", execute_data->opline);
|
||||||
|
|
||||||
if (PHPDBG_G(has_file_bp)
|
if (PHPDBG_G(has_file_bp)
|
||||||
&& phpdbg_breakpoint(execute_data->op_array TSRMLS_CC) == SUCCESS) {
|
&& phpdbg_breakpoint_file(execute_data->op_array TSRMLS_CC) == SUCCESS) {
|
||||||
|
while (phpdbg_interactive(0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHPDBG_G(has_sym_bp)
|
||||||
|
&& (execute_data->opline->opcode == ZEND_DO_FCALL || execute_data->opline->opcode == ZEND_DO_FCALL_BY_NAME)
|
||||||
|
&& phpdbg_breakpoint_symbol(execute_data->function_state.function TSRMLS_CC) == SUCCESS) {
|
||||||
while (phpdbg_interactive(0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
|
while (phpdbg_interactive(0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ typedef struct _phpdbg_breakfile_t {
|
||||||
*/
|
*/
|
||||||
typedef struct _phpdbg_breaksymbol_t {
|
typedef struct _phpdbg_breaksymbol_t {
|
||||||
const char *symbol;
|
const char *symbol;
|
||||||
|
long opline_num;
|
||||||
} phpdbg_breaksymbol_t;
|
} phpdbg_breaksymbol_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
8
test.php
8
test.php
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
echo "Hello World\n";
|
function test() {
|
||||||
if (isset($greeting)) {
|
echo "Hello World\n";
|
||||||
echo $greeting;
|
}
|
||||||
|
if (!isset($greeting)) {
|
||||||
|
echo test();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue