Commit: 1c1cc51295dfedabcd0244a0a2d2851a30d7a7ce Author: krakjoe <joe.watk...@live.co.uk> Wed, 13 Nov 2013 19:32:21 +0000 Parents: 0bc987c9b4d3575963b56dae5b45647ccf458992 Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1c1cc51295dfedabcd0244a0a2d2851a30d7a7ce Log: ... Changed paths: A phpdbg_break.c A phpdbg_break.h M phpdbg_utils.c Diff: diff --git a/phpdbg_break.c b/phpdbg_break.c new file mode 100644 index 0000000..23b1c59 --- /dev/null +++ b/phpdbg_break.c @@ -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 | + | lice...@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Felipe Pena <fel...@php.net> | + | Authors: Joe Watkins <joe.watk...@live.co.uk> | + +----------------------------------------------------------------------+ +*/ + +#include "phpdbg.h" +#include "phpdbg_print.h" +#include "phpdbg_utils.h" +#include "phpdbg_opcode.h" +#include "phpdbg_break.h" +#include "phpdbg_bp.h" + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +PHPDBG_BREAK(file) /* {{{ */ +{ + if (expr && expr_len > 0L) { + if (!phpdbg_is_class_method(expr, expr_len, NULL, NULL)) { + char path[MAXPATHLEN], resolved_name[MAXPATHLEN]; + const char *line_pos = strchr(expr, ':'); + long line_num = strtol(line_pos+1, NULL, 0); + + if (line_num) { + memcpy(path, expr, line_pos - expr); + path[line_pos - expr] = 0; + + if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) { + phpdbg_error("Failed to expand path %s", path); + return SUCCESS; + } + + phpdbg_set_breakpoint_file(resolved_name, line_num TSRMLS_CC); + } else { + phpdbg_error("No line specified in expression %s", expr); + return SUCCESS; + } + } + } else { + phpdbg_error( + "No expression provided"); + } + return SUCCESS; +} /* }}} */ + +PHPDBG_BREAK(method) /* {{{ */ +{ + char *class_name; + char *func_name; + + if (expr && expr_len >0L) { + if (phpdbg_is_class_method(expr, expr_len+1, &class_name, &func_name)) { + phpdbg_set_breakpoint_method( + class_name, func_name TSRMLS_CC); + } else { + phpdbg_error( + "The expression provided is not a method name: %s", expr); + } + } else { + phpdbg_error("No expression provided"); + } + + return SUCCESS; +} /* }}} */ + +PHPDBG_BREAK(address) /* {{{ */ +{ + if (expr && expr_len > 0L) { + if (phpdbg_is_addr(expr)) { + phpdbg_set_breakpoint_opline( + strtoul(expr, 0, 16) TSRMLS_CC); + } else { + phpdbg_error("The expression provided is not an address: %s", expr); + } + } else { + phpdbg_error("No expression provided"); + } + return SUCCESS; +} /* }}} */ + +PHPDBG_BREAK(on) /* {{{ */ +{ + if (expr && expr_len > 0L) { + phpdbg_set_breakpoint_expression( + expr, expr_len TSRMLS_CC); + } else { + phpdbg_error( + "No expression provided!"); + } + + return SUCCESS; +} /* }}} */ + +PHPDBG_BREAK(lineno) /* {{{ */ +{ + /* note: this can break on [no active file] */ + if (expr && expr_len > 0L) { + if (phpdbg_is_numeric(expr)) { + const char *filename = zend_get_executed_filename(TSRMLS_C); + + if (filename) { + phpdbg_set_breakpoint_file( + filename, strtol(expr, NULL, 0) TSRMLS_CC); + } else { + phpdbg_error("No file context found"); + } + } else { + phpdbg_error( + "The expression provided is not a valid line number %s", expr); + } + } else { + phpdbg_error( + "No expression provided!"); + } + + return SUCCESS; +} /* }}} */ + +PHPDBG_BREAK(func) /* {{{ */ +{ + if (expr && expr_len > 0L) { + char name[200]; + size_t name_len = expr_len; + + name_len = MIN(name_len, 200); + memcpy(name, expr, name_len); + name[name_len] = 0; + + phpdbg_set_breakpoint_symbol(name TSRMLS_CC); + } else { + phpdbg_error("No expression provided"); + } + return SUCCESS; +} /* }}} */ diff --git a/phpdbg_break.h b/phpdbg_break.h new file mode 100644 index 0000000..23677e7 --- /dev/null +++ b/phpdbg_break.h @@ -0,0 +1,58 @@ +/* + +----------------------------------------------------------------------+ + | 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 | + | lice...@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Felipe Pena <fel...@php.net> | + | Authors: Joe Watkins <joe.watk...@live.co.uk> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_BREAK_H +#define PHPDBG_BREAK_H + +#include "TSRM.h" + +/** + * Command Declarators + */ +#define PHPDBG_BREAK_D(name, tip) \ + {PHPDBG_STRL(#name), tip, sizeof(tip)-1, 0, phpdbg_do_break_##name} +#define PHPDBG_BREAK_EX_D(name, tip, alias) \ + {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_break_##name} +#define PHPDBG_BREAK(name) \ + int phpdbg_do_break_##name(const char *expr, size_t expr_len TSRMLS_DC) + +/** + * Printer Forward Declarations + */ +PHPDBG_BREAK(file); +PHPDBG_BREAK(method); +PHPDBG_BREAK(address); +PHPDBG_BREAK(on); +PHPDBG_BREAK(lineno); +PHPDBG_BREAK(func); + +/** + * Commands + */ +static const phpdbg_command_t phpdbg_break_commands[] = { + PHPDBG_BREAK_EX_D(file, "specify breakpoint by file:line", 'F'), + PHPDBG_BREAK_EX_D(method, "specify breakpoint by class::method", 'm'), + PHPDBG_BREAK_EX_D(address, "specify breakpoint by address", 'a'), + PHPDBG_BREAK_EX_D(on, "specify breakpoint by expression", 'o'), + PHPDBG_BREAK_EX_D(lineno, "specify breakpoint by line of currently executing file", 'l'), + PHPDBG_BREAK_EX_D(func, "specify breakpoint by global function name", 'f'), + {NULL, 0, 0} +}; + +#endif /* PHPDBG_BREAK_H */ diff --git a/phpdbg_utils.c b/phpdbg_utils.c index 4fff467..02fd46a 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -63,10 +63,15 @@ int phpdbg_is_class_method(const char *str, size_t len, char **class, char **met return 0; } - *class = estrndup(str, sep - str); - (*class)[sep - str] = 0; - - *method = estrndup(sep+2, str + len - (sep + 2)); + if (class != NULL) { + *class = estrndup(str, sep - str); + (*class)[sep - str] = 0; + } + + if (method != NULL) { + *method = estrndup( + sep+2, str + len - (sep + 2)); + } return 1; } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php