- Added "list func" support

This commit is contained in:
Felipe Pena 2013-11-12 00:19:43 -02:00
parent 77cb82dd22
commit e32d511cec
8 changed files with 118 additions and 28 deletions

View file

@ -9,7 +9,7 @@ if test "$PHP_PHPDBG" != "no"; then
AC_DEFINE(HAVE_PHPDBG, 1, [ ]) AC_DEFINE(HAVE_PHPDBG, 1, [ ])
PHP_PHPDBG_CFLAGS="-I$abc_srcdir" PHP_PHPDBG_CFLAGS="-I$abc_srcdir"
PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c" PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c"
PHP_SUBST(PHP_PHPDBG_CFLAGS) PHP_SUBST(PHP_PHPDBG_CFLAGS)
PHP_SUBST(PHP_PHPDBG_FILES) PHP_SUBST(PHP_PHPDBG_FILES)

View file

@ -140,5 +140,7 @@ PHPDBG_HELP(list) /* {{{ */
printf("The list command displays N line from current context file.\n"); printf("The list command displays N line from current context file.\n");
printf("\tphpdbg> list 2\n"); printf("\tphpdbg> list 2\n");
printf("Will print next 2 lines from the current file\n"); printf("Will print next 2 lines from the current file\n");
printf("\tphpdbg> list func\n");
printf("Will print func source code\n");
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */

View file

@ -64,7 +64,7 @@ static const phpdbg_command_t phpdbg_help_commands[] = {
PHPDBG_HELP_D(clear, "clearing breakpoints allows you to run code without interruption"), PHPDBG_HELP_D(clear, "clearing breakpoints allows you to run code without interruption"),
PHPDBG_HELP_D(back, "show debug backtrace information during execution"), PHPDBG_HELP_D(back, "show debug backtrace information during execution"),
PHPDBG_HELP_D(quiet, "be quiet during execution"), PHPDBG_HELP_D(quiet, "be quiet during execution"),
PHPDBG_HELP_D(list, "list specified line"), PHPDBG_HELP_D(list, "list specified line or function"),
{NULL, 0, 0} {NULL, 0, 0}
}; };

View file

@ -73,3 +73,17 @@ void phpdbg_list_file(const char *filename, long count, long offset) /* {{{ */
out: out:
close(fd); close(fd);
} /* }}} */ } /* }}} */
void phpdbg_list_function(const zend_function *fbc) /* {{{ */
{
const zend_op_array *ops;
if (fbc->type != ZEND_USER_FUNCTION) {
return;
}
ops = (zend_op_array*)fbc;
phpdbg_list_file(ops->filename,
ops->line_end - ops->line_start + 1, ops->line_start);
} /* }}} */

View file

@ -20,6 +20,9 @@
#ifndef PHPDBG_LIST_H #ifndef PHPDBG_LIST_H
#define PHPDBG_LIST_H #define PHPDBG_LIST_H
#include "zend_compile.h"
void phpdbg_list_file(const char*, long, long); void phpdbg_list_file(const char*, long, long);
void phpdbg_list_function(const zend_function*);
#endif /* PHPDBG_LIST_H */ #endif /* PHPDBG_LIST_H */

View file

@ -26,6 +26,7 @@
#include "phpdbg_bp.h" #include "phpdbg_bp.h"
#include "phpdbg_opcode.h" #include "phpdbg_opcode.h"
#include "phpdbg_list.h" #include "phpdbg_list.h"
#include "phpdbg_utils.h"
static const phpdbg_command_t phpdbg_prompt_commands[]; static const phpdbg_command_t phpdbg_prompt_commands[];
@ -489,6 +490,7 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */
static PHPDBG_COMMAND(list) /* {{{ */ static PHPDBG_COMMAND(list) /* {{{ */
{ {
if (phpdbg_is_numeric(expr)) {
long offset = 0, count = strtol(expr, NULL, 0); long offset = 0, count = strtol(expr, NULL, 0);
const char *filename = PHPDBG_G(exec); const char *filename = PHPDBG_G(exec);
@ -501,6 +503,19 @@ static PHPDBG_COMMAND(list) /* {{{ */
} }
phpdbg_list_file(filename, count, offset); phpdbg_list_file(filename, count, offset);
} else {
zend_function* fbc;
if (!EG(function_table)) {
printf("[No function table loaded]\n");
return SUCCESS;
}
if (zend_hash_find(EG(function_table), expr, strlen(expr)+1,
(void**)&fbc) == SUCCESS) {
phpdbg_list_function(fbc);
}
}
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */

31
phpdbg_utils.c Normal file
View file

@ -0,0 +1,31 @@
/*
+----------------------------------------------------------------------+
| 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 <ctype.h>
#include "phpdbg_utils.h"
int phpdbg_is_numeric(const char *str) /* {{{ */
{
for (; *str; str++) {
if (isspace(*str)) {
continue;
}
return isdigit(*str);
}
} /* }}} */

25
phpdbg_utils.h Normal file
View file

@ -0,0 +1,25 @@
/*
+----------------------------------------------------------------------+
| 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_UTILS_H
#define PHPDBG_UTILS_H
int phpdbg_is_numeric(const char *);
#endif /* PHPDBG_UTILS_H */