mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
Merge branch 'master' of https://github.com/krakjoe/phpdbg
This commit is contained in:
commit
38883e7cbb
@ -9,7 +9,7 @@ if test "$PHP_PHPDBG" != "no"; then
|
||||
AC_DEFINE(HAVE_PHPDBG, 1, [ ])
|
||||
|
||||
PHP_PHPDBG_CFLAGS=-I$abs_srcdir/sapi/phpdbg
|
||||
PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c"
|
||||
PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c"
|
||||
|
||||
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/phpdbg/Makefile.frag])
|
||||
PHP_SELECT_SAPI(phpdbg, program, $PHP_PHPDBG_FILES, $PHP_PHPDBG_CFLAGS, [$(SAPI_PHPDBG_PATH)])
|
||||
|
6
phpdbg.h
6
phpdbg.h
@ -15,6 +15,10 @@
|
||||
| Authors: Joe Watkins <joe.watkins@live.co.uk> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHPDBG_H
|
||||
#define PHPDBG_H
|
||||
|
||||
#include "php.h"
|
||||
#include "php_globals.h"
|
||||
#include "php_variables.h"
|
||||
@ -54,4 +58,4 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
|
||||
zend_bool quitting; /* quitting flag */
|
||||
ZEND_END_MODULE_GLOBALS(phpdbg)
|
||||
|
||||
#include "phpdbg_prompt.h"
|
||||
#endif /* PHPDBG_H */
|
||||
|
147
phpdbg_bp.c
Normal file
147
phpdbg_bp.c
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| 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 "zend.h"
|
||||
#include "zend_hash.h"
|
||||
#include "phpdbg.h"
|
||||
#include "phpdbg_bp.h"
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
|
||||
|
||||
static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */
|
||||
{
|
||||
phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
|
||||
|
||||
efree((char*)bp->filename);
|
||||
} /* }}} */
|
||||
|
||||
static void phpdbg_llist_breaksym_dtor(void *data) /* {{{ */
|
||||
{
|
||||
phpdbg_breaksymbol_t *bp = (phpdbg_breaksymbol_t*) data;
|
||||
|
||||
efree((char*)bp->symbol);
|
||||
} /* }}} */
|
||||
|
||||
void phpdbg_set_breakpoint_file(const char *expr, const char *line_pos TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
char resolved_name[MAXPATHLEN];
|
||||
long line_num = strtol(line_pos+1, NULL, 0);
|
||||
phpdbg_breakfile_t new_break;
|
||||
zend_llist *break_files_ptr;
|
||||
size_t name_len;
|
||||
char *path = estrndup(expr, line_pos - expr);
|
||||
|
||||
if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
|
||||
efree(path);
|
||||
return;
|
||||
}
|
||||
efree(path);
|
||||
|
||||
name_len = strlen(resolved_name);
|
||||
new_break.filename = estrndup(resolved_name, name_len + 1);
|
||||
new_break.line = line_num;
|
||||
|
||||
PHPDBG_G(has_file_bp) = 1;
|
||||
|
||||
if (zend_hash_find(&PHPDBG_G(bp_files),
|
||||
new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
|
||||
zend_llist break_files;
|
||||
|
||||
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
|
||||
phpdbg_llist_breakfile_dtor, 0);
|
||||
|
||||
zend_hash_update(&PHPDBG_G(bp_files),
|
||||
new_break.filename, name_len, &break_files, sizeof(zend_llist),
|
||||
(void**)&break_files_ptr);
|
||||
}
|
||||
zend_llist_add_element(break_files_ptr, &new_break);
|
||||
} /* }}} */
|
||||
|
||||
void phpdbg_set_breakpoint_symbol(const char *expr, const char *opline_num_pos TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
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);
|
||||
} /* }}} */
|
||||
|
||||
int phpdbg_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
size_t name_len = strlen(op_array->filename);
|
||||
zend_llist *break_list;
|
||||
|
||||
if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
|
||||
(void**)&break_list) == SUCCESS) {
|
||||
zend_llist_element *le;
|
||||
|
||||
for (le = break_list->head; le; le = le->next) {
|
||||
phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) le->data;
|
||||
|
||||
if (bp->line == (*EG(opline_ptr))->lineno) {
|
||||
printf("breakpoint reached!\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
/* }}} */
|
39
phpdbg_bp.h
Normal file
39
phpdbg_bp.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| 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> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHPDBG_BP_H
|
||||
#define PHPDBG_BP_H
|
||||
|
||||
/**
|
||||
* Breakpoint file-based representation
|
||||
*/
|
||||
typedef struct _phpdbg_breakfile_t {
|
||||
const char *filename;
|
||||
long line;
|
||||
} phpdbg_breakfile_t;
|
||||
|
||||
/**
|
||||
* Breakpoint symbol-based representation
|
||||
*/
|
||||
typedef struct _phpdbg_breaksymbol_t {
|
||||
const char *symbol;
|
||||
long opline_num;
|
||||
} phpdbg_breaksymbol_t;
|
||||
|
||||
#endif /* PHPDBG_BP_H */
|
@ -20,6 +20,8 @@
|
||||
#ifndef PHPDBG_HELP_H
|
||||
#define PHPDBG_HELP_H
|
||||
|
||||
#include "phpdbg_prompt.h"
|
||||
|
||||
/**
|
||||
* Command Declarators
|
||||
*/
|
||||
|
121
phpdbg_prompt.c
121
phpdbg_prompt.c
@ -23,25 +23,12 @@
|
||||
#include "zend_compile.h"
|
||||
#include "phpdbg.h"
|
||||
#include "phpdbg_help.h"
|
||||
#include "phpdbg_bp.h"
|
||||
|
||||
static const phpdbg_command_t phpdbg_prompt_commands[];
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
|
||||
|
||||
static void phpdbg_llist_breakfile_dtor(void *data)
|
||||
{
|
||||
phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
|
||||
|
||||
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) { /* {{{ */
|
||||
if (PHPDBG_G(exec)) {
|
||||
printf(
|
||||
@ -142,7 +129,7 @@ static PHPDBG_COMMAND(run) { /* {{{ */
|
||||
|
||||
static PHPDBG_COMMAND(eval) { /* {{{ */
|
||||
zval retval;
|
||||
|
||||
|
||||
if (expr) {
|
||||
if (zend_eval_stringl((char*)expr, expr_len-1, &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
|
||||
printf("Success: ");
|
||||
@ -219,61 +206,11 @@ static PHPDBG_COMMAND(break) /* {{{ */
|
||||
const char *line_pos = zend_memrchr(expr, ':', expr_len);
|
||||
|
||||
if (line_pos) {
|
||||
char resolved_name[MAXPATHLEN];
|
||||
long line_num = strtol(line_pos+1, NULL, 0);
|
||||
phpdbg_breakfile_t new_break;
|
||||
zend_llist *break_files_ptr;
|
||||
size_t name_len;
|
||||
char *path = estrndup(expr, line_pos - expr);
|
||||
|
||||
if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
|
||||
efree(path);
|
||||
return FAILURE;
|
||||
}
|
||||
efree(path);
|
||||
|
||||
name_len = strlen(resolved_name);
|
||||
new_break.filename = estrndup(resolved_name, name_len + 1);
|
||||
new_break.line = line_num;
|
||||
|
||||
PHPDBG_G(has_file_bp) = 1;
|
||||
|
||||
if (zend_hash_find(&PHPDBG_G(bp_files),
|
||||
new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
|
||||
zend_llist break_files;
|
||||
|
||||
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
|
||||
phpdbg_llist_breakfile_dtor, 0);
|
||||
|
||||
zend_hash_update(&PHPDBG_G(bp_files),
|
||||
new_break.filename, name_len, &break_files, sizeof(zend_llist),
|
||||
(void**)&break_files_ptr);
|
||||
}
|
||||
zend_llist_add_element(break_files_ptr, &new_break);
|
||||
phpdbg_set_breakpoint_file(expr, line_pos TSRMLS_CC);
|
||||
} 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);
|
||||
phpdbg_set_breakpoint_symbol(expr, opline_num_pos TSRMLS_CC);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
@ -282,7 +219,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
|
||||
static PHPDBG_COMMAND(quit) /* {{{ */
|
||||
{
|
||||
PHPDBG_G(quitting)=1;
|
||||
|
||||
|
||||
zend_bailout();
|
||||
|
||||
return SUCCESS;
|
||||
@ -354,59 +291,13 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
|
||||
return FAILURE;
|
||||
} /* }}} */
|
||||
|
||||
int phpdbg_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
size_t name_len = strlen(op_array->filename);
|
||||
zend_llist *break_list;
|
||||
|
||||
if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
|
||||
(void**)&break_list) == SUCCESS) {
|
||||
zend_llist_element *le;
|
||||
|
||||
for (le = break_list->head; le; le = le->next) {
|
||||
phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) le->data;
|
||||
|
||||
if (bp->line == (*EG(opline_ptr))->lineno) {
|
||||
printf("breakpoint reached!\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) /* {{{ */
|
||||
{
|
||||
char cmd[PHPDBG_MAX_CMD];
|
||||
|
||||
printf("phpdbg> ");
|
||||
|
||||
while (!PHPDBG_G(quitting) &&
|
||||
while (!PHPDBG_G(quitting) &&
|
||||
fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
|
||||
size_t cmd_len = strlen(cmd) - 1;
|
||||
|
||||
|
@ -43,23 +43,6 @@ typedef struct _phpdbg_command_t {
|
||||
phpdbg_command_handler_t handler; /* Command handler */
|
||||
} phpdbg_command_t;
|
||||
|
||||
|
||||
/**
|
||||
* Breakpoint file-based representation
|
||||
*/
|
||||
typedef struct _phpdbg_breakfile_t {
|
||||
const char *filename;
|
||||
long line;
|
||||
} phpdbg_breakfile_t;
|
||||
|
||||
/**
|
||||
* Breakpoint symbol-based representation
|
||||
*/
|
||||
typedef struct _phpdbg_breaksymbol_t {
|
||||
const char *symbol;
|
||||
long opline_num;
|
||||
} phpdbg_breaksymbol_t;
|
||||
|
||||
/**
|
||||
* Command Executor
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user