From a947c890a03ce5a6f6065ce17823b0678f2c7b8c Mon Sep 17 00:00:00 2001 From: krakjoe Date: Mon, 25 Nov 2013 17:41:09 +0000 Subject: [PATCH] add source export functionality, only files working, buggy source --- phpdbg_bp.c | 34 ++++++++++++++++++++++++++++++++++ phpdbg_bp.h | 2 ++ phpdbg_help.c | 10 +++++++--- phpdbg_prompt.c | 18 +++++++++++++++++- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/phpdbg_bp.c b/phpdbg_bp.c index 2547e39f13..d04525526b 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -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; diff --git a/phpdbg_bp.h b/phpdbg_bp.h index 661962c45f..8b1a0f0bce 100644 --- a/phpdbg_bp.h +++ b/phpdbg_bp.h @@ -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 */ diff --git a/phpdbg_help.c b/phpdbg_help.c index fe621fb818..2dc4577fba 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -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; } /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 12c85d6216..84b1838929 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -853,7 +853,23 @@ PHPDBG_COMMAND(source) /* {{{ */ { switch (param->type) { case STR_PARAM: { - phpdbg_init(param->str, param->len, 0 TSRMLS_CC); + 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(); -- 2.50.1