php-src/phpdbg_bp.c

203 lines
6.0 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
| 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 "zend.h"
#include "zend_hash.h"
2013-11-10 20:10:54 +00:00
#include "zend_llist.h"
#include "phpdbg.h"
#include "phpdbg_bp.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */
{
phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
efree((char*)bp->filename);
} /* }}} */
void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
{
phpdbg_breakfile_t new_break;
zend_llist *break_files_ptr;
size_t path_len = strlen(path);
new_break.filename = estrndup(path, path_len);
new_break.line = line_num;
2013-11-11 22:06:36 +00:00
PHPDBG_G(has_file_bp) = 1;
if (zend_hash_find(&PHPDBG_G(bp_files),
new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) {
zend_llist break_files;
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
phpdbg_llist_breakfile_dtor, 0);
zend_hash_update(&PHPDBG_G(bp_files),
new_break.filename, path_len, &break_files, sizeof(zend_llist),
(void**)&break_files_ptr);
}
2013-11-10 19:15:32 +00:00
new_break.id = PHPDBG_G(bp_count)++;
zend_llist_add_element(break_files_ptr, &new_break);
2013-11-11 22:06:36 +00:00
printf(
2013-11-11 14:03:14 +00:00
"[Breakpoint #%d added at %s:%ld]\n", new_break.id, new_break.filename, new_break.line);
} /* }}} */
2013-11-10 21:38:58 +00:00
void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */
{
size_t name_len = strlen(name);
2013-11-10 21:38:58 +00:00
if (!zend_hash_exists(&PHPDBG_G(bp_symbols), name, name_len)) {
phpdbg_breaksymbol_t new_break;
2013-11-10 21:38:58 +00:00
PHPDBG_G(has_sym_bp) = 1;
2013-11-10 21:38:58 +00:00
new_break.symbol = estrndup(name, name_len + 1);
new_break.id = PHPDBG_G(bp_count)++;
2013-11-10 21:38:58 +00:00
zend_hash_update(&PHPDBG_G(bp_symbols), new_break.symbol,
name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL);
2013-11-11 22:06:36 +00:00
2013-11-11 14:03:14 +00:00
printf("[Breakpoint #%d added at %s]\n", new_break.id, new_break.symbol);
} else {
2013-11-11 14:03:14 +00:00
printf("[Breakpoint exists at %s]\n", name);
}
} /* }}} */
2013-11-11 11:54:41 +00:00
void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */
{
2013-11-11 13:04:21 +00:00
zend_ulong opline = strtoul(name, 0, 16);
2013-11-11 22:06:36 +00:00
2013-11-11 13:04:21 +00:00
if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), opline)) {
2013-11-11 11:54:41 +00:00
phpdbg_breakline_t new_break;
PHPDBG_G(has_opline_bp) = 1;
2013-11-11 22:06:36 +00:00
2013-11-11 15:14:37 +00:00
new_break.name = strdup(name);
2013-11-11 13:04:21 +00:00
new_break.opline = opline;
2013-11-11 11:54:41 +00:00
new_break.id = PHPDBG_G(bp_count)++;
2013-11-11 22:06:36 +00:00
2013-11-11 13:04:21 +00:00
zend_hash_index_update(&PHPDBG_G(bp_oplines), opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
2013-11-11 22:06:36 +00:00
2013-11-11 14:03:14 +00:00
printf("[Breakpoint #%d added at %s]\n", new_break.id, new_break.name);
2013-11-11 11:54:41 +00:00
} else {
2013-11-11 14:03:14 +00:00
printf("[Breakpoint exists at %s]\n", name);
2013-11-11 11:54:41 +00:00
}
} /* }}} */
2013-11-11 14:33:53 +00:00
void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
{
if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), (zend_ulong) opline)) {
phpdbg_breakline_t new_break;
PHPDBG_G(has_opline_bp) = 1;
2013-11-11 22:06:36 +00:00
asprintf(
(char**)&new_break.name, "%p", (zend_op*) opline);
2013-11-11 22:06:36 +00:00
new_break.opline = (zend_ulong) opline;
2013-11-11 14:33:53 +00:00
new_break.id = PHPDBG_G(bp_count)++;
2013-11-11 22:06:36 +00:00
zend_hash_index_update(&PHPDBG_G(bp_oplines), (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
2013-11-11 22:06:36 +00:00
printf("[Breakpoint #%d added at %p]\n", new_break.id, (zend_op*) new_break.opline);
2013-11-11 14:33:53 +00:00
}
} /* }}} */
2013-11-10 20:06:19 +00:00
int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
size_t name_len = strlen(op_array->filename);
zend_llist *break_list;
2013-11-10 19:15:32 +00:00
zend_llist_element *le;
if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
2013-11-10 19:15:32 +00:00
(void**)&break_list) == FAILURE) {
return FAILURE;
}
2013-11-10 19:15:32 +00:00
for (le = break_list->head; le; le = le->next) {
const phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*)le->data;
2013-11-10 19:15:32 +00:00
if (bp->line == (*EG(opline_ptr))->lineno) {
2013-11-11 14:03:14 +00:00
printf("[Breakpoint #%d at %s:%ld]\n", bp->id, bp->filename, bp->line);
2013-11-10 19:15:32 +00:00
return SUCCESS;
}
}
return FAILURE;
} /* }}} */
2013-11-10 20:06:19 +00:00
int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
{
const char *fname;
2013-11-10 21:38:58 +00:00
phpdbg_breaksymbol_t *bp;
if (fbc->type != ZEND_USER_FUNCTION) {
return FAILURE;
}
fname = ((zend_op_array*)fbc)->function_name;
if (!fname) {
fname = "main";
}
2013-11-10 21:38:58 +00:00
if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
2013-11-10 21:38:58 +00:00
(void**)&bp) == SUCCESS) {
2013-11-11 22:06:36 +00:00
printf("[Breakpoint #%d in %s() at %s:%u]\n", bp->id, bp->symbol,
zend_get_executed_filename(TSRMLS_C),
zend_get_executed_lineno(TSRMLS_C));
return SUCCESS;
}
return FAILURE;
2013-11-10 21:57:43 +00:00
} /* }}} */
2013-11-11 11:54:41 +00:00
2013-11-11 13:07:02 +00:00
int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
2013-11-11 11:54:41 +00:00
{
phpdbg_breakline_t *bp;
2013-11-11 13:04:21 +00:00
if (zend_hash_index_find(&PHPDBG_G(bp_oplines), (zend_ulong) opline,
(void**)&bp) == SUCCESS) {
2013-11-11 22:06:36 +00:00
printf("[Breakpoint #%d in %s at %s:%u]\n", bp->id, bp->name,
zend_get_executed_filename(TSRMLS_C),
zend_get_executed_lineno(TSRMLS_C));
2013-11-11 11:54:41 +00:00
return SUCCESS;
}
2013-11-11 22:06:36 +00:00
2013-11-11 11:54:41 +00:00
return FAILURE;
} /* }}} */
2013-11-11 14:33:53 +00:00
2013-11-11 17:19:05 +00:00
void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
{
zend_hash_clean(&PHPDBG_G(bp_files));
zend_hash_clean(&PHPDBG_G(bp_symbols));
zend_hash_clean(&PHPDBG_G(bp_oplines));
2013-11-11 22:06:36 +00:00
2013-11-11 17:19:05 +00:00
PHPDBG_G(has_file_bp) = 0;
PHPDBG_G(has_sym_bp) = 0;
PHPDBG_G(has_opline_bp) = 0;
PHPDBG_G(bp_count) = 0;
} /* }}} */