mirror of
https://github.com/php/php-src.git
synced 2026-03-31 04:32:19 +02:00
- Added initial code for list command
This commit is contained in:
@@ -9,7 +9,7 @@ if test "$PHP_PHPDBG" != "no"; then
|
||||
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)
|
||||
@@ -27,7 +27,7 @@ if test "$PHP_PHPDBG" != "no"; then
|
||||
\$(PHPDBG_EXTRA_LIBS) \
|
||||
\$(ZEND_EXTRA_LIBS) \
|
||||
-o \$(BUILD_BINARY)"
|
||||
|
||||
|
||||
PHP_SUBST(BUILD_BINARY)
|
||||
PHP_SUBST(BUILD_PHPDBG)
|
||||
fi
|
||||
|
||||
@@ -120,7 +120,6 @@ PHPDBG_HELP(quiet) /* {{{ */
|
||||
printf("Will silence OPLINE output, while\n");
|
||||
printf("\tphpdbg> quiet 0\n");
|
||||
printf("Will enable OPLINE output again\n");
|
||||
|
||||
return SUCCESS;
|
||||
} /* }}} */
|
||||
|
||||
@@ -132,3 +131,11 @@ PHPDBG_HELP(back) /* {{{ */
|
||||
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;
|
||||
} /* }}} */
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef PHPDBG_HELP_H
|
||||
#define PHPDBG_HELP_H
|
||||
|
||||
#include "TSRM.h"
|
||||
#include "phpdbg_prompt.h"
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,7 @@ PHPDBG_HELP(clean);
|
||||
PHPDBG_HELP(clear);
|
||||
PHPDBG_HELP(back);
|
||||
PHPDBG_HELP(quiet);
|
||||
PHPDBG_HELP(list);
|
||||
|
||||
/**
|
||||
* 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(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}
|
||||
};
|
||||
|
||||
|
||||
72
phpdbg_list.c
Normal file
72
phpdbg_list.c
Normal 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
25
phpdbg_list.h
Normal 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 */
|
||||
@@ -422,6 +422,19 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */
|
||||
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"),
|
||||
@@ -432,6 +445,7 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
|
||||
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"),
|
||||
|
||||
Reference in New Issue
Block a user