This commit is contained in:
krakjoe 2013-11-12 00:28:48 +00:00
commit 95d33c18a0
6 changed files with 130 additions and 3 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" PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c"
PHP_SUBST(PHP_PHPDBG_CFLAGS) PHP_SUBST(PHP_PHPDBG_CFLAGS)
PHP_SUBST(PHP_PHPDBG_FILES) PHP_SUBST(PHP_PHPDBG_FILES)
@ -27,7 +27,7 @@ if test "$PHP_PHPDBG" != "no"; then
\$(PHPDBG_EXTRA_LIBS) \ \$(PHPDBG_EXTRA_LIBS) \
\$(ZEND_EXTRA_LIBS) \ \$(ZEND_EXTRA_LIBS) \
-o \$(BUILD_BINARY)" -o \$(BUILD_BINARY)"
PHP_SUBST(BUILD_BINARY) PHP_SUBST(BUILD_BINARY)
PHP_SUBST(BUILD_PHPDBG) PHP_SUBST(BUILD_PHPDBG)
fi fi

View file

@ -123,7 +123,6 @@ PHPDBG_HELP(quiet) /* {{{ */
printf("Will silence OPLINE output, while\n"); printf("Will silence OPLINE output, while\n");
printf("\tphpdbg> quiet 0\n"); printf("\tphpdbg> quiet 0\n");
printf("Will enable OPLINE output again\n"); printf("Will enable OPLINE output again\n");
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */
@ -135,3 +134,11 @@ PHPDBG_HELP(back) /* {{{ */
printf("Will limit the number of frames to 5, the default is no limit\n"); printf("Will limit the number of frames to 5, the default is no limit\n");
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */
PHPDBG_HELP(list) /* {{{ */
{
printf("The list command displays N line from current context file.\n");
printf("\tphpdbg> list 2\n");
printf("Will print next 2 lines from the current file\n");
return SUCCESS;
} /* }}} */

View file

@ -20,6 +20,7 @@
#ifndef PHPDBG_HELP_H #ifndef PHPDBG_HELP_H
#define PHPDBG_HELP_H #define PHPDBG_HELP_H
#include "TSRM.h"
#include "phpdbg_prompt.h" #include "phpdbg_prompt.h"
/** /**
@ -45,6 +46,7 @@ PHPDBG_HELP(clean);
PHPDBG_HELP(clear); PHPDBG_HELP(clear);
PHPDBG_HELP(back); PHPDBG_HELP(back);
PHPDBG_HELP(quiet); PHPDBG_HELP(quiet);
PHPDBG_HELP(list);
/** /**
* Commands * Commands
@ -62,6 +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"),
{NULL, 0, 0} {NULL, 0, 0}
}; };

72
phpdbg_list.c Normal file
View file

@ -0,0 +1,72 @@
/*
+----------------------------------------------------------------------+
| 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 <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include "phpdbg_list.h"
void phpdbg_list_file(const char *filename, long count, long offset) /* {{{ */
{
unsigned char *mem, *pos, *last_pos, *end_pos;
struct stat st;
int fd, all_content = (count == 0);
unsigned int line = 0, displayed = 0;
if ((fd = open(filename, O_RDONLY)) == -1) {
printf("[Failed to open file to list]\n");
return;
}
fstat(fd, &st);
last_pos = mem = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
end_pos = mem + st.st_size;
while (1) {
pos = memchr(last_pos, '\n', end_pos - last_pos);
if (!pos) {
/* No more line breaks */
break;
}
++line;
if (!offset || offset <= line) {
/* Without offset, or offset reached */
printf("%05u: %.*s\n", line, (int)(pos - last_pos), last_pos);
++displayed;
}
last_pos = pos + 1;
if (!all_content && displayed == count) {
/* Reached max line to display */
break;
}
}
munmap(mem, st.st_size);
close(fd);
} /* }}} */

25
phpdbg_list.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_LIST_H
#define PHPDBG_LIST_H
void phpdbg_list_file(const char*, long, long);
#endif /* PHPDBG_LIST_H */

View file

@ -25,6 +25,7 @@
#include "phpdbg_help.h" #include "phpdbg_help.h"
#include "phpdbg_bp.h" #include "phpdbg_bp.h"
#include "phpdbg_opcode.h" #include "phpdbg_opcode.h"
#include "phpdbg_list.h"
static const phpdbg_command_t phpdbg_prompt_commands[]; static const phpdbg_command_t phpdbg_prompt_commands[];
@ -466,6 +467,24 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */
static PHPDBG_COMMAND(list) /* {{{ */
{
long offset = 0, count = strtol(expr, NULL, 0);
const char *filename = PHPDBG_G(exec);
if (zend_is_executing(TSRMLS_C)) {
filename = zend_get_executed_filename(TSRMLS_C);
offset = zend_get_executed_lineno(TSRMLS_C);
} else if (!filename) {
printf("[No file to list]\n");
return SUCCESS;
}
phpdbg_list_file(filename, count, offset);
return SUCCESS;
} /* }}} */
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(compile, "attempt to pre-compile execution context"), PHPDBG_COMMAND_D(compile, "attempt to pre-compile execution context"),
@ -476,6 +495,7 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
PHPDBG_COMMAND_D(print, "print something"), PHPDBG_COMMAND_D(print, "print something"),
PHPDBG_COMMAND_D(break, "set breakpoint"), PHPDBG_COMMAND_D(break, "set breakpoint"),
PHPDBG_COMMAND_D(back, "show backtrace"), PHPDBG_COMMAND_D(back, "show backtrace"),
PHPDBG_COMMAND_D(list, "list specified line"),
PHPDBG_COMMAND_D(clean, "clean the execution environment"), PHPDBG_COMMAND_D(clean, "clean the execution environment"),
PHPDBG_COMMAND_D(clear, "clear breakpoints"), PHPDBG_COMMAND_D(clear, "clear breakpoints"),
PHPDBG_COMMAND_D(help, "show help menu"), PHPDBG_COMMAND_D(help, "show help menu"),