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);
+ struct stat sb;
- new_break.filename = estrndup(path, path_len);
- new_break.line = line_num;
+ if (VCWD_STAT(path, &sb) != FAILURE) {
+ if (sb.st_mode & S_IFREG|S_IFLNK) {
+ phpdbg_breakfile_t new_break;
+ zend_llist *break_files_ptr;
+ size_t path_len = strlen(path);
- PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
+ new_break.filename = estrndup(path, path_len);
+ new_break.line = line_num;
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
- new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) {
- zend_llist break_files;
+ PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
- zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
- phpdbg_llist_breakfile_dtor, 0);
+ if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
+ new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) {
+ zend_llist break_files;
- zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
- new_break.filename, path_len, &break_files, sizeof(zend_llist),
- (void**)&break_files_ptr);
- }
+ zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
+ phpdbg_llist_breakfile_dtor, 0);
+
+ zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
+ new_break.filename, path_len, &break_files, sizeof(zend_llist),
+ (void**)&break_files_ptr);
+ }
- new_break.id = PHPDBG_G(bp_count)++;
- zend_llist_add_element(break_files_ptr, &new_break);
+ new_break.id = PHPDBG_G(bp_count)++;
+ zend_llist_add_element(break_files_ptr, &new_break);
- phpdbg_notice("Breakpoint #%d added at %s:%ld",
- new_break.id, new_break.filename, new_break.line);
+ phpdbg_notice("Breakpoint #%d added at %s:%ld",
+ new_break.id, new_break.filename, new_break.line);
+ } else {
+ phpdbg_error("Cannot set breakpoint in %s, it is not a regular file", path);
+ }
+ } else {
+ phpdbg_error("Cannot stat %s, it does not exist", path);
+ }
} /* }}} */
void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */
case FILE_PARAM:
phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC);
break;
-
- default:
- phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- break;
+
+ phpdbg_default_switch_case();
}
return SUCCESS;
case METHOD_PARAM:
phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC);
break;
-
- default:
- phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- break;
+
+ phpdbg_default_switch_case();
}
return SUCCESS;
phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC);
break;
- default:
- phpdbg_error(
- "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
+ phpdbg_default_switch_case();
}
return SUCCESS;
PHPDBG_BREAK(on) /* {{{ */
{
- if (param->type == STR_PARAM) {
- phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC);
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
- }
+ switch (param->type) {
+ case STR_PARAM:
+ phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC);
+ break;
+
+ phpdbg_default_switch_case();
+ }
+
return SUCCESS;
} /* }}} */
PHPDBG_BREAK(lineno) /* {{{ */
{
- if (!PHPDBG_G(exec)) {
- phpdbg_error("Not file context found!");
- return SUCCESS;
- }
-
switch (param->type) {
- case NUMERIC_PARAM:
- phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC);
- break;
-
- default:
- phpdbg_error(
- "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
+ case NUMERIC_PARAM: {
+ if (PHPDBG_G(exec)) {
+ phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC);
+ } else {
+ phpdbg_error(
+ "Execution context not set !");
+ }
+ } break;
+
+ phpdbg_default_switch_case();
}
return SUCCESS;
case STR_PARAM:
phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC);
break;
-
- default:
- phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- break;
+
+ phpdbg_default_switch_case();
}
return SUCCESS;
int all_content = (count == 0);
unsigned int line = 0, displayed = 0;
- if (VCWD_STAT(filename, &st) == -1) {
+ if (VCWD_STAT(filename, &st) == FAILURE) {
phpdbg_error("Failed to stat file %s", filename);
return;
}
+
#ifndef _WIN32
- if ((fd = VCWD_OPEN(filename, O_RDONLY)) == -1) {
+ if ((fd = VCWD_OPEN(filename, O_RDONLY)) == FAILURE) {
phpdbg_error("Failed to open file %s to list", filename);
return;
}
} else {
phpdbg_error(
"Cannot find class %s", param->str);
- return FAILURE;
}
} else {
phpdbg_error(
"Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
}
return SUCCESS;
zend_bool in_code = 0;
while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
+ phpdbg_command_t *selected = NULL;
+
cmd_len = strlen(cmd)-1;
while (*cmd && isspace(cmd[cmd_len-1]))
goto next_line;
}
- switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+ switch (phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
phpdbg_error(
"Unrecognized command in %s:%d: %s!", init_file, line, cmd);
return SUCCESS;
} /* }}} */
-int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
+int phpdbg_do_cmd( const phpdbg_command_t *command,
+ phpdbg_command_t **selected,
+ char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
{
int rc = FAILURE;
#endif
size_t expr_len = (cmd != NULL) ? strlen(cmd) : 0;
+ phpdbg_param_t *param = NULL;
+
while (command && command->name && command->handler) {
if ((command->name_len == expr_len
&& memcmp(cmd, command->name, expr_len) == 0)
|| ((expr_len == 1) && (command->alias && command->alias == cmd_line[0]))) {
- phpdbg_param_t *param = emalloc(sizeof(phpdbg_param_t));
+ param = emalloc(sizeof(phpdbg_param_t));
PHPDBG_G(last) = (phpdbg_command_t*) command;
PHPDBG_G(lparam) = param;
if (command->subs && (param->type == STR_PARAM)) {
- if (phpdbg_do_cmd(command->subs, param->str, param->len TSRMLS_CC) == SUCCESS) {
+ if (phpdbg_do_cmd(command->subs, selected, param->str, param->len TSRMLS_CC) == SUCCESS) {
rc = SUCCESS;
- break;
+ /* because we can */
+ phpdbg_clear_param(param TSRMLS_CC);
+ efree(param);
+ goto done;
}
}
- phpdbg_debug("phpdbg_do_cmd(%s, \"%s\")",
- command->name, phpdbg_get_param_type(param TSRMLS_CC));
-
+ *selected = command;
+
rc = command->handler(param TSRMLS_CC);
- break;
- }
- ++command;
- }
+
+ break;
+ }
+ ++command;
+ }
+
+done:
+ if (selected && param) {
+ phpdbg_debug(
+ "phpdbg_do_cmd(%s, \"%s\"): %d",
+ command->name, phpdbg_get_param_type(param TSRMLS_CC), (rc==SUCCESS));
+ }
return rc;
} /* }}} */
cmd[cmd_len] = '\0';
if (*cmd && cmd_len > 0L) {
+ /* keep a cursor to selected command */
+ phpdbg_command_t *selected = NULL;
+
#ifdef HAVE_LIBREADLINE
add_history(cmd);
#endif
-
- switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+
+ switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
phpdbg_error("Failed to execute %s!", cmd);
/**
* Command Executor
*/
-int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC);
+int phpdbg_do_cmd(const phpdbg_command_t *command, phpdbg_command_t **selected, char *cmd_line, size_t cmd_len TSRMLS_DC);
/**
* Command Declarators
void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC);
#endif
+#define phpdbg_default_switch_case() \
+ default:\
+ phpdbg_error(\
+ "Unsupported parameter type (%s) for command", \
+ phpdbg_get_param_type(param TSRMLS_CC)); \
+ break
+
#endif /* PHPDBG_PROMPT_H */