add source export functionality, only files working, buggy source

This commit is contained in:
krakjoe 2013-11-25 17:41:09 +00:00
parent 3d6a4cbc63
commit a947c890a0
4 changed files with 60 additions and 4 deletions

View file

@ -44,6 +44,40 @@ static void phpdbg_class_breaks_dtor(void *data) /* {{{ */
efree((char*)bp->func_name);
} /* }}} */
PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
{
HashPosition position;
HashTable *table = NULL;
if (PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) {
zend_llist *brakes;
table = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE];
for (zend_hash_internal_pointer_reset_ex(table, &position);
zend_hash_get_current_data_ex(table, (void*) &brakes, &position) == SUCCESS;
zend_hash_move_forward_ex(table, &position)) {
zend_llist_position lposition;
phpdbg_breakfile_t *brake;
zend_ulong count = zend_llist_count(brakes);
if ((brake = zend_llist_get_first_ex(brakes, &lposition))) {
phpdbg_notice(
"Exporting file breakpoints in %s (%d)", brake->filename, count);
fprintf(handle, "# Breakpoints in %s (%d)\n", brake->filename, count);
do {
fprintf(handle, "break file %s:%lu\n", brake->filename, brake->line);
} while ((brake = zend_llist_get_next_ex(brakes, &lposition)));
}
}
}
/* export other types here after resolving errors from source command */
} /* }}} */
PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
{
struct stat sb;

View file

@ -99,4 +99,6 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC);
PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D);
PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC);
PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC);
#endif /* PHPDBG_BP_H */

View file

@ -505,11 +505,15 @@ PHPDBG_HELP(source) /* {{{ */
{
phpdbg_help_header();
phpdbg_writeln("Sourcing a phpdbginit during your debugging session might save some time");
phpdbg_writeln("The source command can also be used to export breakpoints to a phpdbginit file");
phpdbg_writeln(EMPTY);
phpdbg_notice("Examples");
phpdbg_writeln("\t%ssource /my/phpdbginit", PROMPT);
phpdbg_writeln("\t%s. /my/phpdbginit", PROMPT);
phpdbg_writeln("\tWill execute the init file at /my/phpdbginit");
phpdbg_writeln("\t%ssource /my/init", PROMPT);
phpdbg_writeln("\t%s. /my/init", PROMPT);
phpdbg_writeln("\tWill execute the phpdbginit file at /my/init");
phpdbg_writeln("\t%ssource export /my/init", PROMPT);
phpdbg_writeln("\t%s. export /my/init", PROMPT);
phpdbg_writeln("\tWill export breakpoints to /my/init in phpdbginit file format");
phpdbg_help_footer();
return SUCCESS;
} /* }}} */

View file

@ -853,7 +853,23 @@ PHPDBG_COMMAND(source) /* {{{ */
{
switch (param->type) {
case STR_PARAM: {
if (input->argc > 2) {
if (phpdbg_argv_is(1, "export")) {
FILE *h = VCWD_FOPEN(input->argv[2]->string, "w+");
if (h) {
phpdbg_export_breakpoints(h TSRMLS_CC);
fclose(h);
} else phpdbg_error("Failed to open %s", input->argv[1]->string);
} else {
phpdbg_error(
"Incorrect usage of source command, see help");
}
} else {
struct stat sb;
if (VCWD_STAT(param->str, &sb) != -1) {
phpdbg_init(param->str, param->len, 0 TSRMLS_CC);
} else phpdbg_error("Cannot stat %s", param->str);
}
} break;
phpdbg_default_switch_case();