AC_DEFINE(HAVE_PHPDBG, 1, [ ])
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_FILES)
\$(PHPDBG_EXTRA_LIBS) \
\$(ZEND_EXTRA_LIBS) \
-o \$(BUILD_BINARY)"
-
+
PHP_SUBST(BUILD_BINARY)
PHP_SUBST(BUILD_PHPDBG)
fi
printf("Will silence OPLINE output, while\n");
printf("\tphpdbg> quiet 0\n");
printf("Will enable OPLINE output again\n");
-
return SUCCESS;
} /* }}} */
printf("Will limit the number of frames to 5, the default is no limit\n");
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;
+} /* }}} */
#ifndef PHPDBG_HELP_H
#define PHPDBG_HELP_H
+#include "TSRM.h"
#include "phpdbg_prompt.h"
/**
PHPDBG_HELP(clear);
PHPDBG_HELP(back);
PHPDBG_HELP(quiet);
+PHPDBG_HELP(list);
/**
* Commands
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(quiet, "be quiet during execution"),
+ PHPDBG_HELP_D(list, "list specified line"),
{NULL, 0, 0}
};
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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);
+
+} /* }}} */
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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 */
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);
+ }
+
+ phpdbg_list_file(filename, count, offset);
+} /* }}} */
+
static const phpdbg_command_t phpdbg_prompt_commands[] = {
PHPDBG_COMMAND_D(exec, "set execution context"),
PHPDBG_COMMAND_D(compile, "attempt to pre-compile execution context"),
PHPDBG_COMMAND_D(print, "print something"),
PHPDBG_COMMAND_D(break, "set breakpoint"),
PHPDBG_COMMAND_D(back, "show backtrace"),
+ PHPDBG_COMMAND_D(list, "list specified line"),
PHPDBG_COMMAND_D(clean, "clean the execution environment"),
PHPDBG_COMMAND_D(clear, "clear breakpoints"),
PHPDBG_COMMAND_D(help, "show help menu"),