]> granicus.if.org Git - php/commitdiff
add source export functionality, only files working, buggy source
authorkrakjoe <joe.watkins@live.co.uk>
Mon, 25 Nov 2013 17:41:09 +0000 (17:41 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Mon, 25 Nov 2013 17:41:09 +0000 (17:41 +0000)
phpdbg_bp.c
phpdbg_bp.h
phpdbg_help.c
phpdbg_prompt.c

index 2547e39f13f631147ae6d756d32dabd9a51fc780..d04525526bb7bbd6dff1e327cfead2949e1331fa 100644 (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;
index 661962c45f230e20ed0920163839ebd08b0e945a..8b1a0f0bce0c1197d424e0d3cce76308e5930f34 100644 (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 */
index fe621fb818890a287a225196aaca37a79d943103..2dc4577fbad29339ff79e1e6aa836bc1b8b879cb 100644 (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;
 } /* }}} */
index 12c85d6216c7c2fb5983c292232b2ef0e3b1174f..84b183892964713a22e16e677dfda0d969bf74a7 100644 (file)
@@ -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();